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