Merge "use modern construct '= default' for special functions." into devel/master
[platform/core/uifw/dali-core.git] / dali / internal / update / manager / transform-manager.cpp
1 /*
2  * Copyright (c) 2020 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() = default;
86
87 TransformId TransformManager::CreateTransform()
88 {
89   //Get id for the new component
90   TransformId id = mIds.Add(mComponentCount);
91
92   if( mTxComponentAnimatable.Size() <= mComponentCount )
93   {
94     //Make room for another component
95     mTxComponentAnimatable.PushBack(TransformComponentAnimatable());
96     mTxComponentStatic.PushBack(TransformComponentStatic());
97     mInheritanceMode.PushBack(INHERIT_ALL);
98     mComponentId.PushBack(id);
99     mSize.PushBack(Vector3(0.0f,0.0f,0.0f));
100     mParent.PushBack(INVALID_TRANSFORM_ID);
101     mWorld.PushBack(Matrix::IDENTITY);
102     mLocal.PushBack(Matrix::IDENTITY);
103     mBoundingSpheres.PushBack( Vector4(0.0f,0.0f,0.0f,0.0f) );
104     mTxComponentAnimatableBaseValue.PushBack(TransformComponentAnimatable());
105     mSizeBase.PushBack(Vector3(0.0f,0.0f,0.0f));
106     mComponentDirty.PushBack(false);
107     mLocalMatrixDirty.PushBack(false);
108   }
109   else
110   {
111     //Set default values
112     memcpy( &mTxComponentAnimatable[mComponentCount], &gDefaultTransformComponentAnimatableData, sizeof( TransformComponentAnimatable ) );
113     memcpy( &mTxComponentStatic[mComponentCount], &gDefaultTransformComponentStaticData, sizeof( TransformComponentStatic ) );
114     memcpy( &mTxComponentAnimatableBaseValue[mComponentCount], &gDefaultTransformComponentAnimatableData, sizeof( TransformComponentAnimatable ) );
115     mInheritanceMode[mComponentCount] = INHERIT_ALL;
116     mComponentId[mComponentCount] = id;
117     mSize[mComponentCount] = Vector3(0.0f,0.0f,0.0f);
118     mParent[mComponentCount] = INVALID_TRANSFORM_ID;
119     mLocal[mComponentCount].SetIdentity();
120     mWorld[mComponentCount].SetIdentity();
121     mBoundingSpheres[mComponentCount] = Vector4(0.0f,0.0f,0.0f,0.0f);
122     mSizeBase[mComponentCount] = Vector3(0.0f,0.0f,0.0f);
123     mComponentDirty[mComponentCount] = false;
124     mLocalMatrixDirty[mComponentCount] = false;
125   }
126
127   mComponentCount++;
128   return id;
129 }
130
131 void TransformManager::RemoveTransform(TransformId id)
132 {
133   //Move the last element to the gap
134   mComponentCount--;
135   TransformId index = mIds[id];
136   mTxComponentAnimatable[index] = mTxComponentAnimatable[mComponentCount];
137   mTxComponentStatic[index] = mTxComponentStatic[mComponentCount];
138   mInheritanceMode[index] = mInheritanceMode[mComponentCount];
139   mSize[index] = mSize[mComponentCount];
140   mParent[index] = mParent[mComponentCount];
141   mWorld[index] = mWorld[mComponentCount];
142   mLocal[index] = mLocal[mComponentCount];
143   mTxComponentAnimatableBaseValue[index] = mTxComponentAnimatableBaseValue[mComponentCount];
144   mSizeBase[index] = mSizeBase[mComponentCount];
145   mComponentDirty[index] = mComponentDirty[mComponentCount];
146   mLocalMatrixDirty[index] = mLocalMatrixDirty[mComponentCount];
147   mBoundingSpheres[index] = mBoundingSpheres[mComponentCount];
148
149   TransformId lastItemId = mComponentId[mComponentCount];
150   mIds[ lastItemId ] = index;
151   mComponentId[index] = lastItemId;
152   mIds.Remove( id );
153
154   mReorder = true;
155 }
156
157 void TransformManager::SetParent( TransformId id, TransformId parentId )
158 {
159   DALI_ASSERT_ALWAYS( id != parentId );
160   TransformId index = mIds[id];
161   mParent[ index ] = parentId;
162   mComponentDirty[ index ] = true;
163   mReorder = true;
164 }
165
166 const Matrix& TransformManager::GetWorldMatrix( TransformId id ) const
167 {
168   return mWorld[ mIds[id] ];
169 }
170
171 Matrix& TransformManager::GetWorldMatrix( TransformId id )
172 {
173   return mWorld[ mIds[id] ];
174 }
175
176 void TransformManager::SetInheritPosition( TransformId id, bool inherit )
177 {
178   TransformId index = mIds[id];
179   if( inherit )
180   {
181     mInheritanceMode[ index ] |= INHERIT_POSITION;
182   }
183   else
184   {
185     mInheritanceMode[ index ] &= ~INHERIT_POSITION;
186   }
187
188   mComponentDirty[index] = true;
189 }
190
191 void TransformManager::SetInheritScale( TransformId id, bool inherit )
192 {
193   TransformId index = mIds[id];
194   if( inherit )
195   {
196     mInheritanceMode[ index ] |= INHERIT_SCALE;
197   }
198   else
199   {
200     mInheritanceMode[ index ] &= ~INHERIT_SCALE;
201   }
202
203   mComponentDirty[index] = true;
204 }
205
206 void TransformManager::SetInheritOrientation( TransformId id, bool inherit )
207 {
208   TransformId index = mIds[id];
209   if( inherit )
210   {
211     mInheritanceMode[ index ] |= INHERIT_ORIENTATION;
212   }
213   else
214   {
215     mInheritanceMode[ index ] &= ~INHERIT_ORIENTATION;
216   }
217
218   mComponentDirty[index] = true;
219 }
220
221 void TransformManager::ResetToBaseValue()
222 {
223   if( mComponentCount )
224   {
225     memcpy( &mTxComponentAnimatable[0], &mTxComponentAnimatableBaseValue[0], sizeof(TransformComponentAnimatable)*mComponentCount );
226     memcpy( &mSize[0], &mSizeBase[0], sizeof(Vector3)*mComponentCount );
227     memset( &mLocalMatrixDirty[0], false, sizeof(bool)*mComponentCount );
228   }
229 }
230
231 bool TransformManager::Update()
232 {
233   bool componentsChanged = false;
234
235   if( mReorder )
236   {
237     //If some transform component has change its parent or has been removed since last update
238     //we need to reorder the vectors
239     ReorderComponents();
240     mReorder = false;
241   }
242
243   //Iterate through all components to compute its world matrix
244   Vector3 centerPosition;
245   Vector3 localPosition;
246   const Vector3 half( 0.5f,0.5f,0.5f );
247   const Vector3 topLeft( 0.0f, 0.0f, 0.5f );
248   for( unsigned int i(0); i<mComponentCount; ++i )
249   {
250     if( DALI_LIKELY( mInheritanceMode[i] != DONT_INHERIT_TRANSFORM && mParent[i] != INVALID_TRANSFORM_ID ) )
251     {
252       const TransformId& parentIndex = mIds[mParent[i] ];
253       if( DALI_LIKELY( mInheritanceMode[i] == INHERIT_ALL ) )
254       {
255         if( mComponentDirty[i] || mLocalMatrixDirty[parentIndex])
256         {
257           //Full transform inherited
258           mLocalMatrixDirty[i] = true;
259           CalculateCenterPosition( centerPosition, mTxComponentStatic[ i ], mTxComponentAnimatable[ i ], mSize[ i ], half, topLeft );
260           localPosition = mTxComponentAnimatable[i].mPosition + centerPosition + ( mTxComponentStatic[i].mParentOrigin - half ) *  mSize[parentIndex];
261           mLocal[i].SetTransformComponents( mTxComponentAnimatable[i].mScale, mTxComponentAnimatable[i].mOrientation, localPosition );
262         }
263
264         //Update the world matrix
265         Matrix::Multiply( mWorld[i], mLocal[i], mWorld[parentIndex]);
266       }
267       else
268       {
269         //Some components are not inherited
270         Vector3 parentPosition, parentScale;
271         Quaternion parentOrientation;
272         const Matrix& parentMatrix = mWorld[parentIndex];
273         parentMatrix.GetTransformComponents( parentPosition, parentOrientation, parentScale );
274
275         Vector3 localScale = mTxComponentAnimatable[i].mScale;
276         if( (mInheritanceMode[i] & INHERIT_SCALE) == 0 )
277         {
278           //Don't inherit scale
279           localScale /= parentScale;
280         }
281
282         Quaternion localOrientation( mTxComponentAnimatable[i].mOrientation );
283         if( (mInheritanceMode[i] & INHERIT_ORIENTATION) == 0 )
284         {
285           //Don't inherit orientation
286           parentOrientation.Invert();
287           localOrientation = parentOrientation * mTxComponentAnimatable[i].mOrientation;
288         }
289
290         if( (mInheritanceMode[i] & INHERIT_POSITION) == 0 )
291         {
292           //Don't inherit position
293           CalculateCenterPosition( centerPosition, mTxComponentStatic[ i ], mTxComponentAnimatable[ i ], mSize[ i ], half, topLeft );
294           mLocal[i].SetTransformComponents( localScale, localOrientation, Vector3::ZERO );
295           Matrix::Multiply( mWorld[i], mLocal[i], parentMatrix );
296           mWorld[i].SetTranslation( mTxComponentAnimatable[i].mPosition + centerPosition );
297         }
298         else
299         {
300           CalculateCenterPosition( centerPosition, mTxComponentStatic[ i ], mTxComponentAnimatable[ i ], mSize[ i ], half, topLeft );
301           localPosition = mTxComponentAnimatable[i].mPosition + centerPosition + ( mTxComponentStatic[i].mParentOrigin - half ) *  mSize[parentIndex];
302           mLocal[i].SetTransformComponents( localScale, localOrientation, localPosition );
303           Matrix::Multiply( mWorld[i], mLocal[i], parentMatrix );
304         }
305
306         mLocalMatrixDirty[i] = true;
307       }
308     }
309     else  //Component has no parent or doesn't inherit transform
310     {
311       CalculateCenterPosition( centerPosition, mTxComponentStatic[ i ], mTxComponentAnimatable[ i ], mSize[ i ], half, topLeft );
312       localPosition = mTxComponentAnimatable[i].mPosition + centerPosition;
313       mLocal[i].SetTransformComponents( mTxComponentAnimatable[i].mScale, mTxComponentAnimatable[i].mOrientation, localPosition );
314       mWorld[i] = mLocal[i];
315       mLocalMatrixDirty[i] = true;
316     }
317
318     //Update the bounding sphere
319     Vec3 centerToEdge = { mSize[i].Length() * 0.5f, 0.0f, 0.0f };
320     Vec3 centerToEdgeWorldSpace;
321     TransformVector3( centerToEdgeWorldSpace, mWorld[i].AsFloat(), centerToEdge );
322
323     mBoundingSpheres[i] = mWorld[i].GetTranslation();
324     mBoundingSpheres[i].w = Length( centerToEdgeWorldSpace );
325
326     componentsChanged = componentsChanged || mComponentDirty[i];
327     mComponentDirty[i] = false;
328   }
329
330   return componentsChanged;
331 }
332
333 void TransformManager::SwapComponents( unsigned int i, unsigned int j )
334 {
335   std::swap( mTxComponentAnimatable[i], mTxComponentAnimatable[j] );
336   std::swap( mTxComponentStatic[i], mTxComponentStatic[j] );
337   std::swap( mInheritanceMode[i], mInheritanceMode[j] );
338   std::swap( mSize[i], mSize[j] );
339   std::swap( mParent[i], mParent[j] );
340   std::swap( mComponentId[i], mComponentId[j] );
341   std::swap( mTxComponentAnimatableBaseValue[i], mTxComponentAnimatableBaseValue[j] );
342   std::swap( mSizeBase[i], mSizeBase[j] );
343   std::swap( mLocal[i], mLocal[j] );
344   std::swap( mComponentDirty[i], mComponentDirty[j] );
345   std::swap( mBoundingSpheres[i], mBoundingSpheres[j] );
346   std::swap( mWorld[i], mWorld[j] );
347
348   mIds[ mComponentId[i] ] = i;
349   mIds[ mComponentId[j] ] = j;
350 }
351
352 void TransformManager::ReorderComponents()
353 {
354   mOrderedComponents.Resize(mComponentCount);
355
356   TransformId parentId;
357   for( TransformId i = 0; i<mComponentCount; ++i )
358   {
359     mOrderedComponents[i].id = mComponentId[i];
360     mOrderedComponents[i].level = 0u;
361
362     parentId = mParent[i];
363     while( parentId != INVALID_TRANSFORM_ID )
364     {
365       mOrderedComponents[i].level++;
366       parentId = mParent[ mIds[parentId] ];
367     }
368   }
369
370   std::stable_sort( mOrderedComponents.Begin(), mOrderedComponents.End());
371   TransformId previousIndex = 0;
372   for( TransformId newIndex = 0; newIndex < mComponentCount-1; ++newIndex )
373   {
374     previousIndex = mIds[mOrderedComponents[newIndex].id];
375     if( previousIndex != newIndex )
376     {
377       SwapComponents( previousIndex, newIndex);
378     }
379   }
380 }
381
382 Vector3& TransformManager::GetVector3PropertyValue( TransformId id, TransformManagerProperty property )
383 {
384   switch( property )
385   {
386     case TRANSFORM_PROPERTY_POSITION:
387     {
388       TransformId index( mIds[id] );
389       return mTxComponentAnimatable[ index ].mPosition;
390     }
391     case TRANSFORM_PROPERTY_SCALE:
392     {
393       TransformId index( mIds[id] );
394       return mTxComponentAnimatable[ index ].mScale;
395     }
396     case TRANSFORM_PROPERTY_PARENT_ORIGIN:
397     {
398       TransformId index( mIds[id] );
399       return mTxComponentStatic[ index ].mParentOrigin;
400     }
401     case TRANSFORM_PROPERTY_ANCHOR_POINT:
402     {
403       TransformId index( mIds[id] );
404       return mTxComponentStatic[ index ].mAnchorPoint;
405     }
406     case TRANSFORM_PROPERTY_SIZE:
407     {
408       TransformId index( mIds[id] );
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   TransformId 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   TransformId 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   TransformId 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   TransformId 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   TransformId 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   TransformId 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   TransformId 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   TransformId 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   TransformId 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   TransformId index( mIds[id] );
837   return mTxComponentAnimatable[ index ].mOrientation;
838 }
839
840 const Quaternion& TransformManager::GetQuaternionPropertyValue( TransformId id ) const
841 {
842   return mTxComponentAnimatable[ mIds[id] ].mOrientation;
843 }
844
845 void TransformManager::SetQuaternionPropertyValue( TransformId id, const Quaternion& q )
846 {
847   TransformId index( mIds[id] );
848   mTxComponentAnimatable[ index ].mOrientation = q;
849   mComponentDirty[ index ] = true;
850 }
851
852 void TransformManager::BakeQuaternionPropertyValue( TransformId id, const Quaternion& q )
853 {
854   TransformId index( mIds[id] );
855   mTxComponentAnimatable[ index ].mOrientation = mTxComponentAnimatableBaseValue[index].mOrientation = q;
856   mComponentDirty[ index ] = true;
857 }
858
859 void TransformManager::BakeRelativeQuaternionPropertyValue( TransformId id, const Quaternion& q )
860 {
861   TransformId index( mIds[id] );
862   mTxComponentAnimatable[ index ].mOrientation = mTxComponentAnimatableBaseValue[index].mOrientation = mTxComponentAnimatable[ index ].mOrientation * q;
863   mComponentDirty[ index ] = true;
864 }
865
866 const Vector4& TransformManager::GetBoundingSphere( TransformId id ) const
867 {
868   return mBoundingSpheres[ mIds[id] ];
869 }
870
871 void TransformManager::GetWorldMatrixAndSize( TransformId id, Matrix& worldMatrix, Vector3& size ) const
872 {
873   TransformId index = mIds[id];
874   worldMatrix = mWorld[index];
875   size = mSize[index];
876 }
877
878 void TransformManager::SetPositionUsesAnchorPoint( TransformId id, bool value )
879 {
880   TransformId index( mIds[ id ] );
881   mComponentDirty[ index ] = true;
882   mTxComponentStatic[ index ].mPositionUsesAnchorPoint = value;
883 }
884
885 } //namespace SceneGraph
886 } //namespace Internal
887 } //namespace Dali