Added object sizes to platform abstraction in profiling section
[platform/core/uifw/dali-core.git] / dali / internal / event / actors / camera-actor-impl.cpp
1 //
2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
3 //
4 // Licensed under the Flora License, Version 1.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://floralicense.org/license/
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 // CLASS HEADER
18 #include <dali/internal/event/actors/camera-actor-impl.h>
19
20 // EXTERNAL INCLUDES
21 #include <cmath>
22
23 // INTERNAL INCLUDES
24 #include <dali/public-api/common/stage.h>
25 #include <dali/public-api/object/type-registry.h>
26 #include <dali/internal/event/actor-attachments/camera-attachment-impl.h>
27 #include <dali/internal/event/common/property-index-ranges.h>
28 #include <dali/internal/event/common/stage-impl.h>
29 #include <dali/internal/event/render-tasks/render-task-impl.h>
30 #include <dali/internal/event/render-tasks/render-task-list-impl.h>
31 #include <dali/internal/event/common/projection.h>
32 #include <dali/integration-api/debug.h>
33
34 namespace Dali
35 {
36
37 const Property::Index CameraActor::TYPE                    = Internal::DEFAULT_ACTOR_PROPERTY_MAX_COUNT;
38 const Property::Index CameraActor::PROJECTION_MODE         = Internal::DEFAULT_ACTOR_PROPERTY_MAX_COUNT + 1;
39 const Property::Index CameraActor::FIELD_OF_VIEW           = Internal::DEFAULT_ACTOR_PROPERTY_MAX_COUNT + 2;
40 const Property::Index CameraActor::ASPECT_RATIO            = Internal::DEFAULT_ACTOR_PROPERTY_MAX_COUNT + 3;
41 const Property::Index CameraActor::NEAR_PLANE_DISTANCE     = Internal::DEFAULT_ACTOR_PROPERTY_MAX_COUNT + 4;
42 const Property::Index CameraActor::FAR_PLANE_DISTANCE      = Internal::DEFAULT_ACTOR_PROPERTY_MAX_COUNT + 5;
43 const Property::Index CameraActor::LEFT_PLANE_DISTANCE     = Internal::DEFAULT_ACTOR_PROPERTY_MAX_COUNT + 6;
44 const Property::Index CameraActor::RIGHT_PLANE_DISTANCE    = Internal::DEFAULT_ACTOR_PROPERTY_MAX_COUNT + 7;
45 const Property::Index CameraActor::TOP_PLANE_DISTANCE      = Internal::DEFAULT_ACTOR_PROPERTY_MAX_COUNT + 8;
46 const Property::Index CameraActor::BOTTOM_PLANE_DISTANCE   = Internal::DEFAULT_ACTOR_PROPERTY_MAX_COUNT + 9;
47 const Property::Index CameraActor::TARGET_POSITION         = Internal::DEFAULT_ACTOR_PROPERTY_MAX_COUNT + 10;
48 const Property::Index CameraActor::PROJECTION_MATRIX       = Internal::DEFAULT_ACTOR_PROPERTY_MAX_COUNT + 11;
49 const Property::Index CameraActor::VIEW_MATRIX             = Internal::DEFAULT_ACTOR_PROPERTY_MAX_COUNT + 12;
50 const Property::Index CameraActor::INVERT_Y_AXIS           = Internal::DEFAULT_ACTOR_PROPERTY_MAX_COUNT + 13;
51
52 namespace Internal
53 {
54 bool CameraActor::mFirstInstance = true;
55 Actor::DefaultPropertyLookup* CameraActor::mDefaultCameraActorPropertyLookup = NULL;
56
57 namespace
58 {
59
60 // calculate the far plane distance for a 16bit depth buffer with 4 bits per unit precision
61 void CalculateClippingAndZ( float width, float height, float& nearClippingPlane, float& farClippingPlane, float& cameraZ )
62 {
63   nearClippingPlane = std::max( width, height );
64   farClippingPlane = nearClippingPlane + static_cast<float>( 0xFFFF >> 4 );
65   cameraZ = 2.0f * nearClippingPlane;
66 }
67
68 BaseHandle Create()
69 {
70   return Dali::CameraActor::New();
71 }
72
73 TypeRegistration mType( typeid(Dali::CameraActor), typeid(Dali::Actor), Create );
74
75 const std::string DEFAULT_CAMERA_ACTOR_PROPERTY_NAMES[] =
76 {
77   "type",
78   "projection-mode",
79   "field-of-view",
80   "aspect-ratio",
81   "near-plane-distance",
82   "far-plane-distance",
83   "left-plane-distance",
84   "right-plane-distance",
85   "top-plane-distance",
86   "bottom-plane-distance",
87   "target-position",
88   "projection-matrix",
89   "view-matrix",
90   "invert-y-axis"
91 };
92 const int DEFAULT_CAMERA_ACTOR_PROPERTY_COUNT = sizeof( DEFAULT_CAMERA_ACTOR_PROPERTY_NAMES ) / sizeof( std::string );
93
94 const Property::Type DEFAULT_CAMERA_ACTOR_PROPERTY_TYPES[DEFAULT_CAMERA_ACTOR_PROPERTY_COUNT] =
95 {
96   Property::STRING,   // "type",
97   Property::STRING,   // "projection-mode",
98   Property::FLOAT,    // "field-of-view",
99   Property::FLOAT,    // "aspect-ratio",
100   Property::FLOAT,    // "near-plane-distance",
101   Property::FLOAT,    // "far-plane-distance",
102   Property::FLOAT,    // "left-plane-distance",
103   Property::FLOAT,    // "right-plane-distance",
104   Property::FLOAT,    // "top-plane-distance",
105   Property::FLOAT,    // "bottom-plane-distance",
106   Property::VECTOR3,  // "target-position",
107   Property::MATRIX,   // "projection-matrix",
108   Property::MATRIX,   // "view-matrix",
109   Property::BOOLEAN,  // "invert-y-axis",
110 };
111
112 /**
113  * Builds the picking ray in the world reference system from an orthographic camera
114  * The ray origin is the screen coordinate in the near plane translated to a parallel
115  * plane at the camera origin. The ray direction is the direction the camera is facing
116  * (i.e. Z=-1 in view space).
117  */
118 void BuildOrthoPickingRay( const Matrix& viewMatrix,
119                            const Matrix& projectionMatrix,
120                            const Viewport& viewport,
121                            float screenX,
122                            float screenY,
123                            Vector4& rayOrigin,
124                            Vector4& rayDir,
125                            float nearPlaneDistance )
126 {
127   //          inv( modelMatrix )          inv( viewMatrix )    inv( projectionMatrix )           normalize
128   //          <-----------------         <-----------------         <--------------           <-------------
129   //  Local                      World                      Camera                 Normalized                 Screen
130   // reference                  reference                  reference                  clip                  coordinates
131   //  system                     system                     system                 coordinates
132   //          ----------------->         ----------------->         -------------->           ------------->
133   //             modelMatrix                 viewMatrix             projectionMatrix             viewport
134
135   // Transforms the touch point from the screen reference system to the world reference system.
136   Matrix invViewProjection( false ); // Don't initialize.
137   Matrix::Multiply( invViewProjection, viewMatrix, projectionMatrix );
138   if( !invViewProjection.Invert() )
139   {
140     DALI_ASSERT_DEBUG( false );
141   }
142
143   Vector4 near( screenX - viewport.x, viewport.height - (screenY - viewport.y), 0.f, 1.f );
144   if( !Unproject( near, invViewProjection, viewport.width, viewport.height, rayOrigin ) )
145   {
146     DALI_ASSERT_DEBUG( false );
147   }
148
149   Matrix invView = viewMatrix;
150   if( !invView.Invert() )
151   {
152     DALI_ASSERT_DEBUG( false );
153   }
154
155   Vector4 cameraOrigin = invView * Vector4( 0.f, 0.f, 0.f, 1.f );
156   Vector4 nearPlaneOrigin = invView * Vector4( 0.0f, 0.0f, -nearPlaneDistance, 1.0f);
157
158   // Vector pointing from the camera to the near plane
159   rayDir = cameraOrigin - nearPlaneOrigin;
160   rayOrigin -= rayDir;
161   rayDir.Normalize();
162   rayDir.w = 1.0f;
163 }
164
165 } // namespace
166
167 CameraActorPtr CameraActor::New( const Size& size )
168 {
169   CameraActorPtr actor(new CameraActor());
170
171   // Second-phase construction
172
173   actor->Initialize();
174
175   actor->SetName("DefaultCamera");
176
177   // Create the attachment
178   actor->mCameraAttachment = CameraAttachment::New( *actor->mNode );
179
180   actor->Attach(*actor->mCameraAttachment);
181
182   actor->SetPerspectiveProjection( size );
183
184   return actor;
185 }
186
187 void CameraActor::OnInitialize()
188 {
189   if(CameraActor::mFirstInstance)
190   {
191     mDefaultCameraActorPropertyLookup = new DefaultPropertyLookup();
192     const int start = DEFAULT_ACTOR_PROPERTY_MAX_COUNT;
193     for ( int i = 0; i < DEFAULT_CAMERA_ACTOR_PROPERTY_COUNT; ++i )
194     {
195       (*mDefaultCameraActorPropertyLookup)[DEFAULT_CAMERA_ACTOR_PROPERTY_NAMES[i]] = i + start;
196     }
197     CameraActor::mFirstInstance = false;
198   }
199 }
200
201 CameraActor::CameraActor()
202 : Actor( Actor::BASIC )
203 {
204 }
205
206 CameraActor::~CameraActor()
207 {
208 }
209
210 void CameraActor::SetType( Dali::Camera::Type type )
211 {
212   mCameraAttachment->SetType(type);
213 }
214
215 Dali::Camera::Type CameraActor::GetType() const
216 {
217   return mCameraAttachment->GetType();
218 }
219
220 void CameraActor::SetProjectionMode( Dali::Camera::ProjectionMode mode )
221 {
222   mCameraAttachment->SetProjectionMode(mode);
223 }
224
225 Dali::Camera::ProjectionMode CameraActor::GetProjectionMode() const
226 {
227   return mCameraAttachment->GetProjectionMode();
228 }
229
230 void CameraActor::SetFieldOfView( float fieldOfView )
231 {
232   mCameraAttachment->SetFieldOfView(fieldOfView);
233 }
234
235 float CameraActor::GetFieldOfView( ) const
236 {
237   return mCameraAttachment->GetFieldOfView();
238 }
239
240 void CameraActor::SetAspectRatio( float aspectRatio )
241 {
242   mCameraAttachment->SetAspectRatio(aspectRatio);
243 }
244
245 float CameraActor::GetAspectRatio( ) const
246 {
247   return mCameraAttachment->GetAspectRatio();
248 }
249
250 void CameraActor::SetNearClippingPlane( float nearClippingPlane )
251 {
252   mCameraAttachment->SetNearClippingPlane(nearClippingPlane);
253 }
254
255 float CameraActor::GetNearClippingPlane( ) const
256 {
257   return mCameraAttachment->GetNearClippingPlane();
258 }
259
260 void CameraActor::SetFarClippingPlane( float farClippingPlane )
261 {
262   mCameraAttachment->SetFarClippingPlane(farClippingPlane);
263 }
264
265 float CameraActor::GetFarClippingPlane( ) const
266 {
267   return mCameraAttachment->GetFarClippingPlane();
268 }
269
270 void CameraActor::SetTargetPosition(const Vector3& target)
271 {
272   mCameraAttachment->SetTargetPosition(target);
273 }
274
275 Vector3 CameraActor::GetTargetPosition() const
276 {
277   return mCameraAttachment->GetTargetPosition();
278 }
279
280 void CameraActor::SetInvertYAxis(bool invertYAxis)
281 {
282   mCameraAttachment->SetInvertYAxis(invertYAxis);
283 }
284
285 bool CameraActor::GetInvertYAxis() const
286 {
287   return mCameraAttachment->GetInvertYAxis();
288 }
289
290 void CameraActor::SetPerspectiveProjection( const Size& size, float stereoBias /* = 0.0f */ )
291 {
292   float width = size.width;
293   float height = size.height;
294
295   if( Size::ZERO == size )
296   {
297     if( Stage::IsInstalled() )
298     {
299       const Size& stageSize = mStage->GetSize();
300
301       width = stageSize.width;
302       height = stageSize.height;
303     }
304   }
305
306   if( ( width < Math::MACHINE_EPSILON_1000 ) || ( height < Math::MACHINE_EPSILON_1000 ) )
307   {
308     // On the stage initialization this method is called but the size has not been set.
309     // There is no point to set any value if width or height is zero.
310     return;
311   }
312
313   float nearClippingPlane;
314   float farClippingPlane;
315   float cameraZ;
316   CalculateClippingAndZ( width, height, nearClippingPlane, farClippingPlane, cameraZ );
317
318   // calculate the position of the camera to have the desired aspect ratio
319   const float fieldOfView = 2.0f * std::atan( height * 0.5f / cameraZ );
320
321   // unless it is too small, we want at least as much space to the back as we have torwards the front
322   const float minClippingFarPlane = 2.f * nearClippingPlane;
323   if ( farClippingPlane < minClippingFarPlane )
324   {
325     farClippingPlane = minClippingFarPlane;
326   }
327
328   const float aspectRatio = width / height;
329
330   SetProjectionMode(Dali::Camera::PERSPECTIVE_PROJECTION);
331   SetFieldOfView( fieldOfView );
332   SetNearClippingPlane( nearClippingPlane );
333   SetFarClippingPlane( farClippingPlane );
334   SetAspectRatio( aspectRatio );
335   mCameraAttachment->SetStereoBias( stereoBias );
336   SetZ( cameraZ );
337 }
338
339
340 void CameraActor::SetOrthographicProjection( const Vector2& size )
341 {
342   // Choose near, far and Z parameters to match the SetPerspectiveProjection above.
343   float nearClippingPlane;
344   float farClippingPlane;
345   float cameraZ;
346   CalculateClippingAndZ( size.width, size.height, nearClippingPlane, farClippingPlane, cameraZ );
347   SetOrthographicProjection( -size.x*0.5f, size.x*0.5f, size.y*0.5f, -size.y*0.5f,
348                              nearClippingPlane, farClippingPlane );
349   SetZ( cameraZ );
350 }
351
352 void CameraActor::SetOrthographicProjection( float left, float right, float top, float bottom, float near, float far )
353 {
354   mCameraAttachment->SetLeftClippingPlane(left);
355   mCameraAttachment->SetRightClippingPlane(right);
356   mCameraAttachment->SetTopClippingPlane(top);
357   mCameraAttachment->SetBottomClippingPlane(bottom);
358   SetNearClippingPlane( near );
359   SetFarClippingPlane( far );
360   SetProjectionMode(Dali::Camera::ORTHOGRAPHIC_PROJECTION);
361 }
362
363 bool CameraActor::BuildPickingRay( const Vector2& screenCoordinates,
364                                    const Viewport& viewport,
365                                    Vector4& rayOrigin,
366                                    Vector4& rayDirection )
367 {
368   bool success = true;
369   if( GetProjectionMode() == Dali::Camera::PERSPECTIVE_PROJECTION )
370   {
371     // Build a picking ray in the world reference system.
372     // ray starts from the camera world position
373     rayOrigin = mNode->GetWorldPosition( mStage->GetEventBufferIndex() );
374     rayOrigin.w = 1.0f;
375
376     // Transform the touch point from the screen coordinate system to the world coordinates system.
377     Vector4 near( screenCoordinates.x - viewport.x, viewport.height - (screenCoordinates.y - viewport.y), 0.f, 1.f );
378     if( !Unproject( near, mCameraAttachment->GetInverseViewProjectionMatrix(), viewport.width, viewport.height, near ) )
379     {
380       // unproject failed so no picking ray possible
381       success = false;
382     }
383
384     // Compute the ray's director vector.
385     rayDirection.x = near.x - rayOrigin.x;
386     rayDirection.y = near.y - rayOrigin.y;
387     rayDirection.z = near.z - rayOrigin.z;
388     rayDirection.Normalize();
389     rayDirection.w = 1.f;
390   }
391   else
392   {
393     float nearPlaneDistance = GetNearClippingPlane();
394     BuildOrthoPickingRay( GetViewMatrix(),
395                           GetProjectionMatrix(),
396                           viewport, screenCoordinates.x,
397                           screenCoordinates.y,
398                           rayOrigin,
399                           rayDirection,
400                           nearPlaneDistance );
401   }
402
403   return success;
404 }
405
406 const Matrix& CameraActor::GetViewMatrix() const
407 {
408   if ( OnStage() )
409   {
410     return mCameraAttachment->GetViewMatrix();
411   }
412   else
413   {
414     return Matrix::IDENTITY;
415   }
416 }
417
418 const Matrix& CameraActor::GetProjectionMatrix() const
419 {
420   if ( OnStage() )
421   {
422     return mCameraAttachment->GetProjectionMatrix();
423   }
424   else
425   {
426     return Matrix::IDENTITY;
427   }
428 }
429
430 unsigned int CameraActor::GetDefaultPropertyCount() const
431 {
432   return Actor::GetDefaultPropertyCount() + DEFAULT_CAMERA_ACTOR_PROPERTY_COUNT;
433 }
434
435 void CameraActor::GetDefaultPropertyIndices( Property::IndexContainer& indices ) const
436 {
437   Actor::GetDefaultPropertyIndices( indices ); // Actor class properties
438
439   indices.reserve( indices.size() + DEFAULT_CAMERA_ACTOR_PROPERTY_COUNT );
440
441   int index = DEFAULT_ACTOR_PROPERTY_MAX_COUNT;
442   for ( int i = 0; i < DEFAULT_CAMERA_ACTOR_PROPERTY_COUNT; ++i, ++index )
443   {
444     indices.push_back( index );
445   }
446 }
447
448 bool CameraActor::IsDefaultPropertyWritable( Property::Index index ) const
449 {
450   if(index < DEFAULT_ACTOR_PROPERTY_MAX_COUNT)
451   {
452     return Actor::IsDefaultPropertyWritable(index);
453   }
454   else
455   {
456     if( Dali::CameraActor::PROJECTION_MATRIX == index || Dali::CameraActor::VIEW_MATRIX == index )
457     {
458       return false;
459     }
460     else
461     {
462       return true;
463     }
464   }
465 }
466
467 bool CameraActor::IsDefaultPropertyAnimatable( Property::Index index ) const
468 {
469   bool animatable = false; // Our properties are not animatable.
470
471   if(index < DEFAULT_ACTOR_PROPERTY_MAX_COUNT )
472   {
473     animatable = Actor::IsDefaultPropertyAnimatable(index);
474   }
475   return animatable;
476 }
477
478 bool CameraActor::IsDefaultPropertyAConstraintInput( Property::Index index ) const
479 {
480   bool animatable = true; // Our properties can be used as inputs to constraints.
481
482   if( index < DEFAULT_ACTOR_PROPERTY_MAX_COUNT )
483   {
484     animatable = Actor::IsDefaultPropertyAConstraintInput(index);
485   }
486   return animatable;
487 }
488
489 Property::Type CameraActor::GetDefaultPropertyType( Property::Index index ) const
490 {
491   if(index < DEFAULT_ACTOR_PROPERTY_MAX_COUNT)
492   {
493     return Actor::GetDefaultPropertyType(index);
494   }
495   else
496   {
497     index -= DEFAULT_ACTOR_PROPERTY_MAX_COUNT;
498
499     if ( ( index >= 0 ) && ( index < DEFAULT_CAMERA_ACTOR_PROPERTY_COUNT ) )
500     {
501       return DEFAULT_CAMERA_ACTOR_PROPERTY_TYPES[index];
502     }
503     else
504     {
505       // index out-of-bounds
506       return Property::NONE;
507     }
508   }
509 }
510
511 const std::string& CameraActor::GetDefaultPropertyName( Property::Index index ) const
512 {
513   if(index < DEFAULT_ACTOR_PROPERTY_MAX_COUNT)
514   {
515     return Actor::GetDefaultPropertyName(index);
516   }
517   else
518   {
519     index -= DEFAULT_ACTOR_PROPERTY_MAX_COUNT;
520
521     if ( ( index >= 0 ) && ( index < DEFAULT_CAMERA_ACTOR_PROPERTY_COUNT ) )
522     {
523       return DEFAULT_CAMERA_ACTOR_PROPERTY_NAMES[index];
524     }
525     else
526     {
527       // index out-of-bounds
528       static const std::string INVALID_PROPERTY_NAME;
529       return INVALID_PROPERTY_NAME;
530     }
531   }
532 }
533
534 Property::Index CameraActor::GetDefaultPropertyIndex(const std::string& name) const
535 {
536   Property::Index index = Property::INVALID_INDEX;
537
538   DALI_ASSERT_DEBUG( NULL != mDefaultCameraActorPropertyLookup );
539
540   // Look for name in current class' default properties
541   DefaultPropertyLookup::const_iterator result = mDefaultCameraActorPropertyLookup->find( name );
542   if ( mDefaultCameraActorPropertyLookup->end() != result )
543   {
544     index = result->second;
545   }
546   else
547   {
548     // If not found, check in base class
549     index = Actor::GetDefaultPropertyIndex( name );
550   }
551
552   return index;
553 }
554
555 void CameraActor::SetDefaultProperty( Property::Index index, const Property::Value& propertyValue )
556 {
557   if(index < DEFAULT_ACTOR_PROPERTY_MAX_COUNT)
558   {
559     Actor::SetDefaultProperty(index, propertyValue);
560   }
561   else
562   {
563     DALI_ASSERT_DEBUG(mCameraAttachment && "where is the camera?");
564     switch(index)
565     {
566       case Dali::CameraActor::TYPE:
567       {
568         std::string s(propertyValue.Get<std::string>());
569         if(s == "LOOK_AT_TARGET")
570         {
571           mCameraAttachment->SetType(Dali::Camera::LOOK_AT_TARGET);
572         }
573         else if(s == "FREE_LOOK")
574         {
575           mCameraAttachment->SetType(Dali::Camera::FREE_LOOK);
576         }
577         else
578         {
579           DALI_LOG_WARNING("Unknown camera type\n");
580         }
581         break;
582       }
583       case Dali::CameraActor::PROJECTION_MODE:
584       {
585         std::string s(propertyValue.Get<std::string>());
586         if(s == "PERSPECTIVE_PROJECTION")
587         {
588           mCameraAttachment->SetProjectionMode(Dali::Camera::PERSPECTIVE_PROJECTION);
589         }
590         else if(s == "ORTHOGRAPHIC_PROJECTION")
591         {
592           mCameraAttachment->SetProjectionMode(Dali::Camera::ORTHOGRAPHIC_PROJECTION);
593         }
594         else
595         {
596           DALI_LOG_WARNING("Unknown projection mode\n");
597         }
598         break;
599       }
600       case Dali::CameraActor::FIELD_OF_VIEW:
601       {
602         mCameraAttachment->SetFieldOfView(propertyValue.Get<float>());
603         break;
604       }
605       case Dali::CameraActor::ASPECT_RATIO:
606       {
607         mCameraAttachment->SetAspectRatio(propertyValue.Get<float>());
608         break;
609       }
610       case Dali::CameraActor::LEFT_PLANE_DISTANCE:
611       {
612         mCameraAttachment->SetLeftClippingPlane(propertyValue.Get<float>());
613         break;
614       }
615       case Dali::CameraActor::RIGHT_PLANE_DISTANCE:
616       {
617         mCameraAttachment->SetRightClippingPlane(propertyValue.Get<float>());
618         break;
619       }
620       case Dali::CameraActor::TOP_PLANE_DISTANCE:
621       {
622         mCameraAttachment->SetTopClippingPlane(propertyValue.Get<float>());
623         break;
624       }
625       case Dali::CameraActor::BOTTOM_PLANE_DISTANCE:
626       {
627         mCameraAttachment->SetBottomClippingPlane(propertyValue.Get<float>());
628         break;
629       }
630       case Dali::CameraActor::NEAR_PLANE_DISTANCE:
631       {
632         mCameraAttachment->SetNearClippingPlane(propertyValue.Get<float>());
633         break;
634       }
635       case Dali::CameraActor::FAR_PLANE_DISTANCE:
636       {
637         mCameraAttachment->SetFarClippingPlane(propertyValue.Get<float>());
638         break;
639       }
640       case Dali::CameraActor::TARGET_POSITION:
641       {
642         mCameraAttachment->SetTargetPosition(propertyValue.Get<Vector3>());
643         break;
644       }
645       case Dali::CameraActor::PROJECTION_MATRIX:
646       {
647         DALI_LOG_WARNING("projection-matrix property is not animatable \n");
648         break;
649       }
650       case Dali::CameraActor::VIEW_MATRIX:
651       {
652         DALI_LOG_WARNING("view-matrix property is not animatable \n");
653         break;
654       }
655       case Dali::CameraActor::INVERT_Y_AXIS:
656       {
657         mCameraAttachment->SetInvertYAxis(propertyValue.Get<bool>());
658         break;
659       }
660       default:
661       {
662         DALI_LOG_WARNING("Unknown property (%d)\n", index);
663         break;
664       }
665     } // switch(index)
666
667   } // else
668 }
669
670 Property::Value CameraActor::GetDefaultProperty( Property::Index index ) const
671 {
672   Property::Value ret;
673   if(index < DEFAULT_ACTOR_PROPERTY_MAX_COUNT)
674   {
675     ret = Actor::GetDefaultProperty(index);
676   }
677   else
678   {
679     DALI_ASSERT_DEBUG(mCameraAttachment && "where is the camera?");
680     switch(index)
681     {
682
683       case Dali::CameraActor::TYPE:
684       {
685         if(mCameraAttachment->GetType() == Dali::Camera::LOOK_AT_TARGET)
686         {
687           ret = "LOOK_AT_TARGET";
688         }
689         else if(mCameraAttachment->GetType() == Dali::Camera::FREE_LOOK)
690         {
691           ret = "FREE_LOOK";
692         }
693         else
694         {
695           ret = "";
696           DALI_ASSERT_DEBUG("Unknown camera type\n");
697         }
698         break;
699       }
700
701
702       case Dali::CameraActor::PROJECTION_MODE:
703       {
704         if(mCameraAttachment->GetProjectionMode() == Dali::Camera::PERSPECTIVE_PROJECTION)
705         {
706           ret = "PERSPECTIVE_PROJECTION";
707         }
708         else if(mCameraAttachment->GetProjectionMode() == Dali::Camera::ORTHOGRAPHIC_PROJECTION)
709         {
710           ret = "ORTHOGRAPHIC_PROJECTION";
711         }
712         else
713         {
714           ret = "";
715           DALI_ASSERT_DEBUG("Unknown projection mode\n");
716         }
717         break;
718       }
719       case Dali::CameraActor::FIELD_OF_VIEW:
720       {
721         ret = mCameraAttachment->GetFieldOfView();
722         break;
723       }
724       case Dali::CameraActor::ASPECT_RATIO:
725       {
726         ret = mCameraAttachment->GetAspectRatio();
727         break;
728       }
729       case Dali::CameraActor::LEFT_PLANE_DISTANCE:
730       {
731         ret = mCameraAttachment->GetLeftClippingPlane();
732         break;
733       }
734       case Dali::CameraActor::RIGHT_PLANE_DISTANCE:
735       {
736         ret = mCameraAttachment->GetRightClippingPlane();
737         break;
738       }
739       case Dali::CameraActor::TOP_PLANE_DISTANCE:
740       {
741         ret = mCameraAttachment->GetTopClippingPlane();
742         break;
743       }
744       case Dali::CameraActor::BOTTOM_PLANE_DISTANCE:
745       {
746         ret = mCameraAttachment->GetBottomClippingPlane();
747         break;
748       }
749       case Dali::CameraActor::NEAR_PLANE_DISTANCE:
750       {
751         ret = mCameraAttachment->GetNearClippingPlane();
752         break;
753       }
754       case Dali::CameraActor::FAR_PLANE_DISTANCE:
755       {
756         ret = mCameraAttachment->GetFarClippingPlane();
757         break;
758       }
759       case Dali::CameraActor::TARGET_POSITION:
760       {
761         ret = mCameraAttachment->GetTargetPosition();
762         break;
763       }
764       case Dali::CameraActor::PROJECTION_MATRIX:
765       {
766         ret = mCameraAttachment->GetProjectionMatrix();
767         break;
768       }
769       case Dali::CameraActor::VIEW_MATRIX:
770       {
771         ret = mCameraAttachment->GetViewMatrix();
772         break;
773       }
774       case Dali::CameraActor::INVERT_Y_AXIS:
775       {
776         ret = mCameraAttachment->GetInvertYAxis();
777         break;
778       }
779       default:
780       {
781         DALI_LOG_WARNING("Unknown property (%d)\n", index);
782         break;
783       }
784     } // switch(index)
785   }
786
787   return ret;
788 }
789
790 const SceneGraph::PropertyBase* CameraActor::GetSceneObjectAnimatableProperty( Property::Index index ) const
791 {
792   DALI_ASSERT_ALWAYS( IsPropertyAnimatable(index) && "Property is not animatable" );
793
794   const SceneGraph::PropertyBase* property( NULL );
795
796   // This method should only return a property of an object connected to the scene-graph
797   if ( !OnStage() )
798   {
799     return property;
800   }
801
802   // let actor handle animatable properties, we have no animatable properties
803   if( index < DEFAULT_ACTOR_PROPERTY_MAX_COUNT )
804   {
805     property = Actor::GetSceneObjectAnimatableProperty(index);
806   }
807
808   return property;
809 }
810
811 const PropertyInputImpl* CameraActor::GetSceneObjectInputProperty( Property::Index index ) const
812 {
813   const PropertyInputImpl* property( NULL );
814
815   // This method should only return a property of an object connected to the scene-graph
816   if ( !OnStage() )
817   {
818     return property;
819   }
820
821   // if its an actor default property or a custom property (actor already handles custom properties)
822   if( ( index < DEFAULT_ACTOR_PROPERTY_MAX_COUNT ) || ( index >= DEFAULT_PROPERTY_MAX_COUNT ) )
823   {
824     property = Actor::GetSceneObjectInputProperty(index);
825   }
826   else
827   {
828     switch( index )
829     {
830       case Dali::CameraActor::PROJECTION_MATRIX:
831       {
832         property = mCameraAttachment->GetProjectionMatrixProperty();
833         break;
834       }
835       case Dali::CameraActor::VIEW_MATRIX:
836       {
837         property = mCameraAttachment->GetViewMatrixProperty();
838         break;
839       }
840       default:
841         DALI_LOG_WARNING("Not an input property (%d)\n", index);
842         break;
843     }
844   }
845
846   return property;
847 }
848
849
850 } // namespace Internal
851
852 } // namespace Dali