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