Replace DALI_COMPILE_TIME_ASSERT with C++11 static_assert
[platform/core/uifw/dali-core.git] / dali / internal / update / manager / transform-manager.cpp
1 /*
2  * Copyright (c) 2017 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 // CLASS HEADER
19 #include <dali/internal/update/manager/transform-manager.h>
20
21 //EXTERNAL INCLUDES
22 #include <algorithm>
23 #include <cstring>
24 #include <type_traits>
25
26 //INTERNAL INCLUDES
27 #include <dali/public-api/common/constants.h>
28 #include <dali/internal/common/math.h>
29
30 namespace Dali
31 {
32
33 namespace Internal
34 {
35
36 namespace SceneGraph
37 {
38
39 namespace
40 {
41 //Default values for scale (1.0,1.0,1.0), orientation (Identity) and position (0.0,0.0,0.0)
42 static const float gDefaultTransformComponentAnimatableData[] = { 1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f };
43
44 //Default values for anchor point (CENTER) and parent origin (TOP_LEFT)
45 static const float gDefaultTransformComponentStaticData[] = { 0.5f, 0.5f, 0.5f, 0.0f, 0.0f, 0.5f, true };
46
47 static_assert( sizeof(gDefaultTransformComponentAnimatableData) == sizeof(TransformComponentAnimatable), "gDefaultTransformComponentAnimatableData should have the same number of floats as specified in TransformComponentAnimatable" );
48 static_assert( sizeof(gDefaultTransformComponentStaticData) == sizeof(TransformComponentStatic), "gDefaultTransformComponentStaticData should have the same number of floats as specified in TransformComponentStatic" );
49
50 /**
51  * @brief Calculates the center position for the transform component
52  * @param[out] centerPosition The calculated center-position of the transform component
53  * @param[in] transformComponentStatic A const reference to the static component transform struct
54  * @param[in] transformComponentAnimatable A const reference to the animatable component transform struct
55  * @param[in] size The size of the current transform component
56  * @param[in] half Halfway point of the transform
57  * @param[in] topLeft The top-left coords of the transform
58  */
59 inline void CalculateCenterPosition(
60   Vector3& centerPosition,
61   const TransformComponentStatic& transformComponentStatic,
62   const TransformComponentAnimatable& transformComponentAnimatable,
63   const Vector3& size,
64   const Vector3& half,
65   const Vector3& topLeft )
66 {
67   // Calculate the center-point by applying the scale and rotation on the anchor point.
68   centerPosition = ( half - transformComponentStatic.mAnchorPoint ) * size * transformComponentAnimatable.mScale;
69   centerPosition *= transformComponentAnimatable.mOrientation;
70
71   // If the position is ignoring the anchor-point, then remove the anchor-point shift from the position.
72   if( ! transformComponentStatic.mPositionUsesAnchorPoint )
73   {
74     centerPosition -= ( topLeft - transformComponentStatic.mAnchorPoint ) * size;
75   }
76 }
77
78 } // unnamed namespace
79
80 TransformManager::TransformManager()
81 :mComponentCount(0),
82  mReorder(false)
83 {}
84
85 TransformManager::~TransformManager()
86 {}
87
88 TransformId TransformManager::CreateTransform()
89 {
90   //Get id for the new component
91   TransformId id = mIds.Add(mComponentCount);
92
93   if( mTxComponentAnimatable.Size() <= mComponentCount )
94   {
95     //Make room for another component
96     mTxComponentAnimatable.PushBack(TransformComponentAnimatable());
97     mTxComponentStatic.PushBack(TransformComponentStatic());
98     mInheritanceMode.PushBack(INHERIT_ALL);
99     mComponentId.PushBack(id);
100     mSize.PushBack(Vector3(0.0f,0.0f,0.0f));
101     mParent.PushBack(INVALID_TRANSFORM_ID);
102     mWorld.PushBack(Matrix::IDENTITY);
103     mLocal.PushBack(Matrix::IDENTITY);
104     mBoundingSpheres.PushBack( Vector4(0.0f,0.0f,0.0f,0.0f) );
105     mTxComponentAnimatableBaseValue.PushBack(TransformComponentAnimatable());
106     mSizeBase.PushBack(Vector3(0.0f,0.0f,0.0f));
107     mComponentDirty.PushBack(false);
108     mLocalMatrixDirty.PushBack(false);
109   }
110   else
111   {
112     //Set default values
113     memcpy( &mTxComponentAnimatable[mComponentCount], &gDefaultTransformComponentAnimatableData, sizeof( TransformComponentAnimatable ) );
114     memcpy( &mTxComponentStatic[mComponentCount], &gDefaultTransformComponentStaticData, sizeof( TransformComponentStatic ) );
115     memcpy( &mTxComponentAnimatableBaseValue[mComponentCount], &gDefaultTransformComponentAnimatableData, sizeof( TransformComponentAnimatable ) );
116     mInheritanceMode[mComponentCount] = INHERIT_ALL;
117     mComponentId[mComponentCount] = id;
118     mSize[mComponentCount] = Vector3(0.0f,0.0f,0.0f);
119     mParent[mComponentCount] = INVALID_TRANSFORM_ID;
120     mLocal[mComponentCount].SetIdentity();
121     mWorld[mComponentCount].SetIdentity();
122     mBoundingSpheres[mComponentCount] = Vector4(0.0f,0.0f,0.0f,0.0f);
123     mSizeBase[mComponentCount] = Vector3(0.0f,0.0f,0.0f);
124     mComponentDirty[mComponentCount] = false;
125     mLocalMatrixDirty[mComponentCount] = false;
126   }
127
128   mComponentCount++;
129   return id;
130 }
131
132 void TransformManager::RemoveTransform(TransformId id)
133 {
134   //Move the last element to the gap
135   mComponentCount--;
136   unsigned int index = mIds[id];
137   mTxComponentAnimatable[index] = mTxComponentAnimatable[mComponentCount];
138   mTxComponentStatic[index] = mTxComponentStatic[mComponentCount];
139   mInheritanceMode[index] = mInheritanceMode[mComponentCount];
140   mSize[index] = mSize[mComponentCount];
141   mParent[index] = mParent[mComponentCount];
142   mWorld[index] = mWorld[mComponentCount];
143   mLocal[index] = mLocal[mComponentCount];
144   mTxComponentAnimatableBaseValue[index] = mTxComponentAnimatableBaseValue[mComponentCount];
145   mSizeBase[index] = mSizeBase[mComponentCount];
146   mComponentDirty[index] = mComponentDirty[mComponentCount];
147   mLocalMatrixDirty[index] = mLocalMatrixDirty[mComponentCount];
148   mBoundingSpheres[index] = mBoundingSpheres[mComponentCount];
149
150   TransformId lastItemId = mComponentId[mComponentCount];
151   mIds[ lastItemId ] = index;
152   mComponentId[index] = lastItemId;
153   mIds.Remove( id );
154
155   mReorder = true;
156 }
157
158 void TransformManager::SetParent( TransformId id, TransformId parentId )
159 {
160   DALI_ASSERT_ALWAYS( id != parentId );
161   unsigned int index = mIds[id];
162   mParent[ index ] = parentId;
163   mComponentDirty[ index ] = true;
164   mReorder = true;
165 }
166
167 const Matrix& TransformManager::GetWorldMatrix( TransformId id ) const
168 {
169   return mWorld[ mIds[id] ];
170 }
171
172 Matrix& TransformManager::GetWorldMatrix( TransformId id )
173 {
174   return mWorld[ mIds[id] ];
175 }
176
177 void TransformManager::SetInheritPosition( TransformId id, bool inherit )
178 {
179   unsigned int index = mIds[id];
180   if( inherit )
181   {
182     mInheritanceMode[ index ] |= INHERIT_POSITION;
183   }
184   else
185   {
186     mInheritanceMode[ index ] &= ~INHERIT_POSITION;
187   }
188
189   mComponentDirty[index] = true;
190 }
191
192 void TransformManager::SetInheritScale( TransformId id, bool inherit )
193 {
194   unsigned int index = mIds[id];
195   if( inherit )
196   {
197     mInheritanceMode[ index ] |= INHERIT_SCALE;
198   }
199   else
200   {
201     mInheritanceMode[ index ] &= ~INHERIT_SCALE;
202   }
203
204   mComponentDirty[index] = true;
205 }
206
207 void TransformManager::SetInheritOrientation( TransformId id, bool inherit )
208 {
209   unsigned int index = mIds[id];
210   if( inherit )
211   {
212     mInheritanceMode[ index ] |= INHERIT_ORIENTATION;
213   }
214   else
215   {
216     mInheritanceMode[ index ] &= ~INHERIT_ORIENTATION;
217   }
218
219   mComponentDirty[index] = true;
220 }
221
222 void TransformManager::ResetToBaseValue()
223 {
224   if( mComponentCount )
225   {
226     memcpy( &mTxComponentAnimatable[0], &mTxComponentAnimatableBaseValue[0], sizeof(TransformComponentAnimatable)*mComponentCount );
227     memcpy( &mSize[0], &mSizeBase[0], sizeof(Vector3)*mComponentCount );
228     memset( &mLocalMatrixDirty[0], false, sizeof(bool)*mComponentCount );
229   }
230 }
231
232 void TransformManager::Update()
233 {
234   if( mReorder )
235   {
236     //If some transform component has change its parent or has been removed since last update
237     //we need to reorder the vectors
238     ReorderComponents();
239     mReorder = false;
240   }
241
242   //Iterate through all components to compute its world matrix
243   Vector3 centerPosition;
244   Vector3 localPosition;
245   const Vector3 half( 0.5f,0.5f,0.5f );
246   const Vector3 topLeft( 0.0f, 0.0f, 0.5f );
247   for( unsigned int i(0); i<mComponentCount; ++i )
248   {
249     if( DALI_LIKELY( mInheritanceMode[i] != DONT_INHERIT_TRANSFORM && mParent[i] != INVALID_TRANSFORM_ID ) )
250     {
251       const unsigned int& parentIndex = mIds[mParent[i] ];
252       if( DALI_LIKELY( mInheritanceMode[i] == INHERIT_ALL ) )
253       {
254         if( mComponentDirty[i] || mLocalMatrixDirty[parentIndex])
255         {
256           //Full transform inherited
257           mLocalMatrixDirty[i] = true;
258           CalculateCenterPosition( centerPosition, mTxComponentStatic[ i ], mTxComponentAnimatable[ i ], mSize[ i ], half, topLeft );
259           localPosition = mTxComponentAnimatable[i].mPosition + centerPosition + ( mTxComponentStatic[i].mParentOrigin - half ) *  mSize[parentIndex];
260           mLocal[i].SetTransformComponents( mTxComponentAnimatable[i].mScale, mTxComponentAnimatable[i].mOrientation, localPosition );
261         }
262
263         //Update the world matrix
264         Matrix::Multiply( mWorld[i], mLocal[i], mWorld[parentIndex]);
265       }
266       else
267       {
268         //Some components are not inherited
269         Vector3 parentPosition, parentScale;
270         Quaternion parentOrientation;
271         const Matrix& parentMatrix = mWorld[parentIndex];
272         parentMatrix.GetTransformComponents( parentPosition, parentOrientation, parentScale );
273
274         Vector3 localScale = mTxComponentAnimatable[i].mScale;
275         if( (mInheritanceMode[i] & INHERIT_SCALE) == 0 )
276         {
277           //Don't inherit scale
278           localScale /= parentScale;
279         }
280
281         Quaternion localOrientation( mTxComponentAnimatable[i].mOrientation );
282         if( (mInheritanceMode[i] & INHERIT_ORIENTATION) == 0 )
283         {
284           //Don't inherit orientation
285           parentOrientation.Invert();
286           localOrientation = parentOrientation * mTxComponentAnimatable[i].mOrientation;
287         }
288
289         if( (mInheritanceMode[i] & INHERIT_POSITION) == 0 )
290         {
291           //Don't inherit position
292           mLocal[i].SetTransformComponents( localScale, localOrientation, Vector3::ZERO );
293           Matrix::Multiply( mWorld[i], mLocal[i], parentMatrix );
294           mWorld[i].SetTranslation( mTxComponentAnimatable[i].mPosition);
295         }
296         else
297         {
298           CalculateCenterPosition( centerPosition, mTxComponentStatic[ i ], mTxComponentAnimatable[ i ], mSize[ i ], half, topLeft );
299           localPosition = mTxComponentAnimatable[i].mPosition + centerPosition + ( mTxComponentStatic[i].mParentOrigin - half ) *  mSize[parentIndex];
300           mLocal[i].SetTransformComponents( localScale, localOrientation, localPosition );
301           Matrix::Multiply( mWorld[i], mLocal[i], parentMatrix );
302         }
303
304         mLocalMatrixDirty[i] = true;
305       }
306     }
307     else  //Component has no parent or doesn't inherit transform
308     {
309       CalculateCenterPosition( centerPosition, mTxComponentStatic[ i ], mTxComponentAnimatable[ i ], mSize[ i ], half, topLeft );
310       localPosition = mTxComponentAnimatable[i].mPosition + centerPosition;
311       mLocal[i].SetTransformComponents( mTxComponentAnimatable[i].mScale, mTxComponentAnimatable[i].mOrientation, localPosition );
312       mWorld[i] = mLocal[i];
313       mLocalMatrixDirty[i] = true;
314     }
315
316     //Update the bounding sphere
317     Vec3 centerToEdge = { mSize[i].Length() * 0.5f, 0.0f, 0.0f };
318     Vec3 centerToEdgeWorldSpace;
319     TransformVector3( centerToEdgeWorldSpace, mWorld[i].AsFloat(), centerToEdge );
320
321     mBoundingSpheres[i] = mWorld[i].GetTranslation();
322     mBoundingSpheres[i].w = Length( centerToEdgeWorldSpace );
323
324     mComponentDirty[i] = false;
325   }
326 }
327
328 void TransformManager::SwapComponents( unsigned int i, unsigned int j )
329 {
330   std::swap( mTxComponentAnimatable[i], mTxComponentAnimatable[j] );
331   std::swap( mTxComponentStatic[i], mTxComponentStatic[j] );
332   std::swap( mInheritanceMode[i], mInheritanceMode[j] );
333   std::swap( mSize[i], mSize[j] );
334   std::swap( mParent[i], mParent[j] );
335   std::swap( mComponentId[i], mComponentId[j] );
336   std::swap( mTxComponentAnimatableBaseValue[i], mTxComponentAnimatableBaseValue[j] );
337   std::swap( mSizeBase[i], mSizeBase[j] );
338   std::swap( mLocal[i], mLocal[j] );
339   std::swap( mComponentDirty[i], mComponentDirty[j] );
340   std::swap( mBoundingSpheres[i], mBoundingSpheres[j] );
341   std::swap( mWorld[i], mWorld[j] );
342
343   mIds[ mComponentId[i] ] = i;
344   mIds[ mComponentId[j] ] = j;
345 }
346
347 void TransformManager::ReorderComponents()
348 {
349   mOrderedComponents.Resize(mComponentCount);
350
351   TransformId parentId;
352   for( size_t i(0); i<mComponentCount; ++i )
353   {
354     mOrderedComponents[i].id = mComponentId[i];
355     mOrderedComponents[i].level = 0u;
356
357     parentId = mParent[i];
358     while( parentId != INVALID_TRANSFORM_ID )
359     {
360       mOrderedComponents[i].level++;
361       parentId = mParent[ mIds[parentId] ];
362     }
363   }
364
365   std::stable_sort( mOrderedComponents.Begin(), mOrderedComponents.End());
366   unsigned int previousIndex = 0;
367   for( size_t newIndex(0); newIndex<mComponentCount-1; ++newIndex )
368   {
369     previousIndex = mIds[mOrderedComponents[newIndex].id];
370     if( previousIndex != newIndex )
371     {
372       SwapComponents( previousIndex, newIndex);
373     }
374   }
375 }
376
377 Vector3& TransformManager::GetVector3PropertyValue( TransformId id, TransformManagerProperty property )
378 {
379   switch( property )
380   {
381     case TRANSFORM_PROPERTY_POSITION:
382     {
383       unsigned int index( mIds[id] );
384       mComponentDirty[ index ] = true;
385       return mTxComponentAnimatable[ index ].mPosition;
386     }
387     case TRANSFORM_PROPERTY_SCALE:
388     {
389       unsigned int index( mIds[id] );
390       mComponentDirty[ index ] = true;
391       return mTxComponentAnimatable[ index ].mScale;
392     }
393     case TRANSFORM_PROPERTY_PARENT_ORIGIN:
394     {
395       unsigned int index( mIds[id] );
396       mComponentDirty[ index ] = true;
397       return mTxComponentStatic[ index ].mParentOrigin;
398     }
399     case TRANSFORM_PROPERTY_ANCHOR_POINT:
400     {
401       unsigned int index( mIds[id] );
402       mComponentDirty[ index ] = true;
403       return mTxComponentStatic[ index ].mAnchorPoint;
404     }
405     case TRANSFORM_PROPERTY_SIZE:
406     {
407       unsigned int index( mIds[id] );
408       mComponentDirty[ index ] = true;
409       return mSize[ index ];
410     }
411     default:
412     {
413       DALI_ASSERT_ALWAYS(false);
414       return mTxComponentAnimatable[ mIds[id] ].mPosition;
415     }
416   }
417 }
418
419 const Vector3& TransformManager::GetVector3PropertyValue( TransformId id, TransformManagerProperty property ) const
420 {
421   switch( property )
422   {
423     case TRANSFORM_PROPERTY_POSITION:
424     {
425       return mTxComponentAnimatable[ mIds[id] ].mPosition;
426     }
427     case TRANSFORM_PROPERTY_SCALE:
428     {
429       return mTxComponentAnimatable[ mIds[id] ].mScale;
430     }
431     case TRANSFORM_PROPERTY_PARENT_ORIGIN:
432     {
433       return mTxComponentStatic[ mIds[id] ].mParentOrigin;
434     }
435     case TRANSFORM_PROPERTY_ANCHOR_POINT:
436     {
437       return mTxComponentStatic[ mIds[id] ].mAnchorPoint;
438     }
439     case TRANSFORM_PROPERTY_SIZE:
440     {
441       return mSize[ mIds[id] ];
442     }
443     default:
444     {
445       DALI_ASSERT_ALWAYS(false);
446       return mTxComponentAnimatable[ mIds[id] ].mPosition;
447     }
448   }
449 }
450
451 const float& TransformManager::GetVector3PropertyComponentValue(TransformId id, TransformManagerProperty property, unsigned int component ) const
452 {
453   switch( property )
454   {
455     case TRANSFORM_PROPERTY_POSITION:
456     {
457       return mTxComponentAnimatable[ mIds[id] ].mPosition[component];
458     }
459     case TRANSFORM_PROPERTY_SCALE:
460     {
461       return mTxComponentAnimatable[ mIds[id] ].mScale[component];
462     }
463     case TRANSFORM_PROPERTY_PARENT_ORIGIN:
464     {
465       return mTxComponentStatic[ mIds[id] ].mParentOrigin[component];
466     }
467     case TRANSFORM_PROPERTY_ANCHOR_POINT:
468     {
469       return mTxComponentStatic[ mIds[id] ].mAnchorPoint[component];
470     }
471     case TRANSFORM_PROPERTY_SIZE:
472     {
473       return mSize[ mIds[id] ][component];
474     }
475     default:
476     {
477       DALI_ASSERT_ALWAYS(false);
478       return mTxComponentAnimatable[ mIds[id] ].mPosition[component];
479     }
480   }
481 }
482
483 void TransformManager::SetVector3PropertyValue( TransformId id, TransformManagerProperty property, const Vector3& value )
484 {
485   unsigned int index( mIds[id] );
486   mComponentDirty[ index ] = true;
487
488   switch( property )
489   {
490     case TRANSFORM_PROPERTY_POSITION:
491     {
492       mTxComponentAnimatable[ index ].mPosition = value;
493       break;
494     }
495     case TRANSFORM_PROPERTY_SCALE:
496     {
497       mTxComponentAnimatable[ index ].mScale = value;
498       break;
499     }
500     case TRANSFORM_PROPERTY_PARENT_ORIGIN:
501     {
502       mTxComponentStatic[ index ].mParentOrigin = value;
503       break;
504     }
505     case TRANSFORM_PROPERTY_ANCHOR_POINT:
506     {
507       mTxComponentStatic[ index ].mAnchorPoint = value;
508       break;
509     }
510     case TRANSFORM_PROPERTY_SIZE:
511     {
512       mSize[ index ] = value;
513       break;
514     }
515     default:
516     {
517       DALI_ASSERT_ALWAYS(false);
518     }
519   }
520 }
521
522 void TransformManager::SetVector3PropertyComponentValue( TransformId id, TransformManagerProperty property, float value, unsigned int component )
523 {
524   unsigned int index( mIds[id] );
525   mComponentDirty[ index ] = true;
526
527   switch( property )
528   {
529     case TRANSFORM_PROPERTY_POSITION:
530     {
531       mTxComponentAnimatable[ index ].mPosition[component] = value;
532       break;
533     }
534     case TRANSFORM_PROPERTY_SCALE:
535     {
536       mTxComponentAnimatable[ index ].mScale[component] = value;
537       break;
538     }
539     case TRANSFORM_PROPERTY_PARENT_ORIGIN:
540     {
541       mTxComponentStatic[ index ].mParentOrigin[component] = value;
542       break;
543     }
544     case TRANSFORM_PROPERTY_ANCHOR_POINT:
545     {
546       mTxComponentStatic[ index ].mAnchorPoint[component] = value;
547       break;
548     }
549     case TRANSFORM_PROPERTY_SIZE:
550     {
551       mSize[ index ][component] = value;
552       break;
553     }
554     default:
555     {
556       DALI_ASSERT_ALWAYS(false);
557     }
558   }
559 }
560
561 void TransformManager::BakeVector3PropertyValue( TransformId id, TransformManagerProperty property, const Vector3& value )
562 {
563   unsigned int index( mIds[id] );
564   mComponentDirty[ index ] = true;
565
566   switch( property )
567   {
568     case TRANSFORM_PROPERTY_POSITION:
569     {
570       mTxComponentAnimatable[ index ].mPosition = mTxComponentAnimatableBaseValue[index].mPosition = value;
571       break;
572     }
573     case TRANSFORM_PROPERTY_SCALE:
574     {
575       mTxComponentAnimatable[ index ].mScale = mTxComponentAnimatableBaseValue[index].mScale = value;
576       break;
577     }
578     case TRANSFORM_PROPERTY_PARENT_ORIGIN:
579     {
580       mTxComponentStatic[ index ].mParentOrigin = value;
581       break;
582     }
583     case TRANSFORM_PROPERTY_ANCHOR_POINT:
584     {
585       mTxComponentStatic[ index ].mAnchorPoint = value;
586       break;
587     }
588     case TRANSFORM_PROPERTY_SIZE:
589     {
590       mSize[ index ] = mSizeBase[index] = value;
591       break;
592     }
593     default:
594     {
595       DALI_ASSERT_ALWAYS(false);
596     }
597   }
598 }
599
600 void TransformManager::BakeRelativeVector3PropertyValue( TransformId id, TransformManagerProperty property, const Vector3& value )
601 {
602   unsigned int index( mIds[id] );
603   mComponentDirty[ index ] = true;
604
605   switch( property )
606   {
607     case TRANSFORM_PROPERTY_POSITION:
608     {
609       mTxComponentAnimatable[ index ].mPosition = mTxComponentAnimatableBaseValue[index].mPosition = mTxComponentAnimatable[ index ].mPosition + value;
610       break;
611     }
612     case TRANSFORM_PROPERTY_SCALE:
613     {
614       mTxComponentAnimatable[ index ].mScale = mTxComponentAnimatableBaseValue[index].mScale = mTxComponentAnimatable[ index ].mScale + value;
615       break;
616     }
617     case TRANSFORM_PROPERTY_PARENT_ORIGIN:
618     {
619       mTxComponentStatic[ index ].mParentOrigin = mTxComponentStatic[ index ].mParentOrigin + value;
620       break;
621     }
622     case TRANSFORM_PROPERTY_ANCHOR_POINT:
623     {
624       mTxComponentStatic[ index ].mAnchorPoint = mTxComponentStatic[ index ].mAnchorPoint + value;
625       break;
626     }
627     case TRANSFORM_PROPERTY_SIZE:
628     {
629       mSize[ index ] = mSizeBase[index] = mSize[ index ] + value;
630       break;
631     }
632     default:
633     {
634       DALI_ASSERT_ALWAYS(false);
635     }
636   }
637 }
638
639 void TransformManager::BakeMultiplyVector3PropertyValue( TransformId id, TransformManagerProperty property, const Vector3& value )
640 {
641   unsigned int index( mIds[id] );
642   mComponentDirty[ index ] = true;
643
644   switch( property )
645   {
646     case TRANSFORM_PROPERTY_POSITION:
647     {
648       mTxComponentAnimatable[ index ].mPosition = mTxComponentAnimatableBaseValue[index].mPosition = mTxComponentAnimatable[ index ].mPosition * value;
649       break;
650     }
651     case TRANSFORM_PROPERTY_SCALE:
652     {
653       mTxComponentAnimatable[ index ].mScale = mTxComponentAnimatableBaseValue[index].mScale = mTxComponentAnimatable[ index ].mScale * value;
654       break;
655     }
656     case TRANSFORM_PROPERTY_PARENT_ORIGIN:
657     {
658       mTxComponentStatic[ index ].mParentOrigin = mTxComponentStatic[ index ].mParentOrigin * value;
659       break;
660     }
661     case TRANSFORM_PROPERTY_ANCHOR_POINT:
662     {
663       mTxComponentStatic[ index ].mAnchorPoint = mTxComponentStatic[ index ].mAnchorPoint * value;
664       break;
665     }
666     case TRANSFORM_PROPERTY_SIZE:
667     {
668       mSize[ index ] = mSizeBase[index] = mSize[ index ] * value;
669       break;
670     }
671     default:
672     {
673       DALI_ASSERT_ALWAYS(false);
674     }
675   }
676 }
677
678 void TransformManager::BakeVector3PropertyComponentValue( TransformId id, TransformManagerProperty property, float value, unsigned int component )
679 {
680   unsigned int index( mIds[id] );
681   mComponentDirty[ index ] = true;
682
683   switch( property )
684   {
685     case TRANSFORM_PROPERTY_POSITION:
686     {
687       mTxComponentAnimatable[ index ].mPosition[component] = mTxComponentAnimatableBaseValue[index].mPosition[component] = value;
688       break;
689     }
690     case TRANSFORM_PROPERTY_SCALE:
691     {
692       mTxComponentAnimatable[ index ].mScale[component] = mTxComponentAnimatableBaseValue[index].mScale[component] = value;
693       break;
694     }
695     case TRANSFORM_PROPERTY_PARENT_ORIGIN:
696     {
697       mTxComponentStatic[ index ].mParentOrigin[component] = value;
698       break;
699     }
700     case TRANSFORM_PROPERTY_ANCHOR_POINT:
701     {
702       mTxComponentStatic[ index ].mAnchorPoint[component] = value;
703       break;
704     }
705     case TRANSFORM_PROPERTY_SIZE:
706     {
707       mSize[ index ][component] = mSizeBase[index][component] = value;
708       break;
709     }
710     default:
711     {
712       DALI_ASSERT_ALWAYS(false);
713     }
714   }
715 }
716
717 void TransformManager::BakeXVector3PropertyValue( TransformId id, TransformManagerProperty property, float value )
718 {
719   unsigned int index( mIds[id] );
720   mComponentDirty[ index ] = true;
721
722   switch( property )
723   {
724     case TRANSFORM_PROPERTY_POSITION:
725     {
726       mTxComponentAnimatable[ index ].mPosition.x = mTxComponentAnimatableBaseValue[index].mPosition.x = value;
727       break;
728     }
729     case TRANSFORM_PROPERTY_SCALE:
730     {
731       mTxComponentAnimatable[ index ].mScale.x = mTxComponentAnimatableBaseValue[index].mScale.x = value;
732       break;
733     }
734     case TRANSFORM_PROPERTY_PARENT_ORIGIN:
735     {
736       mTxComponentStatic[ index ].mParentOrigin.x = value;
737       break;
738     }
739     case TRANSFORM_PROPERTY_ANCHOR_POINT:
740     {
741       mTxComponentStatic[ index ].mAnchorPoint.x = value;
742       break;
743     }
744     case TRANSFORM_PROPERTY_SIZE:
745     {
746       mSize[ index ].x = mSizeBase[index].x = value;
747       break;
748     }
749     default:
750     {
751       DALI_ASSERT_ALWAYS(false);
752     }
753   }
754 }
755
756 void TransformManager::BakeYVector3PropertyValue( TransformId id, TransformManagerProperty property, float value )
757 {
758   unsigned int index( mIds[id] );
759   mComponentDirty[ index ] = true;
760
761   switch( property )
762   {
763     case TRANSFORM_PROPERTY_POSITION:
764     {
765       mTxComponentAnimatable[ index ].mPosition.y = mTxComponentAnimatableBaseValue[index].mPosition.y = value;
766       break;
767     }
768     case TRANSFORM_PROPERTY_SCALE:
769     {
770       mTxComponentAnimatable[ index ].mScale.y = mTxComponentAnimatableBaseValue[index].mScale.y = value;
771       break;
772     }
773     case TRANSFORM_PROPERTY_PARENT_ORIGIN:
774     {
775       mTxComponentStatic[ index ].mParentOrigin.y = value;
776       break;
777     }
778     case TRANSFORM_PROPERTY_ANCHOR_POINT:
779     {
780       mTxComponentStatic[ index ].mAnchorPoint.y = value;
781       break;
782     }
783     case TRANSFORM_PROPERTY_SIZE:
784     {
785       mSize[ index ].y = mSizeBase[index].y = value;
786       break;
787     }
788     default:
789     {
790       DALI_ASSERT_ALWAYS(false);
791     }
792   }
793 }
794
795 void TransformManager::BakeZVector3PropertyValue( TransformId id, TransformManagerProperty property, float value )
796 {
797   unsigned int index( mIds[id] );
798   mComponentDirty[ index ] = true;
799
800   switch( property )
801   {
802     case TRANSFORM_PROPERTY_POSITION:
803     {
804       mTxComponentAnimatable[ index ].mPosition.z = mTxComponentAnimatableBaseValue[index].mPosition.z = value;
805       break;
806     }
807     case TRANSFORM_PROPERTY_SCALE:
808     {
809       mTxComponentAnimatable[ index ].mScale.z = mTxComponentAnimatableBaseValue[index].mScale.z = value;
810       break;
811     }
812     case TRANSFORM_PROPERTY_PARENT_ORIGIN:
813     {
814       mTxComponentStatic[ index ].mParentOrigin.z = value;
815       break;
816     }
817     case TRANSFORM_PROPERTY_ANCHOR_POINT:
818     {
819       mTxComponentStatic[ index ].mAnchorPoint.z = value;
820       break;
821     }
822     case TRANSFORM_PROPERTY_SIZE:
823     {
824       mSize[ index ].z = mSizeBase[index].z = value;
825       break;
826     }
827     default:
828     {
829       DALI_ASSERT_ALWAYS(false);
830     }
831   }
832 }
833
834 Quaternion& TransformManager::GetQuaternionPropertyValue( TransformId id )
835 {
836   unsigned int index( mIds[id] );
837   mComponentDirty[ index ] = true;
838   return mTxComponentAnimatable[ index ].mOrientation;
839 }
840
841 const Quaternion& TransformManager::GetQuaternionPropertyValue( TransformId id ) const
842 {
843   return mTxComponentAnimatable[ mIds[id] ].mOrientation;
844 }
845
846 void TransformManager::SetQuaternionPropertyValue( TransformId id, const Quaternion& q )
847 {
848   unsigned int index( mIds[id] );
849   mTxComponentAnimatable[ index ].mOrientation = q;
850   mComponentDirty[ index ] = true;
851 }
852
853 void TransformManager::BakeQuaternionPropertyValue( TransformId id, const Quaternion& q )
854 {
855   unsigned int index( mIds[id] );
856   mTxComponentAnimatable[ index ].mOrientation = mTxComponentAnimatableBaseValue[index].mOrientation = q;
857   mComponentDirty[ index ] = true;
858 }
859
860 void TransformManager::BakeRelativeQuaternionPropertyValue( TransformId id, const Quaternion& q )
861 {
862   unsigned int index( mIds[id] );
863   mTxComponentAnimatable[ index ].mOrientation = mTxComponentAnimatableBaseValue[index].mOrientation = mTxComponentAnimatable[ index ].mOrientation * q;
864   mComponentDirty[ index ] = true;
865 }
866
867 const Vector4& TransformManager::GetBoundingSphere( TransformId id ) const
868 {
869   return mBoundingSpheres[ mIds[id] ];
870 }
871
872 void TransformManager::GetWorldMatrixAndSize( TransformId id, Matrix& worldMatrix, Vector3& size ) const
873 {
874   unsigned int index = mIds[id];
875   worldMatrix = mWorld[index];
876   size = mSize[index];
877 }
878
879 void TransformManager::SetPositionUsesAnchorPoint( TransformId id, bool value )
880 {
881   unsigned int index( mIds[ id ] );
882   mComponentDirty[ index ] = true;
883   mTxComponentStatic[ index ].mPositionUsesAnchorPoint = value;
884 }
885
886 } //namespace SceneGraph
887 } //namespace Internal
888 } //namespace Dali