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