Dali 3D User Interface Engine
utc-Dali-CameraActor.cpp
Go to the documentation of this file.
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 #include <iostream>
19 
20 #include <stdlib.h>
21 #include <cmath>
23 
24 #include "dali-test-suite-utils/dali-test-suite-utils.h"
25 
26 using namespace Dali;
27 
29 {
31 }
32 
34 {
36 }
37 
38 namespace
39 {
40 
41 const float FLOAT_EPSILON = 0.001f;
42 const float TEST_ASPECT_RATIO = 0.123f;
43 const float TEST_FIELD_OF_VIEW = Radian(Degree(40.0f));
44 const float TEST_NEAR_PLANE_DISTANCE = 0.23f;
45 const float TEST_FAR_PLANE_DISTANCE = 0.973f;
46 
47 const std::string SHADER_LIGHT_CAMERA_PROJECTION_MATRIX_PROPERTY_NAME( "uLightCameraProjectionMatrix" );
48 const std::string SHADER_LIGHT_CAMERA_VIEW_MATRIX_PROPERTY_NAME( "uLightCameraViewMatrix" );
49 const char* const RENDER_SHADOW_VERTEX_SOURCE =
50  " uniform mediump mat4 uLightCameraProjectionMatrix;\n"
51  " uniform mediump mat4 uLightCameraViewMatrix;\n"
52  "\n"
53  "void main()\n"
54  "{\n"
55  " gl_Position = uProjection * uModelView * vec4(aPosition,1.0);\n"
56  " vec4 textureCoords = uLightCameraProjectionMatrix * uLightCameraViewMatrix * uModelMatrix * vec4(aPosition,1.0);\n"
57  " vTexCoord = 0.5 + 0.5 * (textureCoords.xy/textureCoords.w);\n"
58  "}\n";
59 
60 const char* const RENDER_SHADOW_FRAGMENT_SOURCE =
61  "uniform lowp vec4 uShadowColor;\n"
62  "void main()\n"
63  "{\n"
64  " lowp float alpha;\n"
65  " alpha = texture2D(sTexture, vec2(vTexCoord.x, vTexCoord.y)).a;\n"
66  " gl_FragColor = vec4(uShadowColor.rgb, uShadowColor.a * alpha);\n"
67  "}\n";
68 
69 } // Anonymous namespace
70 
71 
73 {
74  TestApplication application;
75  tet_infoline( "Testing Dali::CameraActor::CameraActor()" );
76 
77  CameraActor actor;
78 
79  DALI_TEST_CHECK( !actor );
80  END_TEST;
81 }
82 
83 // Note: No negative test for UtcDaliCameraActorConstructor.
84 
86 {
87  TestApplication application;
88  tet_infoline( "Testing Dali::~CameraActor (P)" );
89  CameraActor* actor = new CameraActor();
90  delete actor;
91  actor = NULL;
92 
93  DALI_TEST_CHECK( true );
94  END_TEST;
95 }
96 
97 // Note: No negative test for UtcDaliCameraActorDestructor.
98 
100 {
101  TestApplication application;
102  tet_infoline( "Testing Dali::CameraActor Copy Constructor (P)" );
103  CameraActor actor = CameraActor::New();
104 
105  CameraActor copyActor( actor );
106 
107  DALI_TEST_CHECK( copyActor );
108  DALI_TEST_CHECK( copyActor == actor );
109 
110  END_TEST;
111 }
112 
114 {
115  TestApplication application;
116  tet_infoline( "Testing Dali::CameraActor Copy Constructor (N)" );
117  CameraActor actor;
118 
119  CameraActor copyActor( actor );
120 
121  DALI_TEST_CHECK( !copyActor );
122 
123  END_TEST;
124 }
125 
127 {
128  TestApplication application;
129  tet_infoline( "Testing Dali::CameraActor Assignment Operator (P)" );
130  const CameraActor actor = CameraActor::New();
131 
132  CameraActor copyActor = actor;
133 
134  DALI_TEST_CHECK( copyActor );
135  DALI_TEST_CHECK( copyActor == actor );
136 
137  END_TEST;
138 }
139 
141 {
142  TestApplication application;
143  tet_infoline( "Testing Dali::CameraActor = (N)" );
144  CameraActor actor;
145 
146  CameraActor copyActor = actor;
147 
148  DALI_TEST_CHECK( !copyActor );
149 
150  END_TEST;
151 }
152 
154 {
155  TestApplication application;
156  tet_infoline( "Testing Dali::CameraActor::New (P)" );
157 
158  CameraActor actor = CameraActor::New();
159 
160  DALI_TEST_CHECK( actor );
161 
162  actor.Reset();
163 
164  DALI_TEST_CHECK( !actor );
165  END_TEST;
166 }
167 
168 // Note: No negative test for UtcDaliCameraActorNew.
169 
171 {
172  TestApplication application;
173  tet_infoline( "Testing Dali::CameraActor::DownCast (P)" );
174 
175  CameraActor camera = CameraActor::New();
176  Actor anActor = Actor::New();
177  anActor.Add( camera );
178 
179  Actor child = anActor.GetChildAt( 0 );
180  CameraActor cameraActor = CameraActor::DownCast( child );
181  DALI_TEST_CHECK( cameraActor );
182 
183  cameraActor.Reset();
184  DALI_TEST_CHECK( !cameraActor );
185 
186  cameraActor = DownCast< CameraActor >( child );
187  DALI_TEST_CHECK( cameraActor );
188  END_TEST;
189 }
190 
192 {
193  TestApplication application;
194  tet_infoline( "Testing Dali::CameraActor::DownCast (N)" );
195 
196  Actor actor1 = Actor::New();
197  Actor anActor = Actor::New();
198  anActor.Add( actor1 );
199 
200  Actor child = anActor.GetChildAt( 0 );
201  CameraActor cameraActor = CameraActor::DownCast( child );
202  DALI_TEST_CHECK( !cameraActor );
203 
204  Actor unInitialzedActor;
205  cameraActor = CameraActor::DownCast( unInitialzedActor );
206  DALI_TEST_CHECK( !cameraActor );
207 
208  cameraActor = DownCast< CameraActor >( unInitialzedActor );
209  DALI_TEST_CHECK( !cameraActor );
210  END_TEST;
211 }
212 
213 // Note: SetType and GetType are tested within the same test cases.
214 
216 {
217  TestApplication application;
218  tet_infoline( "Testing Dali::CameraActor GetType (P)" );
219 
220  CameraActor actor = CameraActor::New();
222 
225 
226  std::string sValue;
227  actor.GetProperty( CameraActor::Property::TYPE ).Get( sValue );
228  std::string result( "LOOK_AT_TARGET");
229  DALI_TEST_EQUALS( result, sValue, TEST_LOCATION );
230  END_TEST;
231 }
232 
234 {
235  TestApplication application;
236  tet_infoline( "Testing Dali::CameraActor GetType (N)" );
237 
238  CameraActor actor;
239 
241  try
242  {
243  cameraType = actor.GetType();
244  }
245  catch ( Dali::DaliException& e )
246  {
248  DALI_TEST_ASSERT( e, "camera", TEST_LOCATION );
249  }
250 
251  const CameraActor aConstActor;
252 
253  try
254  {
255  cameraType = aConstActor.GetType();
256  }
257  catch ( Dali::DaliException& e )
258  {
260  DALI_TEST_ASSERT( e, "camera", TEST_LOCATION );
261  }
262 
264  END_TEST;
265 }
266 
268 {
269  TestApplication application;
270  tet_infoline( "Testing Dali::CameraActor Set Field of view (P)" );
271 
273  const float defaultFieldOfView = defaultCamera.GetFieldOfView();
274 
275  CameraActor actor = CameraActor::New();
276  DALI_TEST_EQUALS( actor.GetFieldOfView(), defaultFieldOfView, TEST_LOCATION );
277 
278  float fieldOfView = Math::PI / 3.0f;
279  actor.SetFieldOfView( fieldOfView );
280  DALI_TEST_EQUALS( actor.GetFieldOfView(), fieldOfView, TEST_LOCATION );
281 
282  float value;
284  DALI_TEST_EQUALS( fieldOfView, value, FLOAT_EPSILON, TEST_LOCATION );
285  END_TEST;
286 }
287 
289 {
290  TestApplication application;
291  tet_infoline( "Testing Dali::CameraActor Set Field of view (N)" );
292 
294  const float defaultFieldOfView = defaultCamera.GetFieldOfView();
295 
296  CameraActor actor = CameraActor::New();
297  DALI_TEST_EQUALS( actor.GetFieldOfView(), defaultFieldOfView, TEST_LOCATION );
298 
299  float fieldOfView = Math::PI / 3.0f;
300  actor.SetFieldOfView( fieldOfView );
301  DALI_TEST_EQUALS( actor.GetFieldOfView(), fieldOfView, TEST_LOCATION );
302 
303  float value;
305  DALI_TEST_EQUALS( fieldOfView, value, FLOAT_EPSILON, TEST_LOCATION );
306  END_TEST;
307 }
308 
310 {
311  TestApplication application;
312  tet_infoline( "Testing Dali::CameraActor Get Field of view (P)" );
314 
315  CameraActor defaultCamera = CameraActor::New( size );
316 
317  const float cameraZ = 2.0f * std::max( size.width, size.height );
318  const float expectedFieldOfView = 2.0f * std::atan( size.height * 0.5f / cameraZ );
319 
320  CameraActor actor = CameraActor::New();
321  DALI_TEST_EQUALS( actor.GetFieldOfView(), expectedFieldOfView, TEST_LOCATION );
322 
323  float value;
325  DALI_TEST_EQUALS( expectedFieldOfView, value, FLOAT_EPSILON, TEST_LOCATION);
326  END_TEST;
327 }
328 
330 {
331  TestApplication application;
332  tet_infoline( "Testing Dali::CameraActor Get Field of view (N)" );
333 
334  CameraActor defaultCamera = CameraActor::New();
335 
336  bool asserted = true;
337  try
338  {
339  defaultCamera.GetFieldOfView();
340  }
341  catch( Dali::DaliException& e )
342  {
344  DALI_TEST_ASSERT( e, "camera && \"Camera handle is empty\"", TEST_LOCATION );
345  asserted = true;
346  }
347  DALI_TEST_CHECK( asserted );
348 
349  END_TEST;
350 }
351 
352 //todor
354 {
355  TestApplication application;
356  tet_infoline( "Testing Dali::CameraActor Set Aspect Ratio (P)" );
357 
358  CameraActor actor = CameraActor::New();
360 
361  // Set an initial value to confirm a further set changes it.
362  float aspect = 4.0f / 3.0f;
363  actor.SetAspectRatio( aspect );
364  DALI_TEST_EQUALS( actor.GetAspectRatio(), aspect, TEST_LOCATION );
365 
366  aspect = 16.0f / 9.0f;
367  actor.SetAspectRatio( aspect );
368  DALI_TEST_EQUALS( actor.GetAspectRatio(), aspect, TEST_LOCATION );
369 
370  END_TEST;
371 }
372 
374 {
375  TestApplication application;
376  tet_infoline( "Testing Dali::CameraActor Set Aspect Ratio (N)" );
377 
378  CameraActor actor;
379 
380  bool asserted = true;
381  try
382  {
383  actor.SetAspectRatio( 16.0f / 9.0f );
384  }
385  catch( Dali::DaliException& e )
386  {
388  DALI_TEST_ASSERT( e, "camera && \"Camera handle is empty\"", TEST_LOCATION );
389  asserted = true;
390  }
391  DALI_TEST_CHECK( asserted );
392 
393  END_TEST;
394 }
395 
397 {
398  TestApplication application;
399  tet_infoline("Testing Dali::CameraActor Get Aspect Ratio");
400 
401  CameraActor actor = CameraActor::New();
402  float defaultAspect = static_cast<float>( TestApplication::DEFAULT_SURFACE_WIDTH ) / static_cast<float>( TestApplication::DEFAULT_SURFACE_HEIGHT );
403 
404  DALI_TEST_EQUALS( actor.GetAspectRatio(), defaultAspect, TEST_LOCATION );
405 
406  float value = 0.0f;
407  actor.GetProperty( CameraActor::Property::ASPECT_RATIO ).Get( value );
408  DALI_TEST_EQUALS( defaultAspect, value, FLOAT_EPSILON, TEST_LOCATION );
409 
410  END_TEST;
411 }
412 
414 {
415  TestApplication application;
416  tet_infoline( "Testing Dali::CameraActor Get Aspect Ratio (N)" );
417 
418  CameraActor actor;
419 
420  bool asserted = true;
421  try
422  {
423  actor.GetAspectRatio();
424  }
425  catch( Dali::DaliException& e )
426  {
428  DALI_TEST_ASSERT( e, "camera && \"Camera handle is empty\"", TEST_LOCATION );
429  asserted = true;
430  }
431 
432  DALI_TEST_CHECK( asserted );
433 
434  END_TEST;
435 }
436 
438 {
439  TestApplication application;
440  tet_infoline( "Testing Dali::CameraActor Set Near clipping plane (P)" );
441 
442  CameraActor actor = CameraActor::New();
443 
444  // Set a value so we are not relying on a particular default for this test case.
445  actor.SetNearClippingPlane( 200.0f );
447 
448  actor.SetNearClippingPlane( 400.0f );
450 
451  // Check setting the property.
454  END_TEST;
455 }
456 
458 {
459  TestApplication application;
460  tet_infoline( "Testing Dali::CameraActor Set Near clipping plane (N)" );
461 
462  CameraActor actor;
463 
464  bool asserted = true;
465  try
466  {
467  actor.SetNearClippingPlane( 200.0f );
468  }
469  catch( Dali::DaliException& e )
470  {
472  DALI_TEST_ASSERT( e, "camera && \"Camera handle is empty\"", TEST_LOCATION );
473  asserted = true;
474  }
475 
476  DALI_TEST_CHECK( asserted );
477 
478  END_TEST;
479 }
480 
482 {
483  TestApplication application;
484  tet_infoline( "Testing Dali::CameraActor Get Near clipping plane (P)" );
485 
486  // Check the default value.
487  CameraActor actor = CameraActor::New();
488  float defaultValue = 800.0f;
489  DALI_TEST_EQUALS( actor.GetNearClippingPlane(), defaultValue, TEST_LOCATION );
490 
491  // Check getting the property.
492  float value;
494  DALI_TEST_EQUALS( defaultValue, value, FLOAT_EPSILON, TEST_LOCATION );
495  END_TEST;
496 }
497 
499 {
500  TestApplication application;
501  tet_infoline( "Testing Dali::CameraActor Get Near clipping plane (N)" );
502 
503  CameraActor actor;
504  bool asserted = true;
505  try
506  {
507  actor.GetNearClippingPlane();
508  }
509  catch( Dali::DaliException& e )
510  {
512  DALI_TEST_ASSERT( e, "camera && \"Camera handle is empty\"", TEST_LOCATION );
513  asserted = true;
514  }
515 
516  DALI_TEST_CHECK( asserted );
517 
518  END_TEST;
519 }
520 
522 {
523  TestApplication application;
524  tet_infoline( "Testing Dali::CameraActor Set Far clipping plane (P)" );
525 
526  CameraActor actor = CameraActor::New();
527 
528  // Set a value so we are not relying on a particular default for this test case.
529  actor.SetFarClippingPlane( 2000.0f );
531 
532  actor.SetFarClippingPlane( 4000.0f );
534 
535  // Check setting the property.
538  END_TEST;
539 }
540 
542 {
543  TestApplication application;
544  tet_infoline( "Testing Dali::CameraActor Set Far clipping plane (N)" );
545 
546  CameraActor actor;
547 
548  bool asserted = true;
549  try
550  {
551  actor.SetFarClippingPlane( 2000.0f );
552  }
553  catch( Dali::DaliException& e )
554  {
556  DALI_TEST_ASSERT( e, "camera && \"Camera handle is empty\"", TEST_LOCATION );
557  asserted = true;
558  }
559 
560  DALI_TEST_CHECK( asserted );
561 
562  END_TEST;
563 }
564 
566 {
567  TestApplication application;
568  tet_infoline( "Testing Dali::CameraActor Get Far clipping plane (P)" );
569 
570  CameraActor actor = CameraActor::New();
571  float defaultValue = 800.0f + ( 0xFFFF >> 4 );
572  DALI_TEST_EQUALS( actor.GetFarClippingPlane(), defaultValue, TEST_LOCATION );
573 
574  // Check getting the property.
575  float value;
577  DALI_TEST_EQUALS( defaultValue, value, FLOAT_EPSILON, TEST_LOCATION );
578  END_TEST;
579 }
580 
582 {
583  TestApplication application;
584  tet_infoline( "Testing Dali::CameraActor Get Far clipping plane (N)" );
585 
586  CameraActor actor;
587 
588  bool asserted = true;
589  try
590  {
591  actor.GetFarClippingPlane();
592  }
593  catch( Dali::DaliException& e )
594  {
596  DALI_TEST_ASSERT( e, "camera && \"Camera handle is empty\"", TEST_LOCATION );
597  asserted = true;
598  }
599 
600  DALI_TEST_CHECK( asserted );
601 
602  END_TEST;
603 }
604 
606 {
607  TestApplication application;
608  tet_infoline( "Testing Dali::CameraActor Set Target Position (P)" );
609 
610  CameraActor actor = CameraActor::New();
611 
612  Vector3 target1( 10.0f, 20.0f, 30.0f );
613  Vector3 target2( 15.0f, 25.0f, 35.0f );
614 
615  // Set a value so we are not relying on a particular default for this test case.
616  actor.SetTargetPosition( target1 );
617  DALI_TEST_EQUALS( actor.GetTargetPosition(), target1, TEST_LOCATION );
618 
619  actor.SetTargetPosition( target2 );
620  DALI_TEST_EQUALS( actor.GetTargetPosition(), target2, TEST_LOCATION );
621 
622  // Check setting the property.
625  END_TEST;
626 }
627 
629 {
630  TestApplication application;
631  tet_infoline( "Testing Dali::CameraActor Set Target Position (N)" );
632 
633  CameraActor actor;
634 
635  bool asserted = true;
636  try
637  {
638  actor.SetTargetPosition( Vector3( 10.0f, 20.0f, 30.0f ) );
639  }
640  catch( Dali::DaliException& e )
641  {
643  DALI_TEST_ASSERT( e, "camera && \"Camera handle is empty\"", TEST_LOCATION );
644  asserted = true;
645  }
646  DALI_TEST_CHECK( asserted );
647 
648  END_TEST;
649 }
650 
652 {
653  TestApplication application;
654  tet_infoline( "Testing Dali::CameraActor Get Target Position (P)" );
655 
656  CameraActor actor = CameraActor::New();
657  Vector3 defaultValue( Vector3::ZERO );
658  DALI_TEST_EQUALS( actor.GetTargetPosition(), defaultValue, TEST_LOCATION );
659 
660  // Check getting the property.
661  Vector3 value;
663  DALI_TEST_EQUALS( defaultValue, value, FLOAT_EPSILON, TEST_LOCATION );
664  END_TEST;
665 }
666 
668 {
669  TestApplication application;
670  tet_infoline( "Testing Dali::CameraActor Get Target Position (N)" );
671 
672  CameraActor actor;
673 
674  bool asserted = true;
675  try
676  {
677  actor.GetTargetPosition();
678  }
679  catch( Dali::DaliException& e )
680  {
682  DALI_TEST_ASSERT( e, "camera && \"Camera handle is empty\"", TEST_LOCATION );
683  asserted = true;
684  }
685  DALI_TEST_CHECK( asserted );
686 
687  END_TEST;
688 }
689 
691 {
692  TestApplication application;
693  tet_infoline( "Testing Dali::CameraActor Set InvertYAxis (P)" );
694 
695  CameraActor actor = CameraActor::New();
696 
697  // Set a value so we are not relying on a particular default for this test case.
698  actor.SetInvertYAxis( false );
699  DALI_TEST_EQUALS( actor.GetInvertYAxis(), false, TEST_LOCATION );
700 
701  actor.SetInvertYAxis( true );
703 
705  DALI_TEST_EQUALS( actor.GetInvertYAxis(), false, TEST_LOCATION );
706  END_TEST;
707 }
708 
710 {
711  TestApplication application;
712  tet_infoline( "Testing Dali::CameraActor Set InvertYAxis (N)" );
713 
714  CameraActor actor;
715 
716  bool asserted = true;
717  try
718  {
719  actor.SetInvertYAxis( false );
720  }
721  catch( Dali::DaliException& e )
722  {
724  DALI_TEST_ASSERT( e, "camera && \"Camera handle is empty\"", TEST_LOCATION );
725  asserted = true;
726  }
727  DALI_TEST_CHECK( asserted );
728  END_TEST;
729 }
730 
732 {
733  TestApplication application;
734  tet_infoline( "Testing Dali::CameraActor Get InvertYAxis (P)" );
735 
736  // Check the default value.
737  CameraActor actor = CameraActor::New();
738  DALI_TEST_EQUALS( actor.GetInvertYAxis(), false, TEST_LOCATION );
739 
740  // Check getting the property.
741  bool bValue;
742  actor.GetProperty( CameraActor::Property::INVERT_Y_AXIS ).Get( bValue );
743  DALI_TEST_EQUALS( false, bValue, TEST_LOCATION );
744  END_TEST;
745 }
746 
748 {
749  TestApplication application;
750  tet_infoline( "Testing Dali::CameraActor Get InvertYAxis (N)" );
751 
752  CameraActor actor;
753 
754  bool asserted = true;
755  try
756  {
757  actor.GetInvertYAxis();
758  }
759  catch( Dali::DaliException& e )
760  {
762  DALI_TEST_ASSERT( e, "camera && \"Camera handle is empty\"", TEST_LOCATION );
763  asserted = true;
764  }
765  DALI_TEST_CHECK( asserted );
766  END_TEST;
767 }
768 
770 {
771  TestApplication application;
772  tet_infoline( "Testing Dali::CameraActor::SetPerspectiveProjection (P)" );
773 
774  CameraActor actor = CameraActor::New();
775  actor.SetPerspectiveProjection( Size( 100.f, 150.f ) );
776 
777  DALI_TEST_CHECK( actor );
778 
779  float value;
780  actor.GetProperty( CameraActor::Property::ASPECT_RATIO ).Get( value );
781  DALI_TEST_EQUALS( 0.666666f, value, FLOAT_EPSILON, TEST_LOCATION );
783  DALI_TEST_EQUALS( 0.489957f, value, FLOAT_EPSILON, TEST_LOCATION );
785  DALI_TEST_EQUALS( 150.f, value, FLOAT_EPSILON, TEST_LOCATION );
787  DALI_TEST_EQUALS( 4245.f, value, FLOAT_EPSILON, TEST_LOCATION );
788 
790 
791  END_TEST;
792 }
793 
795 {
796  TestApplication application;
797  tet_infoline( "Testing Dali::CameraActor::SetPerspectiveProjection (N)" );
798 
799  Stage stage = Stage::GetCurrent();
800  Vector2 stageSize = stage.GetSize();
801 
802  CameraActor actor = CameraActor::New();
803 
804  // Check that setting perspective projection without a size (using zero size) uses the stages size.
806 
807  float nearClippingPlane = std::max( stageSize.width, stageSize.height );
808  float farClippingPlane = nearClippingPlane + static_cast<float>( 0xFFFF >> 4 );
809 
810  DALI_TEST_EQUALS( nearClippingPlane, actor.GetNearClippingPlane(), FLOAT_EPSILON, TEST_LOCATION );
811  DALI_TEST_EQUALS( farClippingPlane, actor.GetFarClippingPlane(), FLOAT_EPSILON, TEST_LOCATION );
813 
814  END_TEST;
815 }
816 
818 {
819  TestApplication application;
820  tet_infoline( "Testing Dali::CameraActor::SetOrthographicProjection (P,1)" );
821 
822  CameraActor actor = CameraActor::New( Size( 1080.0f, 1920.0f ) );
823  DALI_TEST_CHECK( actor );
824 
825  Stage::GetCurrent().Add( actor );
826 
827  actor.SetOrthographicProjection( Size( 1080.0f, 1920.0f ) );
828  application.SendNotification();
829  application.Render( 0 );
830  application.Render();
831  application.SendNotification();
832 
833  float defaultAspectRatio;
834  float defaultFieldOfView;
835  float defaultNearPlaneDistance;
836  float defaultFarPlaneDistance;
837  actor.GetProperty( CameraActor::Property::ASPECT_RATIO ).Get( defaultAspectRatio );
838  actor.GetProperty( CameraActor::Property::FIELD_OF_VIEW ).Get( defaultFieldOfView );
839  actor.GetProperty( CameraActor::Property::NEAR_PLANE_DISTANCE ).Get( defaultNearPlaneDistance );
840  actor.GetProperty( CameraActor::Property::FAR_PLANE_DISTANCE ).Get( defaultFarPlaneDistance );
841  Vector3 defaultPos = actor.GetCurrentPosition();
842 
843  actor.SetOrthographicProjection( Size( 1080.0f, 1920.0f ) );
844 
845  application.SendNotification();
846  application.Render( 0 );
847  application.Render();
848  application.SendNotification();
849 
850  float value;
851  actor.GetProperty( CameraActor::Property::ASPECT_RATIO ).Get( value );
852  DALI_TEST_EQUALS( defaultAspectRatio, value, FLOAT_EPSILON, TEST_LOCATION );
854  DALI_TEST_EQUALS( defaultFieldOfView, value, FLOAT_EPSILON, TEST_LOCATION );
856  DALI_TEST_EQUALS( defaultNearPlaneDistance, value, FLOAT_EPSILON, TEST_LOCATION );
858  DALI_TEST_EQUALS( defaultFarPlaneDistance, value, FLOAT_EPSILON, TEST_LOCATION );
859 
861  DALI_TEST_EQUALS( -540.0f, value, FLOAT_EPSILON, TEST_LOCATION );
863  DALI_TEST_EQUALS( 540.0f, value, FLOAT_EPSILON, TEST_LOCATION );
865  DALI_TEST_EQUALS( 960.0f, value, FLOAT_EPSILON, TEST_LOCATION );
867  DALI_TEST_EQUALS( -960.0f, value, FLOAT_EPSILON, TEST_LOCATION );
868 
869  Vector3 pos = actor.GetCurrentPosition();
870  DALI_TEST_EQUALS( defaultPos.z, pos.z, 0.001f, TEST_LOCATION );
871 
873  END_TEST;
874 }
875 
877 {
878  TestApplication application;
879  tet_infoline( "Testing Dali::CameraActor::SetOrthographicProjection (N)" );
880 
881  CameraActor actor;
882  bool asserted = true;
883  try
884  {
885  actor.GetProjectionMode();
886  }
887  catch( Dali::DaliException& e )
888  {
890  DALI_TEST_ASSERT( e, "camera && \"Camera handle is empty\"", TEST_LOCATION );
891  asserted = true;
892  }
893  DALI_TEST_CHECK( asserted );
894  END_TEST;
895 }
896 
898 {
899  TestApplication application;
900  tet_infoline( "Testing Dali::CameraActor::SetOrthographicProjection (P,2)" );
901 
902  CameraActor actor = CameraActor::New();
903  DALI_TEST_CHECK( actor );
904 
905  float defaultAspectRatio;
906  float defaultFieldOfView;
907  float defaultNearPlaneDistance;
908  float defaultFarPlaneDistance;
909  actor.GetProperty( CameraActor::Property::ASPECT_RATIO ).Get( defaultAspectRatio );
910  actor.GetProperty( CameraActor::Property::FIELD_OF_VIEW ).Get( defaultFieldOfView );
911  actor.GetProperty( CameraActor::Property::NEAR_PLANE_DISTANCE ).Get( defaultNearPlaneDistance );
912  actor.GetProperty( CameraActor::Property::FAR_PLANE_DISTANCE ).Get( defaultFarPlaneDistance );
913 
914  // Check setting with specific near and far plane distances.
915  actor.SetOrthographicProjection( -100.0f, 200.0f, -300.0f, 500.0f, 400.0f, 4000.0f );
916 
917  float value;
918  actor.GetProperty( CameraActor::Property::ASPECT_RATIO ).Get( value );
919  DALI_TEST_EQUALS( defaultAspectRatio, value, FLOAT_EPSILON, TEST_LOCATION );
921  DALI_TEST_EQUALS( defaultFieldOfView, value, FLOAT_EPSILON, TEST_LOCATION );
923  DALI_TEST_EQUALS( 400.0f, value, FLOAT_EPSILON, TEST_LOCATION );
925  DALI_TEST_EQUALS( 4000.0f, value, FLOAT_EPSILON, TEST_LOCATION );
926 
928  DALI_TEST_EQUALS( -100.0f, value, FLOAT_EPSILON, TEST_LOCATION );
930  DALI_TEST_EQUALS( 200.0f, value, FLOAT_EPSILON, TEST_LOCATION );
932  DALI_TEST_EQUALS( -300.0f, value, FLOAT_EPSILON, TEST_LOCATION );
934  DALI_TEST_EQUALS( 500.0f, value, FLOAT_EPSILON, TEST_LOCATION );
935 
937 
938  END_TEST;
939 }
940 
942 {
943  TestApplication application;
944  tet_infoline( "Testing Dali::CameraActor::SetOrthographicProjection (P,3)" );
945 
946  CameraActor actor = CameraActor::New();
947  DALI_TEST_CHECK( actor );
948 
949  float defaultAspectRatio;
950  float defaultFieldOfView;
951  float defaultNearPlaneDistance;
952  float defaultFarPlaneDistance;
953  actor.GetProperty( CameraActor::Property::ASPECT_RATIO ).Get( defaultAspectRatio );
954  actor.GetProperty( CameraActor::Property::FIELD_OF_VIEW ).Get( defaultFieldOfView );
955  actor.GetProperty( CameraActor::Property::NEAR_PLANE_DISTANCE ).Get( defaultNearPlaneDistance );
956  actor.GetProperty( CameraActor::Property::FAR_PLANE_DISTANCE ).Get( defaultFarPlaneDistance );
957 
959 
964  actor.SetNearClippingPlane( 400.0f );
965  actor.SetFarClippingPlane( 4000.0f );
966 
967  float value;
968  actor.GetProperty( CameraActor::Property::ASPECT_RATIO ).Get( value );
969  DALI_TEST_EQUALS( defaultAspectRatio, value, FLOAT_EPSILON, TEST_LOCATION );
971  DALI_TEST_EQUALS( defaultFieldOfView, value, FLOAT_EPSILON, TEST_LOCATION );
973  DALI_TEST_EQUALS( 400.0f, value, FLOAT_EPSILON, TEST_LOCATION );
975  DALI_TEST_EQUALS( 4000.0f, value, FLOAT_EPSILON, TEST_LOCATION );
976 
978  DALI_TEST_EQUALS( -100.0f, value, FLOAT_EPSILON, TEST_LOCATION );
980  DALI_TEST_EQUALS( 200.0f, value, FLOAT_EPSILON, TEST_LOCATION );
982  DALI_TEST_EQUALS( -300.0f, value, FLOAT_EPSILON, TEST_LOCATION );
984  DALI_TEST_EQUALS( 500.0f, value, FLOAT_EPSILON, TEST_LOCATION );
985 
987  std::string stringValue;
988  actor.GetProperty( CameraActor::Property::PROJECTION_MODE ).Get( stringValue );
989  DALI_TEST_EQUALS( stringValue, "ORTHOGRAPHIC_PROJECTION", TEST_LOCATION );
990  END_TEST;
991 }
992 
994 {
995  TestApplication application;
996  tet_infoline( "Testing Dali::CameraActor::SetProjectionModeP (P)" );
997 
998  CameraActor actor = CameraActor::New();
999 
1000  // Check that changing the projection mode alone does not alter other presets.
1001  actor.SetNearClippingPlane( 200.0f );
1002  actor.SetFarClippingPlane( 400.0f );
1003 
1005 
1009 
1011 
1015 
1016  // Check setting the property.
1017  Property::Value setValue = "PERSPECTIVE_PROJECTION";
1020  END_TEST;
1021 }
1022 
1024 {
1025  TestApplication application;
1026  tet_infoline( "Testing Dali::CameraActor::SetProjectionModeP (N)" );
1027 
1028  CameraActor actor;
1029 
1030  bool asserted = true;
1031  try
1032  {
1034  }
1035  catch( Dali::DaliException& e )
1036  {
1038  DALI_TEST_ASSERT( e, "camera && \"Camera handle is empty\"", TEST_LOCATION );
1039  asserted = true;
1040  }
1041  DALI_TEST_CHECK( asserted );
1042  END_TEST;
1043 }
1044 
1046 {
1047  TestApplication application;
1048  tet_infoline( "Testing Dali::CameraActor::GetPerspectiveProjection (P)" );
1049 
1050  CameraActor actor = CameraActor::New();
1051 
1054 
1055  actor.SetPerspectiveProjection( Size( 100.f, 150.f ) );
1057 
1058  // Check getting the property.
1059  std::string stringValue;
1060  actor.GetProperty( CameraActor::Property::PROJECTION_MODE ).Get( stringValue );
1061  DALI_TEST_EQUALS( stringValue, "PERSPECTIVE_PROJECTION", TEST_LOCATION );
1062  END_TEST;
1063 }
1064 
1066 {
1067  TestApplication application;
1068  tet_infoline( "Testing Dali::CameraActor::GetProjectionMode (N)" );
1069 
1070  CameraActor actor;
1071 
1072  bool asserted = true;
1073  try
1074  {
1075  actor.GetProjectionMode();
1076  }
1077  catch( Dali::DaliException& e )
1078  {
1080  DALI_TEST_ASSERT( e, "camera && \"Camera handle is empty\"", TEST_LOCATION );
1081  asserted = true;
1082  }
1083  DALI_TEST_CHECK( asserted );
1084  END_TEST;
1085 }
1086 
1088 {
1089  TestApplication application;
1090  tet_infoline( "Testing Dali::CameraActor::SetCamera()" );
1091 
1092  CameraActor actor = CameraActor::New();
1093 
1094  actor.SetType( Camera::FREE_LOOK );
1095  actor.SetFieldOfView( TEST_FIELD_OF_VIEW );
1096  actor.SetAspectRatio( TEST_ASPECT_RATIO );
1100 
1101  actor.SetInvertYAxis( false );
1102 
1103  DALI_TEST_EQUALS( TEST_ASPECT_RATIO, actor.GetAspectRatio(), FLOAT_EPSILON, TEST_LOCATION );//change to machine epsilon
1104  DALI_TEST_EQUALS( TEST_FIELD_OF_VIEW, actor.GetFieldOfView(), FLOAT_EPSILON, TEST_LOCATION );
1108  DALI_TEST_EQUALS( false, actor.GetInvertYAxis(), TEST_LOCATION );
1109 
1110  float value;
1111  std::string sValue;
1112  actor.GetProperty( CameraActor::Property::ASPECT_RATIO).Get( value );
1113  DALI_TEST_EQUALS( TEST_ASPECT_RATIO, value, FLOAT_EPSILON, TEST_LOCATION );
1115  DALI_TEST_EQUALS( TEST_FIELD_OF_VIEW, value, FLOAT_EPSILON, TEST_LOCATION );
1117  DALI_TEST_EQUALS( TEST_NEAR_PLANE_DISTANCE, value, FLOAT_EPSILON, TEST_LOCATION );
1119  DALI_TEST_EQUALS( TEST_FAR_PLANE_DISTANCE, value, FLOAT_EPSILON, TEST_LOCATION );
1121  DALI_TEST_EQUALS( "PERSPECTIVE_PROJECTION", sValue, TEST_LOCATION );
1122  bool bValue;
1123  actor.GetProperty( CameraActor::Property::INVERT_Y_AXIS).Get( bValue );
1124  DALI_TEST_EQUALS( false, bValue, TEST_LOCATION );
1125  END_TEST;
1126 }
1127 
1129 {
1130  TestApplication application;
1131  tet_infoline( "Testing Dali::CameraActor::SetCamera()" );
1132 
1133  CameraActor actor = CameraActor::New();
1134  Stage::GetCurrent().Add( actor );
1135  application.Render( 0 );
1136  application.SendNotification();
1137 
1139  actor.SetFieldOfView( TEST_FIELD_OF_VIEW );
1140  actor.SetAspectRatio( TEST_ASPECT_RATIO );
1143  actor.SetInvertYAxis( false );
1144 
1145  DALI_TEST_EQUALS( false, actor.GetInvertYAxis(), TEST_LOCATION );
1146 
1147  // Will need 2 frames to ensure both buffers are set to same values:
1148  application.Render();
1149  application.SendNotification();
1150  application.Render();
1151  application.SendNotification();
1152 
1153  DALI_TEST_EQUALS( TEST_ASPECT_RATIO, actor.GetAspectRatio(), FLOAT_EPSILON, TEST_LOCATION );
1154  DALI_TEST_EQUALS( TEST_FIELD_OF_VIEW, actor.GetFieldOfView(), FLOAT_EPSILON, TEST_LOCATION );
1157  DALI_TEST_EQUALS( false, actor.GetInvertYAxis(), TEST_LOCATION );
1158 
1159  std::string sValue;
1160  actor.GetProperty( CameraActor::Property::TYPE ).Get( sValue );
1161  DALI_TEST_EQUALS( sValue, "LOOK_AT_TARGET", TEST_LOCATION );
1162 
1163  float value;
1164  actor.GetProperty( CameraActor::Property::ASPECT_RATIO ).Get( value );
1165  DALI_TEST_EQUALS( TEST_ASPECT_RATIO, value, FLOAT_EPSILON, TEST_LOCATION );
1166  actor.GetProperty( CameraActor::Property::FIELD_OF_VIEW ).Get( value );
1167  DALI_TEST_EQUALS( TEST_FIELD_OF_VIEW, value, FLOAT_EPSILON, TEST_LOCATION );
1169  DALI_TEST_EQUALS( TEST_NEAR_PLANE_DISTANCE, value, FLOAT_EPSILON, TEST_LOCATION );
1171  DALI_TEST_EQUALS( TEST_FAR_PLANE_DISTANCE, value, FLOAT_EPSILON, TEST_LOCATION );
1172 
1173  bool bValue;
1174  actor.GetProperty( CameraActor::Property::INVERT_Y_AXIS ).Get( bValue );
1175  DALI_TEST_EQUALS( false, bValue, TEST_LOCATION );
1176  END_TEST;
1177 }
1178 
1180 {
1181  TestApplication application;
1182  tet_infoline( "Testing Dali::CameraActor::GetCamera()" );
1183 
1184  CameraActor actor = CameraActor::New();
1185 
1186  actor.SetAspectRatio( TEST_ASPECT_RATIO );
1187 
1189 
1190  actor.SetProperty( CameraActor::Property::TYPE, "FREE_LOOK" );
1191  actor.SetProperty( CameraActor::Property::ASPECT_RATIO, TEST_ASPECT_RATIO );
1192  actor.SetProperty( CameraActor::Property::FIELD_OF_VIEW, TEST_FIELD_OF_VIEW );
1195 
1197  DALI_TEST_EQUALS( TEST_ASPECT_RATIO, actor.GetAspectRatio(), FLOAT_EPSILON, TEST_LOCATION );
1198  DALI_TEST_EQUALS( TEST_FIELD_OF_VIEW, actor.GetFieldOfView(), FLOAT_EPSILON, TEST_LOCATION );
1201  END_TEST;
1202 }
1203 
1205 {
1206  TestApplication application;
1207  tet_infoline( "Testing Dali::CameraActor DefaultProperties" );
1208 
1209  CameraActor actor = CameraActor::New();
1210 
1211  actor.SetAspectRatio( TEST_ASPECT_RATIO );
1212  Stage::GetCurrent().Add( actor );
1213  application.Render( 0 );
1214  application.SendNotification();
1215  bool bValue;
1216  actor.GetProperty( CameraActor::Property::INVERT_Y_AXIS ).Get( bValue );
1217  DALI_TEST_EQUALS( false, bValue, TEST_LOCATION );
1218 
1219  std::vector<Property::Index> indices ;
1220  indices.push_back( CameraActor::Property::TYPE );
1221  indices.push_back( CameraActor::Property::PROJECTION_MODE );
1222  indices.push_back( CameraActor::Property::FIELD_OF_VIEW );
1223  indices.push_back( CameraActor::Property::ASPECT_RATIO );
1224  indices.push_back( CameraActor::Property::NEAR_PLANE_DISTANCE );
1225  indices.push_back( CameraActor::Property::FAR_PLANE_DISTANCE );
1226  indices.push_back( CameraActor::Property::LEFT_PLANE_DISTANCE );
1227  indices.push_back( CameraActor::Property::RIGHT_PLANE_DISTANCE );
1228  indices.push_back( CameraActor::Property::TOP_PLANE_DISTANCE );
1229  indices.push_back( CameraActor::Property::BOTTOM_PLANE_DISTANCE );
1230  indices.push_back( CameraActor::Property::TARGET_POSITION );
1231  indices.push_back( CameraActor::Property::PROJECTION_MATRIX );
1232  indices.push_back( CameraActor::Property::VIEW_MATRIX );
1233  indices.push_back( CameraActor::Property::INVERT_Y_AXIS );
1234 
1235  DALI_TEST_CHECK( actor.GetPropertyCount() == ( Actor::New().GetPropertyCount() + indices.size() ) );
1236 
1237  for( std::vector<Property::Index>::iterator iter = indices.begin(); iter != indices.end(); ++iter )
1238  {
1239  DALI_TEST_EQUALS( *iter, actor.GetPropertyIndex( actor.GetPropertyName( *iter ) ), TEST_LOCATION);
1240  DALI_TEST_CHECK( !actor.IsPropertyAnimatable( *iter ) );
1241 
1242  if ( ( *iter == CameraActor::Property::PROJECTION_MATRIX ) ||
1243  ( *iter == CameraActor::Property::VIEW_MATRIX ) )
1244  {
1245  DALI_TEST_CHECK( !actor.IsPropertyWritable( *iter ) );
1246  }
1247  else
1248  {
1249  DALI_TEST_CHECK( actor.IsPropertyWritable( *iter ) );
1250  }
1251 
1252  DALI_TEST_CHECK( actor.GetPropertyType( *iter ) == actor.GetPropertyType( *iter ) ); // just checking call succeeds
1253  }
1254 
1255  // Set/Get one of them.
1256  const float newAspect = TEST_ASPECT_RATIO * 2.0f;
1257 
1259  application.Render();
1260  application.SendNotification();
1261  application.Render();
1262  application.SendNotification();
1263 
1264  DALI_TEST_EQUALS( actor.GetAspectRatio(), newAspect, TEST_LOCATION );
1265  END_TEST;
1266 }
1267 
1269 {
1270  TestApplication application;
1271  tet_infoline( "Testing Dali::CameraActor Test view application" );
1272 
1273  BufferImage image = CreateBufferImage();
1274 
1275  ImageActor actor = ImageActor::New( image );
1276  actor.SetSize( 100.0f, 100.0f );
1277  actor.SetPosition( 20.0f, 30.0f, 40.0f );
1279  Stage::GetCurrent().Add( actor );
1280 
1281  application.SendNotification();
1282  application.Render( 0 );
1283  application.Render();
1284  application.SendNotification();
1285 
1286  Matrix resultMatrix( true );
1288 
1290  CameraActor cameraActor = task.GetCameraActor();
1291 
1292  Matrix viewMatrix( false );
1293  cameraActor.GetProperty( CameraActor::Property::VIEW_MATRIX ).Get( viewMatrix );
1294  Matrix::Multiply( resultMatrix, resultMatrix, viewMatrix );
1295 
1296  DALI_TEST_CHECK( application.GetGlAbstraction().CheckUniformValue( "uModelView", resultMatrix ) );
1297  END_TEST;
1298 }
1299 
1301 {
1302  TestApplication application;
1303  tet_infoline( "Testing Dali::CameraActor::ReadProjectionMatrix()" );
1304 
1306  application.SendNotification();
1307  application.Render( 0 );
1308  application.Render();
1309  application.SendNotification();
1310  Image image = CreateBufferImage();
1311  ImageActor imageActor = ImageActor::New( image );
1312  imageActor.SetSize( 100.0f, 100.0f );
1313  Stage::GetCurrent().Add( imageActor );
1314 
1315  Matrix projectionMatrix;
1316  Matrix viewMatrix;
1317 
1318  camera.GetProperty( CameraActor::CameraActor::Property::PROJECTION_MATRIX ).Get( projectionMatrix );
1319  camera.GetProperty( CameraActor::CameraActor::Property::VIEW_MATRIX ).Get( viewMatrix );
1320 
1322  imageActor.SetShaderEffect( shaderEffect );
1323 
1326 
1327  Property::Index projectionMatrixPropertyIndex = shaderEffect.GetPropertyIndex( SHADER_LIGHT_CAMERA_PROJECTION_MATRIX_PROPERTY_NAME );
1328  Property::Index viewMatrixPropertyIndex = shaderEffect.GetPropertyIndex( SHADER_LIGHT_CAMERA_VIEW_MATRIX_PROPERTY_NAME );
1329 
1330  Constraint projectionMatrixConstraint = Constraint::New<Dali::Matrix>( shaderEffect, projectionMatrixPropertyIndex, EqualToConstraint() );
1331  projectionMatrixConstraint.AddSource( Source( camera, CameraActor::Property::PROJECTION_MATRIX ) );
1332  Constraint viewMatrixConstraint = Constraint::New<Dali::Matrix>( shaderEffect, viewMatrixPropertyIndex, EqualToConstraint() );
1333  viewMatrixConstraint.AddSource( Source( camera, CameraActor::Property::VIEW_MATRIX ) );
1334 
1335  projectionMatrixConstraint.Apply();
1336  viewMatrixConstraint.Apply();
1337 
1338  application.SendNotification();
1339  application.Render();
1340 
1341  // Test effects of Constraint.
1343 
1345  END_TEST;
1346 }
1347 
1349 {
1350  TestApplication application;
1351  tet_infoline( "Testing Dali::Internal::CameraActor::GetSceneObjectAnimatableProperty()" );
1352 
1354  Actor actor = Actor::New();
1355  actor.SetSize( 100.0f, 100.0f );
1356  Stage::GetCurrent().Add( actor );
1357 
1358  Constraint constraint = Constraint::New<Dali::Vector3>( actor, Actor::Property::POSITION, EqualToConstraint() );
1359  constraint.AddSource( Source( camera, Actor::Property::POSITION ) );
1360  constraint.Apply();
1361 
1362  camera.SetPosition( 100.0f, 200.0f, 300.0f );
1363  application.SendNotification();
1364  application.Render();
1365 
1366  DALI_TEST_EQUALS( actor.GetCurrentPosition(), Vector3( 100.0f, 200.0f, 300.0f ), TEST_LOCATION);
1367  END_TEST;
1368 }
1369 
1371 {
1372  TestApplication application;
1374 
1375  Actor basicActor = Actor::New();
1376  Property::IndexContainer indices;
1377  camera.GetPropertyIndices( indices );
1378  DALI_TEST_CHECK( indices.Size() > basicActor.GetPropertyCount() );
1379  DALI_TEST_EQUALS( indices.Size(), camera.GetPropertyCount(), TEST_LOCATION );
1380  END_TEST;
1381 }
1382 
1384 {
1385  TestApplication application;
1386  Stage stage = Stage::GetCurrent();
1387  Vector2 stageSize = stage.GetSize();
1388 
1389  CameraActor freeLookCameraActor = CameraActor::New( stageSize );
1390  freeLookCameraActor.SetParentOrigin( ParentOrigin::CENTER );
1391  freeLookCameraActor.SetType( Camera::FREE_LOOK );
1392 
1393  Vector3 targetPosition( 30.0f, 240.0f, -256.0f );
1394  Actor target = Actor::New();
1396  target.SetPosition( targetPosition );
1397 
1398  Constraint cameraOrientationConstraint = Constraint::New<Quaternion> ( freeLookCameraActor, Actor::Property::ORIENTATION, &LookAt );
1399  cameraOrientationConstraint.AddSource( Source( target, Actor::Property::WORLD_POSITION ) );
1400  cameraOrientationConstraint.AddSource( Source( freeLookCameraActor, Actor::Property::WORLD_POSITION ) );
1401  cameraOrientationConstraint.AddSource( Source( target, Actor::Property::WORLD_ORIENTATION ) );
1402  cameraOrientationConstraint.Apply();
1403 
1404  CameraActor lookAtCameraActor = CameraActor::New( stageSize );
1405  lookAtCameraActor.SetType( Camera::LOOK_AT_TARGET );
1406  lookAtCameraActor.SetTargetPosition( targetPosition );
1407  lookAtCameraActor.SetParentOrigin( ParentOrigin::CENTER );
1408 
1409  stage.Add( target );
1410  stage.Add( freeLookCameraActor );
1411  stage.Add( lookAtCameraActor );
1412 
1413  // Create an arbitrary vector
1414  for( float x=-1.0f; x<=1.0f; x+=0.1f )
1415  {
1416  for( float y=-1.0f; y<1.0f; y+=0.1f )
1417  {
1418  for( float z=-1.0f; z<1.0f; z+=0.1f )
1419  {
1420  Vector3 position( x, y, z );
1421  position.Normalize();
1422  position *= 200.0f;
1423 
1424  freeLookCameraActor.SetPosition( position );
1425  lookAtCameraActor.SetPosition( position );
1426 
1427  application.SendNotification();
1428  application.Render();
1429  application.SendNotification();
1430  application.Render();
1431  Matrix freeLookViewMatrix;
1432  Matrix lookAtViewMatrix;
1433  freeLookCameraActor.GetProperty( CameraActor::CameraActor::Property::VIEW_MATRIX ).Get( freeLookViewMatrix );
1434  lookAtCameraActor.GetProperty( CameraActor::CameraActor::Property::VIEW_MATRIX ).Get( lookAtViewMatrix );
1435 
1436  DALI_TEST_EQUALS( freeLookViewMatrix, lookAtViewMatrix, 0.01, TEST_LOCATION );
1437  }
1438  }
1439  }
1440  END_TEST;
1441 }
1442 
1444 {
1445  TestApplication application;
1446  Stage stage = Stage::GetCurrent();
1447  Vector2 stageSize = stage.GetSize();
1448 
1449  CameraActor freeLookCameraActor = CameraActor::New( stageSize );
1450  freeLookCameraActor.SetParentOrigin( ParentOrigin::CENTER );
1451  freeLookCameraActor.SetType( Camera::FREE_LOOK );
1452 
1453  Vector3 targetPosition( 30.0f, 240.0f, -256.0f );
1454  Actor target = Actor::New();
1456  target.SetPosition( targetPosition );
1457 
1458  Constraint cameraOrientationConstraint = Constraint::New<Quaternion> ( freeLookCameraActor, Actor::Property::ORIENTATION, &LookAt );
1459  cameraOrientationConstraint.AddSource( Source( target, Actor::Property::WORLD_POSITION ) );
1460  cameraOrientationConstraint.AddSource( Source( freeLookCameraActor, Actor::Property::WORLD_POSITION ) );
1461  cameraOrientationConstraint.AddSource( Source( target, Actor::Property::WORLD_ORIENTATION ) );
1462  cameraOrientationConstraint.Apply();
1463 
1464  CameraActor lookAtCameraActor = CameraActor::New( stageSize );
1465  lookAtCameraActor.SetType( Camera::LOOK_AT_TARGET );
1466  lookAtCameraActor.SetTargetPosition( targetPosition );
1467  lookAtCameraActor.SetParentOrigin( ParentOrigin::CENTER );
1468 
1469  stage.Add( target );
1470  stage.Add( freeLookCameraActor );
1471  stage.Add( lookAtCameraActor );
1472 
1473  // Create an arbitrary vector
1474  for( float x=-1.0f; x<=1.0f; x+=0.1f )
1475  {
1476  for( float y=-1.0f; y<1.0f; y+=0.1f )
1477  {
1478  for( float z=-1.0f; z<1.0f; z+=0.1f )
1479  {
1480  Vector3 position( x, y, z );
1481  position.Normalize();
1482  position *= 200.0f;
1483 
1484  freeLookCameraActor.SetPosition( position );
1485  lookAtCameraActor.SetPosition( position );
1486 
1487  application.SendNotification();
1488  application.Render();
1489  application.SendNotification();
1490  application.Render();
1491  Matrix freeLookViewMatrix;
1492  Matrix lookAtViewMatrix;
1493  freeLookCameraActor.GetProperty( CameraActor::CameraActor::Property::VIEW_MATRIX ).Get( freeLookViewMatrix );
1494  lookAtCameraActor.GetProperty( CameraActor::CameraActor::Property::VIEW_MATRIX ).Get( lookAtViewMatrix );
1495 
1496  Matrix freeLookWorld = freeLookCameraActor.GetCurrentWorldMatrix();
1497 
1498  Matrix freeLookTest( false );
1499  Matrix::Multiply( freeLookTest, freeLookViewMatrix, freeLookWorld );
1500  DALI_TEST_EQUALS( freeLookTest, Matrix::IDENTITY, 0.01f, TEST_LOCATION );
1501 
1502  DALI_TEST_EQUALS( freeLookViewMatrix, lookAtViewMatrix, 0.01, TEST_LOCATION );
1503  }
1504  }
1505  }
1506  END_TEST;
1507 }
1508 
1510 {
1511  TestApplication application;
1512  Stage stage = Stage::GetCurrent();
1513  Vector2 stageSize = stage.GetSize();
1514 
1515  Vector3 targetPosition( Vector3::ZERO );
1516  Vector3 cameraOffset( 0.0f, 0.0f, 100.0f );
1517 
1518  CameraActor freeLookCameraActor = CameraActor::New( stageSize );
1519  freeLookCameraActor.SetType( Camera::FREE_LOOK );
1520  freeLookCameraActor.SetParentOrigin( ParentOrigin::CENTER );
1521 
1522  Quaternion cameraOrientation( Radian( Degree( 180.0f ) ), Vector3::YAXIS );
1523  freeLookCameraActor.SetPosition( cameraOffset );
1524  freeLookCameraActor.SetOrientation( cameraOrientation );
1525 
1526  Actor cameraAnchor = Actor::New();
1527  cameraAnchor.Add( freeLookCameraActor );
1528  stage.Add( cameraAnchor );
1529 
1530  for( float angle = 1.0f; angle <= 180.0f; angle += 1.0f )
1531  {
1532  Quaternion rotation( Radian( Degree( angle ) ), Vector3::YAXIS );
1533 
1534  freeLookCameraActor.SetPosition( rotation.Rotate( cameraOffset ) );
1535  cameraAnchor.SetOrientation( rotation );
1536 
1537  application.SendNotification();
1538  application.Render();
1539  application.SendNotification();
1540  application.Render();
1541 
1542  Matrix freeLookViewMatrix;
1543  freeLookCameraActor.GetProperty( CameraActor::CameraActor::Property::VIEW_MATRIX ).Get( freeLookViewMatrix );
1544 
1545  Matrix freeLookWorld = freeLookCameraActor.GetCurrentWorldMatrix();
1546 
1547  Matrix freeLookTest( false );
1548  Matrix::Multiply( freeLookTest, freeLookViewMatrix, freeLookWorld );
1549  DALI_TEST_EQUALS( freeLookTest, Matrix::IDENTITY, 0.01f, TEST_LOCATION );
1550  }
1551  END_TEST;
1552 }
Dali Docs Home
Read more about Dali