[Tizen] Add screen and client rotation itself function
[platform/core/uifw/dali-core.git] / automated-tests / src / dali / utc-Dali-Matrix.cpp
1 /*
2  * Copyright (c) 2019 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 #include <sstream>
20
21 #include <stdlib.h>
22 #include <dali/public-api/dali-core.h>
23 #include <dali-test-suite-utils.h>
24
25 using namespace Dali;
26
27
28 void utc_dali_matrix_startup(void)
29 {
30   test_return_value = TET_UNDEF;
31 }
32
33 void utc_dali_matrix_cleanup(void)
34 {
35   test_return_value = TET_PASS;
36 }
37
38
39 int UtcDaliMatrixConstructor01P(void)
40 {
41   // State of memory cannot be guaranteed, so use
42   // a buffer in a known state to check for changes
43   char buffer[sizeof(Matrix)];
44
45   memset(buffer, 1, sizeof(Matrix));
46
47   Matrix* m2 = new(&buffer) Matrix(false);
48   bool initialisation_occured = false;
49   {
50     float* els = m2->AsFloat();
51     for(size_t idx=0; idx<16; ++idx, ++els)
52     {
53       if(*els == 0.0f)
54         initialisation_occured = true;
55     }
56   }
57
58   DALI_TEST_EQUALS(initialisation_occured, false, TEST_LOCATION);
59
60   END_TEST;
61 }
62
63 int UtcDaliMatrixConstructor02P(void)
64 {
65   float r[] = { 1.0f, 2.0f, 3.0f, 4.0f, 1.0f, 2.0f, 3.0f, 4.0f, 1.0f, 2.0f, 3.0f, 4.0f, 1.0f, 2.0f, 3.0f, 4.0f};
66   Matrix m(r);
67
68   float* els = m.AsFloat();
69   float* init = r;
70   bool initialised = true;
71   for(size_t idx=0; idx<16; ++idx, ++els, ++init)
72   {
73     if(*els != *init)
74       initialised = false;
75   }
76   DALI_TEST_EQUALS(initialised, true, TEST_LOCATION);
77
78   END_TEST;
79 }
80
81 int UtcDaliMatrixConstructor03P(void)
82 {
83   float r[] = { 1.0f, 2.0f, 3.0f, 4.0f, 1.0f, 2.0f, 3.0f, 4.0f, 1.0f, 2.0f, 3.0f, 4.0f, 1.0f, 2.0f, 3.0f, 4.0f};
84
85   Matrix ma(r);
86   Matrix mb(ma);
87
88   float* els = ma.AsFloat();
89   float* init = mb.AsFloat();
90   bool initialised = true;
91   for(size_t idx=0; idx<16; ++idx, ++els, ++init)
92   {
93     if(*els != *init)
94       initialised = false;
95   }
96   DALI_TEST_EQUALS(initialised, true, TEST_LOCATION);
97
98   END_TEST;
99 }
100
101 int UtcDaliMatrixConstructor04P(void)
102 {
103   Quaternion q(Quaternion::IDENTITY);
104   Matrix m(q);
105   DALI_TEST_EQUALS(Matrix(Matrix::IDENTITY), m, 0.001, TEST_LOCATION);
106   END_TEST;
107 }
108
109 int UtcDaliMatrixAssignP(void)
110 {
111   Matrix a(Matrix::IDENTITY);
112   Matrix b = a;
113   DALI_TEST_EQUALS(a, b, 0.001, TEST_LOCATION);
114   END_TEST;
115 }
116
117 int UtcDaliMatrixAssign02P(void)
118 {
119   Matrix a(Matrix::IDENTITY);
120   a = a; // self assign does the do nothing branch
121   DALI_TEST_EQUALS(Matrix(Matrix::IDENTITY), a, 0.001, TEST_LOCATION);
122   END_TEST;
123 }
124
125 int UtcDaliMatrixSetIdentityP(void)
126 {
127   float els[] = { 0.0f,  1.0f,  2.0f,  3.0f,
128                   4.0f,  5.0f,  6.0f,  7.0f,
129                   8.0f,  9.0f, 10.0f, 11.0f,
130                   12.0f, 13.0f, 14.0f, 15.0f };
131   Matrix m(els);
132   m.SetIdentity();
133
134   DALI_TEST_EQUALS(m, Matrix::IDENTITY, 0.001f, TEST_LOCATION);
135   END_TEST;
136 }
137
138 int UtcDaliMatrixSetIdentityAndScaleP(void)
139 {
140   float els[] = { 0.0f,  1.0f,  2.0f,  3.0f,
141                   4.0f,  5.0f,  6.0f,  7.0f,
142                   8.0f,  9.0f, 10.0f, 11.0f,
143                   12.0f, 13.0f, 14.0f, 15.0f };
144   Matrix m(els);
145   m.SetIdentityAndScale(Vector3(4.0f, 4.0f, 4.0f));
146
147   float els2[] = { 4.0f, 0.0f, 0.0f, 0.0f,
148                    0.0f, 4.0f, 0.0f, 0.0f,
149                    0.0f, 0.0f, 4.0f, 0.0f,
150                    0.0f, 0.0f, 0.0f, 1.0f };
151   Matrix r(els2);
152
153   DALI_TEST_EQUALS(m, r, 0.001f, TEST_LOCATION);
154   END_TEST;
155 }
156
157 int UtcDaliMatrixInvertTransformP(void)
158 {
159   for (int i=0;i<1000;++i)
160   {
161     float f = i;
162     Vector3 axis(cosf(f*0.001f), cosf(f*0.02f), cosf(f*0.03f));
163     axis.Normalize();
164     Vector3 center(f, cosf(f) * 100.0f, cosf(f*0.5f) * 50.0f);
165
166     Matrix m0;
167     m0.SetIdentity();
168     m0.SetTransformComponents( Vector3::ONE, Quaternion(Radian(1.0f), axis), center );
169
170     Matrix m1;
171     m0.InvertTransform(m1);
172
173     Matrix m2( false );
174     Matrix::Multiply( m2, m0, m1 );
175
176     DALI_TEST_EQUALS(m2, Matrix::IDENTITY, 0.001f, TEST_LOCATION);
177   }
178   END_TEST;
179 }
180
181 int UtcDaliMatrixInvertTransformN(void)
182 {
183   std::string exceptionString( "EqualsZero( mMatrix[3] ) && EqualsZero( mMatrix[7] ) && EqualsZero( mMatrix[11] ) && Equals( mMatrix[15], 1.0f" );
184   try
185   {
186     float els[] = { 0.0f,  1.0f,  2.0f,  3.0f,
187                     4.0f,  5.0f,  6.0f,  7.0f,
188                     8.0f,  9.0f, 10.0f, 11.0f,
189                     12.0f, 13.0f, 14.0f, 15.0f };
190     Matrix m(els);
191
192     Matrix it;
193     m.InvertTransform(it);
194     tet_result(TET_FAIL);
195   }
196   catch (Dali::DaliException& e)
197   {
198     DALI_TEST_PRINT_ASSERT( e );
199     DALI_TEST_ASSERT( e, exceptionString, TEST_LOCATION );
200   }
201
202   try
203   {
204     float els[] = { 0.0f,  1.0f,  2.0f,  0.0f,
205                     4.0f,  5.0f,  6.0f,  7.0f,
206                     8.0f,  9.0f, 10.0f, 11.0f,
207                     12.0f, 13.0f, 14.0f, 15.0f };
208     Matrix m(els);
209
210     Matrix it;
211     m.InvertTransform(it);
212     tet_result(TET_FAIL);
213   }
214   catch (Dali::DaliException& e)
215   {
216     DALI_TEST_PRINT_ASSERT( e );
217     DALI_TEST_ASSERT( e, exceptionString, TEST_LOCATION );
218   }
219
220   try
221   {
222     float els[] = { 0.0f,  1.0f,  2.0f,  0.0f,
223                     4.0f,  5.0f,  6.0f,  0.0f,
224                     8.0f,  9.0f, 10.0f, 11.0f,
225                     12.0f, 13.0f, 14.0f, 15.0f };
226     Matrix m(els);
227
228     Matrix it;
229     m.InvertTransform(it);
230     tet_result(TET_FAIL);
231   }
232   catch (Dali::DaliException& e)
233   {
234     DALI_TEST_PRINT_ASSERT( e );
235     DALI_TEST_ASSERT( e, exceptionString, TEST_LOCATION );
236   }
237
238   try
239   {
240     float els[] = { 0.0f,  1.0f,  2.0f,  0.0f,
241                     4.0f,  5.0f,  6.0f,  0.0f,
242                     8.0f,  9.0f, 10.0f,  0.0f,
243                     12.0f, 13.0f, 14.0f, 15.0f };
244     Matrix m(els);
245
246     Matrix it;
247     m.InvertTransform(it);
248     tet_result(TET_FAIL);
249   }
250   catch (Dali::DaliException& e)
251   {
252     DALI_TEST_PRINT_ASSERT( e );
253     DALI_TEST_ASSERT( e, exceptionString, TEST_LOCATION );
254   }
255   END_TEST;
256 }
257
258 int UtcDaliMatrixInvert01P(void)
259 {
260   // We're going to invert a whole load of different matrices to make sure we don't
261   // fail on particular orientations.
262   for (int i=0;i<1000;++i)
263   {
264     float f = i;
265     Vector3 axis(cosf(f*0.001f), cosf(f*0.02f), cosf(f*0.03f));
266     axis.Normalize();
267     Vector3 center(f, cosf(f) * 100.0f, cosf(f*0.5f) * 50.0f);
268
269     Matrix m0;
270     m0.SetIdentity();
271     m0.SetTransformComponents( Vector3::ONE, Quaternion(Radian(1.0f), axis), center );
272
273     Matrix m1(m0);
274     m1.Invert();
275
276     Matrix m2( false );
277     Matrix::Multiply( m2, m0, m1 );
278
279     DALI_TEST_EQUALS(m2, Matrix::IDENTITY, 0.001f, TEST_LOCATION);
280
281     m1.Invert();    // doube invert - should be back to m0
282
283     DALI_TEST_EQUALS(m0, m1, 0.001f, TEST_LOCATION);
284   }
285   END_TEST;
286 }
287
288 int UtcDaliMatrixInvert02P(void)
289 {
290   Matrix m1 = Matrix::IDENTITY;
291   m1.SetXAxis(Vector3(0.0f, 0.0f, 0.0f));
292   DALI_TEST_EQUALS(m1.Invert(), false, TEST_LOCATION);
293   END_TEST;
294 }
295
296 int UtcDaliMatrixTransposeP(void)
297 {
298   float floats[] =
299   {   0.0f,  1.0f,  2.0f,  3.0f,
300       4.0f,  5.0f,  6.0f,  7.0f,
301       8.0f,  9.0f, 10.0f,  11.0f,
302      12.0f, 13.0f, 14.0f,  15.0f
303   };
304
305   Matrix m(floats);
306   m.Transpose();
307
308   bool success = true;
309
310   for (int x=0;x<4;++x)
311   {
312     for (int y=0;y<4;++y)
313     {
314       success &= (m.AsFloat()[x+y*4] == floats[x*4+y]);
315     }
316   }
317
318   DALI_TEST_CHECK(success);
319   END_TEST;
320 }
321
322 int UtcDaliMatrixGetXAxisP(void)
323 {
324   float els[] = { 0.0f,  1.0f,  2.0f,  3.0f,
325                   4.0f,  5.0f,  6.0f,  7.0f,
326                   8.0f,  9.0f, 10.0f, 11.0f,
327                   12.0f, 13.0f, 14.0f, 15.0f };
328   Matrix m(els);
329
330   DALI_TEST_CHECK(m.GetXAxis() == Vector3(0.0f,  1.0f,  2.0f));
331   END_TEST;
332 }
333
334 int UtcDaliMatrixGetYAxisP(void)
335 {
336   float els[] = { 0.0f,  1.0f,  2.0f,  3.0f,
337                   4.0f,  5.0f,  6.0f,  7.0f,
338                   8.0f,  9.0f, 10.0f, 11.0f,
339                   12.0f, 13.0f, 14.0f, 15.0f };
340   Matrix m(els);
341
342   DALI_TEST_CHECK(m.GetYAxis() == Vector3(4.0f,  5.0f,  6.0f));
343   END_TEST;
344 }
345
346 int UtcDaliMatrixGetZAxisP(void)
347 {
348   float els[] = { 0.0f,  1.0f,  2.0f,  3.0f,
349                   4.0f,  5.0f,  6.0f,  7.0f,
350                   8.0f,  9.0f, 10.0f, 11.0f,
351                   12.0f, 13.0f, 14.0f, 15.0f };
352   Matrix m(els);
353
354   DALI_TEST_CHECK(m.GetZAxis() == Vector3(8.0f,  9.0f, 10.0f));
355   END_TEST;
356 }
357
358 int UtcDaliMatrixSetXAxisP(void)
359 {
360   Matrix m;
361   Vector3 v(2.0f, 3.0f, 4.0f);
362   m.SetXAxis(v);
363
364   DALI_TEST_CHECK(m.GetXAxis() == v);
365   END_TEST;
366 }
367
368 int UtcDaliMatrixSetYAxisP(void)
369 {
370   Matrix m;
371   Vector3 v(2.0f, 3.0f, 4.0f);
372   m.SetYAxis(v);
373
374   DALI_TEST_CHECK(m.GetYAxis() == v);
375   END_TEST;
376 }
377
378 int UtcDaliMatrixSetZAxisP(void)
379 {
380   Matrix m;
381   Vector3 v(2.0f, 3.0f, 4.0f);
382   m.SetZAxis(v);
383
384   DALI_TEST_CHECK(m.GetZAxis() == v);
385   END_TEST;
386 }
387
388 int UtcDaliMatrixGetTranslationP(void)
389 {
390   float els[] = { 0.0f,  1.0f,  2.0f,  3.0f,
391                   4.0f,  5.0f,  6.0f,  7.0f,
392                   8.0f,  9.0f, 10.0f, 11.0f,
393                   12.0f, 13.0f, 14.0f, 15.0f };
394   Matrix m(els);
395
396   DALI_TEST_EQUALS(m.GetTranslation(), Vector4(12.0f, 13.0f, 14.0f, 15.0f), TEST_LOCATION);
397   END_TEST;
398 }
399
400 int UtcDaliMatrixGetTranslation3P(void)
401 {
402   float els[] = { 0.0f,  1.0f,  2.0f,  3.0f,
403                   4.0f,  5.0f,  6.0f,  7.0f,
404                   8.0f,  9.0f, 10.0f, 11.0f,
405                   12.0f, 13.0f, 14.0f, 15.0f };
406   Matrix m(els);
407
408   DALI_TEST_EQUALS(m.GetTranslation3(), Vector3(12.0f, 13.0f, 14.0f), TEST_LOCATION);
409   END_TEST;
410 }
411
412 int UtcDaliMatrixSetTranslationP(void)
413 {
414   Matrix m;
415   Vector4 v(2.0f, 3.0f, 4.0f, 5.0f);
416   m.SetTranslation(v);
417
418   DALI_TEST_CHECK(m.GetTranslation() == v);
419   END_TEST;
420 }
421
422 int UtcDaliMatrixSetTranslation3P(void)
423 {
424   Matrix m;
425   Vector3 v(2.0f, 3.0f, 4.0f);
426   m.SetTranslation(v);
427
428   DALI_TEST_CHECK(m.GetTranslation3() == v);
429   END_TEST;
430 }
431
432 int UtcDaliMatrixOrthoNormalize0P(void)
433 {
434   // OrthoNormalise fixes floating point errors from matrix rotations
435   Matrix m;
436   m.SetIdentity();
437
438   for (int i=0;i<1000;++i)
439   {
440     float f = i;
441     Vector3 axis(cosf(f*0.001f), cosf(f*0.02f), cosf(f*0.03f));
442     axis.Normalize();
443
444     m.SetTransformComponents( Vector3::ONE, Quaternion(Radian(1.0f), axis), Vector3::ZERO );
445     m.OrthoNormalize();
446   }
447
448   bool success = true;
449   success &= fabsf(m.GetXAxis().Dot(m.GetYAxis())) < 0.001f;
450   success &= fabsf(m.GetYAxis().Dot(m.GetXAxis())) < 0.001f;
451   success &= fabsf(m.GetZAxis().Dot(m.GetYAxis())) < 0.001f;
452
453   success &= fabsf(m.GetXAxis().Length() - 1.0f) < 0.001f;
454   success &= fabsf(m.GetYAxis().Length() - 1.0f) < 0.001f;
455   success &= fabsf(m.GetZAxis().Length() - 1.0f) < 0.001f;
456
457   DALI_TEST_CHECK(success);
458   END_TEST;
459 }
460
461 int UtcDaliMatrixOrthoNormalize1P(void)
462 {
463   // OrthoNormalize is not flipping the axes and is maintaining the translation
464   for (int i=0;i<1000;++i)
465   {
466     float f = i;
467     Vector3 axis(cosf(f*0.001f), cosf(f*0.02f), cosf(f*0.03f));
468     axis.Normalize();
469     Vector3 center(10.0f, 15.0f, 5.0f);
470
471     Matrix m0;
472     m0.SetIdentity();
473     m0.SetTransformComponents( Vector3::ONE, Quaternion(Radian(1.0f), axis), center );
474
475     Matrix m1(m0);
476     m1.OrthoNormalize();
477
478     DALI_TEST_EQUALS(m0.GetXAxis(), m1.GetXAxis(), 0.001f, TEST_LOCATION);
479     DALI_TEST_EQUALS(m0.GetYAxis(), m1.GetYAxis(), 0.001f, TEST_LOCATION);
480     DALI_TEST_EQUALS(m0.GetZAxis(), m1.GetZAxis(), 0.001f, TEST_LOCATION);
481     DALI_TEST_EQUALS(m0.GetTranslation(), m1.GetTranslation(), 0.001f, TEST_LOCATION);
482   }
483   END_TEST;
484 }
485
486 int UtcDaliMatrixConstAsFloatP(void)
487 {
488   float r[] = { 1.0f, 2.0f, 3.0f, 4.0f, 1.0f, 2.0f, 3.0f, 4.0f, 1.0f, 2.0f, 3.0f, 4.0f, 1.0f, 2.0f, 3.0f, 4.0f};
489   const Matrix m(r);
490
491   const float* els = m.AsFloat();
492   const float* init = r;
493   bool initialised = true;
494   for(size_t idx=0; idx<16; ++idx, ++els, ++init)
495   {
496     if(*els != *init)
497       initialised = false;
498   }
499   DALI_TEST_EQUALS(initialised, true, TEST_LOCATION);
500
501
502   END_TEST;
503 }
504
505 int UtcDaliMatrixAsFloatP(void)
506 {
507   float r[] = { 1.0f, 2.0f, 3.0f, 4.0f, 1.0f, 2.0f, 3.0f, 4.0f, 1.0f, 2.0f, 3.0f, 4.0f, 1.0f, 2.0f, 3.0f, 4.0f};
508   Matrix m(r);
509
510   float* els = m.AsFloat();
511   float* init = r;
512   bool initialised = true;
513   for(size_t idx=0; idx<16; ++idx, ++els, ++init)
514   {
515     if(*els != *init)
516       initialised = false;
517   }
518   DALI_TEST_EQUALS(initialised, true, TEST_LOCATION);
519
520
521   END_TEST;
522 }
523
524 int UtcDaliMatrixMultiplyP(void)
525 {
526   Matrix m1 = Matrix::IDENTITY;
527
528   float els[] = { 1.0f, 0.0f,    0.0f,   0.0f,
529                   0.0f, 0.707f, 0.707f, 0.0f,
530                   0.0f, -0.707f,  0.707f, 0.0f,
531                   0.0f, 0.0f,    0.0f,   1.0f };
532   Matrix result(els);
533
534   Quaternion q(Radian(Degree(45.0f)), Vector3::XAXIS);
535   Matrix m2(false);
536   Matrix::Multiply(m2, m1, q);
537
538   DALI_TEST_EQUALS(m2, result, 0.01f, TEST_LOCATION);
539   END_TEST;
540 }
541
542 int UtcDaliMatrixOperatorMultiply01P(void)
543 {
544   Vector4 v1(2.0f, 5.0f, 4.0f, 0.0f);
545
546   float els[] = {2.0f, 0.0f, 0.0f, 0.0f,
547                  0.0f, 3.0f, 0.0f, 0.0f,
548                  0.0f, 0.0f, 4.0f, 0.0f,
549                  0.0f, 0.0f, 0.0f, 1.0f };
550   Matrix m1(els);
551
552   Vector4 v2 = m1 * v1;
553   Vector4 r1(4.0f, 15.0f, 16.0f, 0.0f);
554   DALI_TEST_EQUALS(v2, r1, 0.01f, TEST_LOCATION);
555   END_TEST;
556 }
557
558 int UtcDaliMatrixOperatorMultiply02P(void)
559 {
560   TestApplication application;
561
562   Vector3 position ( 30.f, 40.f, 50.f);
563
564   Matrix m1(false);
565   m1.SetIdentity();
566   m1.SetTranslation(-position);
567
568   Vector4 positionV4(position);
569   positionV4.w=1.0f;
570   Vector4 output = m1 * positionV4;
571
572   output.w = 0.0f;
573   DALI_TEST_EQUALS(output, Vector4::ZERO, 0.01f, TEST_LOCATION);
574   END_TEST;
575 }
576
577 int UtcDaliMatrixOperatorEqualsP(void)
578 {
579   Matrix m1 = Matrix::IDENTITY;
580
581   float els[] = { 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f};
582   Matrix r2(els);
583   DALI_TEST_EQUALS(m1 == r2, true, TEST_LOCATION);
584
585   float *f = m1.AsFloat();
586   for(size_t i=0; i<16; i++)
587   {
588     f[15-i] = 1.2f;
589     DALI_TEST_EQUALS(m1 == r2, false, TEST_LOCATION);
590   }
591   END_TEST;
592 }
593
594 int UtcDaliMatrixOperatorNotEqualsP(void)
595 {
596   Matrix m1 = Matrix::IDENTITY;
597   float els[] = {2.0f, 0.0f, 0.0f, 0.0f,
598                  0.0f, 3.0f, 0.0f, 0.0f,
599                  0.0f, 0.0f, 4.0f, 0.0f,
600                  0.0f, 0.0f, 0.0f, 1.0f };
601   Matrix r1(els);
602
603   DALI_TEST_CHECK(m1 != r1);
604   DALI_TEST_CHECK(!(m1 != m1));
605   END_TEST;
606 }
607
608 int UtcDaliMatrixSetTransformComponents01P(void)
609 {
610   // Create an arbitrary vector
611   for( float x=-1.0f; x<=1.0f; x+=0.1f )
612   {
613     for( float y=-1.0f; y<1.0f; y+=0.1f )
614     {
615       for( float z=-1.0f; z<1.0f; z+=0.1f )
616       {
617         Vector3 vForward(x, y, z);
618         vForward.Normalize();
619
620         for( float angle = 5.0f; angle <= 360.0f; angle += 15.0f)
621         {
622           Quaternion rotation1(Radian(Degree(angle)), vForward);
623
624           Matrix m1(rotation1);
625           Matrix result1(false);
626           Vector3 vForward3(vForward.x, vForward.y, vForward.z);
627           result1.SetTransformComponents( Vector3::ONE, Quaternion(Radian(Degree(angle)), vForward3), Vector3::ZERO );
628
629           DALI_TEST_EQUALS(m1, result1, 0.001, TEST_LOCATION);
630
631           Matrix m2(false);
632           m2.SetTransformComponents(vForward, Quaternion::IDENTITY, Vector3::ZERO);
633
634           Matrix result2a(Matrix::IDENTITY);
635           result2a.SetXAxis(result2a.GetXAxis() * vForward[0]);
636           result2a.SetYAxis(result2a.GetYAxis() * vForward[1]);
637           result2a.SetZAxis(result2a.GetZAxis() * vForward[2]);
638
639           DALI_TEST_EQUALS(m2, result2a, 0.001, TEST_LOCATION);
640
641           Matrix m3(false);
642           m3.SetTransformComponents(vForward, rotation1, Vector3::ZERO);
643
644           Matrix result3(Matrix::IDENTITY);
645           result3.SetXAxis(result3.GetXAxis() * vForward[0]);
646           result3.SetYAxis(result3.GetYAxis() * vForward[1]);
647           result3.SetZAxis(result3.GetZAxis() * vForward[2]);
648
649           Matrix::Multiply(result3, result3, m1);
650           DALI_TEST_EQUALS(m3, result3, 0.001, TEST_LOCATION);
651         }
652       }
653     }
654   }
655   END_TEST;
656 }
657
658 int UtcDaliMatrixSetInverseTransformComponent01P(void)
659 {
660   // Create an arbitrary vector
661   for( float x=-1.0f; x<=1.0f; x+=0.1f )
662   {
663     for( float y=-1.0f; y<1.0f; y+=0.1f )
664     {
665       for( float z=-1.0f; z<1.0f; z+=0.1f )
666       {
667         Vector3 vForward(x, y, z);
668         vForward.Normalize();
669
670         {
671           Quaternion rotation1(Quaternion::IDENTITY); // test no rotation branch
672           Vector3 scale1(2.0f, 3.0f, 4.0f);
673           Vector3 position1(1.0f, 2.0f, 3.0f);
674
675           Matrix m1(false);
676           m1.SetTransformComponents(scale1, rotation1, position1);
677
678           Matrix m2(false);
679           m2.SetInverseTransformComponents(scale1, rotation1, position1);
680
681           Matrix result;
682           Matrix::Multiply(result, m1, m2);
683
684           DALI_TEST_EQUALS(result, Matrix::IDENTITY, 0.001, TEST_LOCATION);
685         }
686       }
687     }
688   }
689   END_TEST;
690 }
691
692 int UtcDaliMatrixSetInverseTransformComponent02P(void)
693 {
694   // Create an arbitrary vector
695   for( float x=-1.0f; x<=1.0f; x+=0.1f )
696   {
697     for( float y=-1.0f; y<1.0f; y+=0.1f )
698     {
699       for( float z=-1.0f; z<1.0f; z+=0.1f )
700       {
701         Vector3 vForward(x, y, z);
702         vForward.Normalize();
703
704         for( float angle = 5.0f; angle <= 360.0f; angle += 15.0f)
705         {
706           Quaternion rotation1(Radian(Degree(angle)), vForward);
707           Matrix rotationMatrix(rotation1);   // TEST RELIES ON THIS METHOD WORKING!!!
708
709           Vector3 position1(5.0f, -6.0f, 7.0f);
710
711           Matrix m1(false);
712           m1.SetTransformComponents( Vector3::ONE, rotation1, position1 );
713
714           Matrix m2(false);
715           m2.SetInverseTransformComponents( rotationMatrix.GetXAxis(),
716                                             rotationMatrix.GetYAxis(),
717                                             rotationMatrix.GetZAxis(),
718                                             position1 );
719
720           Matrix result;
721           Matrix::Multiply(result, m1, m2);
722
723           DALI_TEST_EQUALS(result, Matrix::IDENTITY, 0.001, TEST_LOCATION);
724         }
725       }
726     }
727   }
728   END_TEST;
729 }
730
731 int UtcDaliMatrixGetTransformComponents01P(void)
732 {
733   Matrix m2(Matrix::IDENTITY.AsFloat());
734   Vector3 pos2;
735   Vector3 scale2;
736   Quaternion q2;
737   m2.GetTransformComponents(pos2, q2, scale2);
738   DALI_TEST_EQUALS(Vector3(0.0f, 0.0f, 0.0f), pos2, 0.001, TEST_LOCATION);
739   DALI_TEST_EQUALS(Vector3(1.0f, 1.0f, 1.0f), scale2, 0.001, TEST_LOCATION);
740   DALI_TEST_EQUALS(Quaternion(), q2, 0.001, TEST_LOCATION);
741   END_TEST;
742 }
743
744
745 int UtcDaliMatrixGetTransformComponents02P(void)
746 {
747   // Create an arbitrary vector
748   for( float x=-1.0f; x<=1.0f; x+=0.1f )
749   {
750     for( float y=-1.0f; y<1.0f; y+=0.1f )
751     {
752       for( float z=-1.0f; z<1.0f; z+=0.1f )
753       {
754         Vector3 vForward(x, y, z);
755         vForward.Normalize();
756
757         for( float angle = 5.0f; angle <= 360.0f; angle += 15.0f)
758         {
759           Quaternion rotation1(Radian(Degree(angle)), vForward);
760           Vector3 scale1(2.0f, 3.0f, 4.0f);
761           Vector3 position1(1.0f, 2.0f, 3.0f);
762
763           Matrix m1(false);
764           m1.SetTransformComponents(scale1, rotation1, position1);
765
766           Vector3 position2;
767           Quaternion rotation2;
768           Vector3 scale2;
769           m1.GetTransformComponents(position2, rotation2, scale2);
770
771           DALI_TEST_EQUALS(position1, position2, 0.001, TEST_LOCATION);
772           DALI_TEST_EQUALS(scale1, scale2, 0.001, TEST_LOCATION);
773           DALI_TEST_EQUALS(rotation1, rotation2, 0.001, TEST_LOCATION);
774         }
775       }
776     }
777   }
778   END_TEST;
779 }
780
781 int UtcDaliMatrixGetTransformComponents03P(void)
782 {
783   Matrix m2; // zero branch
784   Vector3 pos2;
785   Vector3 scale2;
786   Quaternion q2;
787   m2.GetTransformComponents(pos2, q2, scale2);
788   DALI_TEST_EQUALS(Vector3(0.0f, 0.0f, 0.0f), pos2, 0.001, TEST_LOCATION);
789   DALI_TEST_EQUALS(Vector3(0.0f, 0.0f, 0.0f), scale2, 0.001, TEST_LOCATION);
790   // DALI_TEST_EQUALS(Quaternion(), q2, 0.001, TEST_LOCATION);
791   END_TEST;
792 }
793
794 int UtcDaliMatrixOStreamOperator(void)
795 {
796   std::ostringstream oss;
797
798   Matrix matrix;
799   matrix.SetIdentity();
800
801   oss << matrix;
802
803   std::string expectedOutput = "[ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 ]";
804
805   DALI_TEST_EQUALS( oss.str(), expectedOutput, TEST_LOCATION);
806   END_TEST;
807 }