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