[dali_1.1.34] Merge branch 'devel/master'
[platform/core/uifw/dali-core.git] / dali / internal / update / manager / transform-manager.cpp
1 /*
2  * Copyright (c) 2016 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
25 //INTERNAL INCLUDES
26 #include <dali/public-api/common/constants.h>
27 #include <dali/public-api/common/compile-time-assert.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 };
46
47 DALI_COMPILE_TIME_ASSERT( sizeof(gDefaultTransformComponentAnimatableData) == sizeof(TransformComponentAnimatable) );
48 DALI_COMPILE_TIME_ASSERT( sizeof(gDefaultTransformComponentStaticData) == sizeof(TransformComponentStatic) );
49 }
50
51 TransformManager::TransformManager()
52 :mComponentCount(0),
53  mReorder(false)
54 {}
55
56 TransformManager::~TransformManager()
57 {}
58
59 TransformId TransformManager::CreateTransform()
60 {
61   //Get id for the new component
62   TransformId id = mIds.Add(mComponentCount);
63
64   if( mTxComponentAnimatable.Size() <= mComponentCount )
65   {
66     //Make room for another component
67     mTxComponentAnimatable.PushBack(TransformComponentAnimatable());
68     mTxComponentStatic.PushBack(TransformComponentStatic());
69     mInheritanceMode.PushBack(INHERIT_ALL);
70     mComponentId.PushBack(id);
71     mSize.PushBack(Vector3(0.0f,0.0f,0.0f));
72     mParent.PushBack(INVALID_TRANSFORM_ID);
73     mWorld.PushBack(Matrix::IDENTITY);
74     mLocal.PushBack(Matrix::IDENTITY);
75     mBoundingSpheres.PushBack( Vector4(0.0f,0.0f,0.0f,0.0f) );
76     mTxComponentAnimatableBaseValue.PushBack(TransformComponentAnimatable());
77     mSizeBase.PushBack(Vector3(0.0f,0.0f,0.0f));
78     mComponentDirty.PushBack(false);
79     mLocalMatrixDirty.PushBack(false);
80   }
81   else
82   {
83     //Set default values
84     memcpy( &mTxComponentAnimatable[mComponentCount], &gDefaultTransformComponentAnimatableData, sizeof( TransformComponentAnimatable ) );
85     memcpy( &mTxComponentStatic[mComponentCount], &gDefaultTransformComponentStaticData, sizeof( TransformComponentStatic ) );
86     memcpy( &mTxComponentAnimatableBaseValue[mComponentCount], &gDefaultTransformComponentAnimatableData, sizeof( TransformComponentAnimatable ) );
87     mInheritanceMode[mComponentCount] = INHERIT_ALL;
88     mComponentId[mComponentCount] = id;
89     mSize[mComponentCount] = Vector3(0.0f,0.0f,0.0f);
90     mParent[mComponentCount] = INVALID_TRANSFORM_ID;
91     mLocal[mComponentCount].SetIdentity();
92     mWorld[mComponentCount].SetIdentity();
93     mBoundingSpheres[mComponentCount] = Vector4(0.0f,0.0f,0.0f,0.0f);
94     mSizeBase[mComponentCount] = Vector3(0.0f,0.0f,0.0f);
95     mComponentDirty[mComponentCount] = false;
96     mLocalMatrixDirty[mComponentCount] = false;
97   }
98
99   mComponentCount++;
100   return id;
101 }
102
103 void TransformManager::RemoveTransform(TransformId id)
104 {
105   //Move the last element to the gap
106   mComponentCount--;
107   unsigned int index = mIds[id];
108   mTxComponentAnimatable[index] = mTxComponentAnimatable[mComponentCount];
109   mTxComponentStatic[index] = mTxComponentStatic[mComponentCount];
110   mInheritanceMode[index] = mInheritanceMode[mComponentCount];
111   mSize[index] = mSize[mComponentCount];
112   mParent[index] = mParent[mComponentCount];
113   mWorld[index] = mWorld[mComponentCount];
114   mLocal[index] = mLocal[mComponentCount];
115   mTxComponentAnimatableBaseValue[index] = mTxComponentAnimatableBaseValue[mComponentCount];
116   mSizeBase[index] = mSizeBase[mComponentCount];
117   mComponentDirty[index] = mComponentDirty[mComponentCount];
118   mLocalMatrixDirty[index] = mLocalMatrixDirty[mComponentCount];
119   mBoundingSpheres[index] = mBoundingSpheres[mComponentCount];
120
121   TransformId lastItemId = mComponentId[mComponentCount];
122   mIds[ lastItemId ] = index;
123   mComponentId[index] = lastItemId;
124   mIds.Remove( id );
125
126   mReorder = true;
127 }
128
129 void TransformManager::SetParent( TransformId id, TransformId parentId )
130 {
131   DALI_ASSERT_ALWAYS( id != parentId );
132   mParent[ mIds[id] ] = parentId;
133   mReorder = true;
134 }
135
136 const Matrix& TransformManager::GetWorldMatrix( TransformId id ) const
137 {
138   return mWorld[ mIds[id] ];
139 }
140
141 Matrix& TransformManager::GetWorldMatrix( TransformId id )
142 {
143   return mWorld[ mIds[id] ];
144 }
145
146 void TransformManager::SetInheritPosition( TransformId id, bool inherit )
147 {
148   unsigned int index = mIds[id];
149   if( inherit )
150   {
151     mInheritanceMode[ index ] |= INHERIT_POSITION;
152   }
153   else
154   {
155     mInheritanceMode[ index ] &= ~INHERIT_POSITION;
156   }
157
158   mComponentDirty[index] = true;
159 }
160
161 void TransformManager::SetInheritScale( TransformId id, bool inherit )
162 {
163   unsigned int index = mIds[id];
164   if( inherit )
165   {
166     mInheritanceMode[ index ] |= INHERIT_SCALE;
167   }
168   else
169   {
170     mInheritanceMode[ index ] &= ~INHERIT_SCALE;
171   }
172
173   mComponentDirty[index] = true;
174 }
175
176 void TransformManager::SetInheritOrientation( TransformId id, bool inherit )
177 {
178   unsigned int index = mIds[id];
179   if( inherit )
180   {
181     mInheritanceMode[ index ] |= INHERIT_ORIENTATION;
182   }
183   else
184   {
185     mInheritanceMode[ index ] &= ~INHERIT_ORIENTATION;
186   }
187
188   mComponentDirty[index] = true;
189 }
190
191 void TransformManager::ResetToBaseValue()
192 {
193   if( mComponentCount )
194   {
195     memcpy( &mTxComponentAnimatable[0], &mTxComponentAnimatableBaseValue[0], sizeof(TransformComponentAnimatable)*mComponentCount );
196     memcpy( &mSize[0], &mSizeBase[0], sizeof(Vector3)*mComponentCount );
197     memset( &mLocalMatrixDirty[0], false, sizeof(bool)*mComponentCount );
198   }
199 }
200
201 void TransformManager::Update()
202 {
203   if( mReorder )
204   {
205     //If some transform component has change its parent or has been removed since last update
206     //we need to reorder the vectors
207     ReorderComponents();
208     mReorder = false;
209   }
210
211   //Iterate through all components to compute its world matrix
212   Vector3 anchorPosition;
213   Vector3 localPosition;
214   Vector3 half( 0.5f,0.5f,0.5f );
215   for( unsigned int i(0); i<mComponentCount; ++i )
216   {
217     if( DALI_LIKELY( mInheritanceMode[i] != DONT_INHERIT_TRANSFORM && mParent[i] != INVALID_TRANSFORM_ID ) )
218     {
219       const unsigned int& parentIndex = mIds[mParent[i] ];
220       if( DALI_LIKELY( mInheritanceMode[i] == INHERIT_ALL ) )
221       {
222         if( mComponentDirty[i] || mLocalMatrixDirty[parentIndex])
223         {
224           //Full transform inherited
225           mComponentDirty[i] = false;
226           mLocalMatrixDirty[i] = true;
227
228           anchorPosition = ( half - mTxComponentStatic[i].mAnchorPoint ) * mSize[i] * mTxComponentAnimatable[i].mScale;
229           anchorPosition *= mTxComponentAnimatable[i].mOrientation;
230           localPosition = mTxComponentAnimatable[i].mPosition + anchorPosition + ( mTxComponentStatic[i].mParentOrigin - half ) *  mSize[parentIndex];
231           mLocal[i].SetTransformComponents( mTxComponentAnimatable[i].mScale,mTxComponentAnimatable[i].mOrientation, localPosition );
232         }
233
234         //Update the world matrix
235         Matrix::Multiply( mWorld[i], mLocal[i], mWorld[parentIndex]);
236       }
237       else
238       {
239         //Some components are not inherited
240         Vector3 parentPosition, parentScale;
241         Quaternion parentOrientation;
242         const Matrix& parentMatrix = mWorld[parentIndex];
243         parentMatrix.GetTransformComponents( parentPosition, parentOrientation, parentScale );
244
245         Vector3 localScale = mTxComponentAnimatable[i].mScale;
246         if( (mInheritanceMode[i] & INHERIT_SCALE) == 0 )
247         {
248           //Don't inherit scale
249           localScale /= parentScale;
250         }
251
252         Quaternion localOrientation( mTxComponentAnimatable[i].mOrientation );
253         if( (mInheritanceMode[i] & INHERIT_ORIENTATION) == 0 )
254         {
255           //Don't inherit orientation
256           parentOrientation.Invert();
257           localOrientation = parentOrientation * mTxComponentAnimatable[i].mOrientation;
258         }
259
260         if( (mInheritanceMode[i] & INHERIT_POSITION) == 0 )
261         {
262           //Don't inherit position
263           mLocal[i].SetTransformComponents( localScale, localOrientation, Vector3::ZERO );
264           Matrix::Multiply( mWorld[i], mLocal[i], parentMatrix );
265           mWorld[i].SetTranslation( mTxComponentAnimatable[i].mPosition);
266         }
267         else
268         {
269           anchorPosition = ( half - mTxComponentStatic[i].mAnchorPoint ) * mSize[i] * mTxComponentAnimatable[i].mScale;
270           anchorPosition *= mTxComponentAnimatable[i].mOrientation;
271           localPosition = mTxComponentAnimatable[i].mPosition + anchorPosition + ( mTxComponentStatic[i].mParentOrigin - half ) *  mSize[parentIndex];
272           mLocal[i].SetTransformComponents( localScale, localOrientation, localPosition );
273           Matrix::Multiply( mWorld[i], mLocal[i], parentMatrix );
274         }
275       }
276     }
277     else  //Component has no parent or doesn't inherit transform
278     {
279       anchorPosition = ( half - mTxComponentStatic[i].mAnchorPoint ) * mSize[i] * mTxComponentAnimatable[i].mScale;
280       anchorPosition *= mTxComponentAnimatable[i].mOrientation;
281       localPosition = mTxComponentAnimatable[i].mPosition + anchorPosition;
282       mWorld[i].SetTransformComponents( mTxComponentAnimatable[i].mScale, mTxComponentAnimatable[i].mOrientation, localPosition );
283     }
284
285     //Update the bounding sphere
286     Vec3 centerToEdge = { mSize[i].Length() * 0.5f, 0.0f, 0.0f };
287     Vec3 centerToEdgeWorldSpace;
288     TransformVector3( centerToEdgeWorldSpace, mWorld[i].AsFloat(), centerToEdge );
289
290     mBoundingSpheres[i] = mWorld[i].GetTranslation();
291     mBoundingSpheres[i].w = Length( centerToEdgeWorldSpace );
292   }
293 }
294
295 void TransformManager::SwapComponents( unsigned int i, unsigned int j )
296 {
297   std::swap( mTxComponentAnimatable[i], mTxComponentAnimatable[j] );
298   std::swap( mTxComponentStatic[i], mTxComponentStatic[j] );
299   std::swap( mInheritanceMode[i], mInheritanceMode[j] );
300   std::swap( mSize[i], mSize[j] );
301   std::swap( mParent[i], mParent[j] );
302   std::swap( mComponentId[i], mComponentId[j] );
303   std::swap( mTxComponentAnimatableBaseValue[i], mTxComponentAnimatableBaseValue[j] );
304   std::swap( mSizeBase[i], mSizeBase[j] );
305   std::swap( mLocal[i], mLocal[j] );
306   std::swap( mComponentDirty[i], mComponentDirty[j] );
307   std::swap( mBoundingSpheres[i], mBoundingSpheres[j] );
308
309   mIds[ mComponentId[i] ] = i;
310   mIds[ mComponentId[j] ] = j;
311 }
312
313 void TransformManager::ReorderComponents()
314 {
315   mOrderedComponents.Resize(mComponentCount);
316
317   TransformId parentId;
318   for( size_t i(0); i<mComponentCount; ++i )
319   {
320     mOrderedComponents[i].id = mComponentId[i];
321     mOrderedComponents[i].level = 0u;
322
323     parentId = mParent[i];
324     while( parentId != INVALID_TRANSFORM_ID )
325     {
326       mOrderedComponents[i].level++;
327       parentId = mParent[ mIds[parentId] ];
328     }
329   }
330
331   std::sort( mOrderedComponents.Begin(), mOrderedComponents.End());
332   for( size_t i(0); i<mComponentCount-1; ++i )
333   {
334     SwapComponents( mIds[mOrderedComponents[i].id], i);
335   }
336 }
337
338 Vector3& TransformManager::GetVector3PropertyValue( TransformId id, TransformManagerProperty property )
339 {
340   switch( property )
341   {
342     case TRANSFORM_PROPERTY_POSITION:
343     {
344       unsigned int index( mIds[id] );
345       mComponentDirty[ index ] = true;
346       return mTxComponentAnimatable[ index ].mPosition;
347     }
348     case TRANSFORM_PROPERTY_SCALE:
349     {
350       unsigned int index( mIds[id] );
351       mComponentDirty[ index ] = true;
352       return mTxComponentAnimatable[ index ].mScale;
353     }
354     case TRANSFORM_PROPERTY_PARENT_ORIGIN:
355     {
356       unsigned int index( mIds[id] );
357       mComponentDirty[ index ] = true;
358       return mTxComponentStatic[ index ].mParentOrigin;
359     }
360     case TRANSFORM_PROPERTY_ANCHOR_POINT:
361     {
362       unsigned int index( mIds[id] );
363       mComponentDirty[ index ] = true;
364       return mTxComponentStatic[ index ].mAnchorPoint;
365     }
366     case TRANSFORM_PROPERTY_SIZE:
367     {
368       unsigned int index( mIds[id] );
369       mComponentDirty[ index ] = true;
370       return mSize[ index ];
371     }
372     default:
373     {
374       DALI_ASSERT_ALWAYS(false);
375       return mTxComponentAnimatable[ mIds[id] ].mPosition;
376     }
377   }
378 }
379
380 const Vector3& TransformManager::GetVector3PropertyValue( TransformId id, TransformManagerProperty property ) const
381 {
382   switch( property )
383   {
384     case TRANSFORM_PROPERTY_POSITION:
385     {
386       return mTxComponentAnimatable[ mIds[id] ].mPosition;
387     }
388     case TRANSFORM_PROPERTY_SCALE:
389     {
390       return mTxComponentAnimatable[ mIds[id] ].mScale;
391     }
392     case TRANSFORM_PROPERTY_PARENT_ORIGIN:
393     {
394       return mTxComponentStatic[ mIds[id] ].mParentOrigin;
395     }
396     case TRANSFORM_PROPERTY_ANCHOR_POINT:
397     {
398       return mTxComponentStatic[ mIds[id] ].mAnchorPoint;
399     }
400     case TRANSFORM_PROPERTY_SIZE:
401     {
402       return mSize[ mIds[id] ];
403     }
404     default:
405     {
406       DALI_ASSERT_ALWAYS(false);
407       return mTxComponentAnimatable[ mIds[id] ].mPosition;
408     }
409   }
410 }
411
412 const float& TransformManager::GetVector3PropertyComponentValue(TransformId id, TransformManagerProperty property, unsigned int component ) const
413 {
414   switch( property )
415   {
416     case TRANSFORM_PROPERTY_POSITION:
417     {
418       return mTxComponentAnimatable[ mIds[id] ].mPosition[component];
419     }
420     case TRANSFORM_PROPERTY_SCALE:
421     {
422       return mTxComponentAnimatable[ mIds[id] ].mScale[component];
423     }
424     case TRANSFORM_PROPERTY_PARENT_ORIGIN:
425     {
426       return mTxComponentStatic[ mIds[id] ].mParentOrigin[component];
427     }
428     case TRANSFORM_PROPERTY_ANCHOR_POINT:
429     {
430       return mTxComponentStatic[ mIds[id] ].mAnchorPoint[component];
431     }
432     case TRANSFORM_PROPERTY_SIZE:
433     {
434       return mSize[ mIds[id] ][component];
435     }
436     default:
437     {
438       DALI_ASSERT_ALWAYS(false);
439       return mTxComponentAnimatable[ mIds[id] ].mPosition[component];
440     }
441   }
442 }
443
444 void TransformManager::SetVector3PropertyValue( TransformId id, TransformManagerProperty property, const Vector3& value )
445 {
446   unsigned int index( mIds[id] );
447   mComponentDirty[ index ] = true;
448
449   switch( property )
450   {
451     case TRANSFORM_PROPERTY_POSITION:
452     {
453       mTxComponentAnimatable[ index ].mPosition = value;
454       break;
455     }
456     case TRANSFORM_PROPERTY_SCALE:
457     {
458       mTxComponentAnimatable[ index ].mScale = value;
459       break;
460     }
461     case TRANSFORM_PROPERTY_PARENT_ORIGIN:
462     {
463       mTxComponentStatic[ index ].mParentOrigin = value;
464       break;
465     }
466     case TRANSFORM_PROPERTY_ANCHOR_POINT:
467     {
468       mTxComponentStatic[ index ].mAnchorPoint = value;
469       break;
470     }
471     case TRANSFORM_PROPERTY_SIZE:
472     {
473       mSize[ index ] = value;
474       break;
475     }
476     default:
477     {
478       DALI_ASSERT_ALWAYS(false);
479     }
480   }
481 }
482
483 void TransformManager::SetVector3PropertyComponentValue( TransformId id, TransformManagerProperty property, float value, unsigned int component )
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[component] = value;
493       break;
494     }
495     case TRANSFORM_PROPERTY_SCALE:
496     {
497       mTxComponentAnimatable[ index ].mScale[component] = value;
498       break;
499     }
500     case TRANSFORM_PROPERTY_PARENT_ORIGIN:
501     {
502       mTxComponentStatic[ index ].mParentOrigin[component] = value;
503       break;
504     }
505     case TRANSFORM_PROPERTY_ANCHOR_POINT:
506     {
507       mTxComponentStatic[ index ].mAnchorPoint[component] = value;
508       break;
509     }
510     case TRANSFORM_PROPERTY_SIZE:
511     {
512       mSize[ index ][component] = value;
513       break;
514     }
515     default:
516     {
517       DALI_ASSERT_ALWAYS(false);
518     }
519   }
520 }
521
522 void TransformManager::BakeVector3PropertyValue( TransformId id, TransformManagerProperty property, const Vector3& value )
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 = mTxComponentAnimatableBaseValue[index].mPosition = value;
532       break;
533     }
534     case TRANSFORM_PROPERTY_SCALE:
535     {
536       mTxComponentAnimatable[ index ].mScale = mTxComponentAnimatableBaseValue[index].mScale = value;
537       break;
538     }
539     case TRANSFORM_PROPERTY_PARENT_ORIGIN:
540     {
541       mTxComponentStatic[ index ].mParentOrigin = value;
542       break;
543     }
544     case TRANSFORM_PROPERTY_ANCHOR_POINT:
545     {
546       mTxComponentStatic[ index ].mAnchorPoint = value;
547       break;
548     }
549     case TRANSFORM_PROPERTY_SIZE:
550     {
551       mSize[ index ] = mSizeBase[index] = value;
552       break;
553     }
554     default:
555     {
556       DALI_ASSERT_ALWAYS(false);
557     }
558   }
559 }
560
561 void TransformManager::BakeRelativeVector3PropertyValue( 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 = mTxComponentAnimatable[ index ].mPosition + value;
571       break;
572     }
573     case TRANSFORM_PROPERTY_SCALE:
574     {
575       mTxComponentAnimatable[ index ].mScale = mTxComponentAnimatableBaseValue[index].mScale = mTxComponentAnimatable[ index ].mScale + value;
576       break;
577     }
578     case TRANSFORM_PROPERTY_PARENT_ORIGIN:
579     {
580       mTxComponentStatic[ index ].mParentOrigin = mTxComponentStatic[ index ].mParentOrigin + value;
581       break;
582     }
583     case TRANSFORM_PROPERTY_ANCHOR_POINT:
584     {
585       mTxComponentStatic[ index ].mAnchorPoint = mTxComponentStatic[ index ].mAnchorPoint + value;
586       break;
587     }
588     case TRANSFORM_PROPERTY_SIZE:
589     {
590       mSize[ index ] = mSizeBase[index] = mSize[ index ] + value;
591       break;
592     }
593     default:
594     {
595       DALI_ASSERT_ALWAYS(false);
596     }
597   }
598 }
599
600 void TransformManager::BakeMultiplyVector3PropertyValue( 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::BakeVector3PropertyComponentValue( TransformId id, TransformManagerProperty property, float value, unsigned int component )
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[component] = mTxComponentAnimatableBaseValue[index].mPosition[component] = value;
649       break;
650     }
651     case TRANSFORM_PROPERTY_SCALE:
652     {
653       mTxComponentAnimatable[ index ].mScale[component] = mTxComponentAnimatableBaseValue[index].mScale[component] = value;
654       break;
655     }
656     case TRANSFORM_PROPERTY_PARENT_ORIGIN:
657     {
658       mTxComponentStatic[ index ].mParentOrigin[component] = value;
659       break;
660     }
661     case TRANSFORM_PROPERTY_ANCHOR_POINT:
662     {
663       mTxComponentStatic[ index ].mAnchorPoint[component] = value;
664       break;
665     }
666     case TRANSFORM_PROPERTY_SIZE:
667     {
668       mSize[ index ][component] = mSizeBase[index][component] = value;
669       break;
670     }
671     default:
672     {
673       DALI_ASSERT_ALWAYS(false);
674     }
675   }
676 }
677
678 void TransformManager::BakeXVector3PropertyValue( TransformId id, TransformManagerProperty property, float value )
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.x = mTxComponentAnimatableBaseValue[index].mPosition.x = value;
688       break;
689     }
690     case TRANSFORM_PROPERTY_SCALE:
691     {
692       mTxComponentAnimatable[ index ].mScale.x = mTxComponentAnimatableBaseValue[index].mScale.x = value;
693       break;
694     }
695     case TRANSFORM_PROPERTY_PARENT_ORIGIN:
696     {
697       mTxComponentStatic[ index ].mParentOrigin.x = value;
698       break;
699     }
700     case TRANSFORM_PROPERTY_ANCHOR_POINT:
701     {
702       mTxComponentStatic[ index ].mAnchorPoint.x = value;
703       break;
704     }
705     case TRANSFORM_PROPERTY_SIZE:
706     {
707       mSize[ index ].x = mSizeBase[index].x = value;
708       break;
709     }
710     default:
711     {
712       DALI_ASSERT_ALWAYS(false);
713     }
714   }
715 }
716
717 void TransformManager::BakeYVector3PropertyValue( 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.y = mTxComponentAnimatableBaseValue[index].mPosition.y = value;
727       break;
728     }
729     case TRANSFORM_PROPERTY_SCALE:
730     {
731       mTxComponentAnimatable[ index ].mScale.y = mTxComponentAnimatableBaseValue[index].mScale.y = value;
732       break;
733     }
734     case TRANSFORM_PROPERTY_PARENT_ORIGIN:
735     {
736       mTxComponentStatic[ index ].mParentOrigin.y = value;
737       break;
738     }
739     case TRANSFORM_PROPERTY_ANCHOR_POINT:
740     {
741       mTxComponentStatic[ index ].mAnchorPoint.y = value;
742       break;
743     }
744     case TRANSFORM_PROPERTY_SIZE:
745     {
746       mSize[ index ].y = mSizeBase[index].y = value;
747       break;
748     }
749     default:
750     {
751       DALI_ASSERT_ALWAYS(false);
752     }
753   }
754 }
755
756 void TransformManager::BakeZVector3PropertyValue( 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.z = mTxComponentAnimatableBaseValue[index].mPosition.z = value;
766       break;
767     }
768     case TRANSFORM_PROPERTY_SCALE:
769     {
770       mTxComponentAnimatable[ index ].mScale.z = mTxComponentAnimatableBaseValue[index].mScale.z = value;
771       break;
772     }
773     case TRANSFORM_PROPERTY_PARENT_ORIGIN:
774     {
775       mTxComponentStatic[ index ].mParentOrigin.z = value;
776       break;
777     }
778     case TRANSFORM_PROPERTY_ANCHOR_POINT:
779     {
780       mTxComponentStatic[ index ].mAnchorPoint.z = value;
781       break;
782     }
783     case TRANSFORM_PROPERTY_SIZE:
784     {
785       mSize[ index ].z = mSizeBase[index].z = value;
786       break;
787     }
788     default:
789     {
790       DALI_ASSERT_ALWAYS(false);
791     }
792   }
793 }
794
795 Quaternion& TransformManager::GetQuaternionPropertyValue( TransformId id )
796 {
797   unsigned int index( mIds[id] );
798   mComponentDirty[ index ] = true;
799   return mTxComponentAnimatable[ index ].mOrientation;
800 }
801
802 const Quaternion& TransformManager::GetQuaternionPropertyValue( TransformId id ) const
803 {
804   return mTxComponentAnimatable[ mIds[id] ].mOrientation;
805 }
806
807 void TransformManager::SetQuaternionPropertyValue( TransformId id, const Quaternion& q )
808 {
809   unsigned int index( mIds[id] );
810   mTxComponentAnimatable[ index ].mOrientation = q;
811   mComponentDirty[ index ] = true;
812 }
813
814 void TransformManager::BakeQuaternionPropertyValue( TransformId id, const Quaternion& q )
815 {
816   unsigned int index( mIds[id] );
817   mTxComponentAnimatable[ index ].mOrientation = mTxComponentAnimatableBaseValue[index].mOrientation = q;
818   mComponentDirty[ index ] = true;
819 }
820
821 void TransformManager::BakeRelativeQuaternionPropertyValue( TransformId id, const Quaternion& q )
822 {
823   unsigned int index( mIds[id] );
824   mTxComponentAnimatable[ index ].mOrientation = mTxComponentAnimatableBaseValue[index].mOrientation = mTxComponentAnimatable[ index ].mOrientation * q;
825   mComponentDirty[ index ] = true;
826 }
827
828 const Vector4& TransformManager::GetBoundingSphere( TransformId id ) const
829 {
830   return mBoundingSpheres[ mIds[id] ];
831 }
832
833 void TransformManager::GetWorldMatrixAndSize( TransformId id, Matrix& worldMatrix, Vector3& size ) const
834 {
835   unsigned int index = mIds[id];
836   worldMatrix = mWorld[index];
837   size = mSize[index];
838 }
839
840 } //namespace SceneGraph
841 } //namespace Internal
842 } //namespace Dali