2 * Copyright (c) 2022 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 #include <dali-test-suite-utils.h>
19 #include <dali/public-api/dali-core.h>
27 void utc_dali_matrix_startup(void)
29 test_return_value = TET_UNDEF;
32 void utc_dali_matrix_cleanup(void)
34 test_return_value = TET_PASS;
37 int UtcDaliMatrixConstructor01P(void)
39 // State of memory cannot be guaranteed, so use
40 // a buffer in a known state to check for changes
41 char buffer[sizeof(Matrix)];
43 memset(buffer, 1, sizeof(Matrix));
45 Matrix* m2 = new(&buffer) Matrix(false);
46 bool initialisation_occured = false;
48 float* els = m2->AsFloat();
49 for(size_t idx = 0; idx < 16; ++idx, ++els)
52 initialisation_occured = true;
56 DALI_TEST_EQUALS(initialisation_occured, false, TEST_LOCATION);
61 int UtcDaliMatrixConstructor02P(void)
63 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 float* els = m.AsFloat();
68 bool initialised = true;
69 for(size_t idx = 0; idx < 16; ++idx, ++els, ++init)
74 DALI_TEST_EQUALS(initialised, true, TEST_LOCATION);
79 int UtcDaliMatrixConstructor03P(void)
81 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};
86 float* els = ma.AsFloat();
87 float* init = mb.AsFloat();
88 bool initialised = true;
89 for(size_t idx = 0; idx < 16; ++idx, ++els, ++init)
94 DALI_TEST_EQUALS(initialised, true, TEST_LOCATION);
99 int UtcDaliMatrixConstructor04P(void)
101 Quaternion q(Quaternion::IDENTITY);
103 DALI_TEST_EQUALS(Matrix(Matrix::IDENTITY), m, 0.001, TEST_LOCATION);
107 int UtcDaliMatrixCopyConstructor(void)
109 Matrix m0(Matrix::IDENTITY);
111 DALI_TEST_EQUALS(m1, Matrix::IDENTITY, 0.001f, TEST_LOCATION);
116 int UtcDaliMatrixMoveConstructor(void)
118 Matrix m0(Matrix::IDENTITY);
119 Matrix m1 = std::move(m0);
120 DALI_TEST_EQUALS(m1, Matrix::IDENTITY, 0.001f, TEST_LOCATION);
125 int UtcDaliMatrixCopyAssignment(void)
127 Matrix m0(Matrix::IDENTITY);
130 DALI_TEST_EQUALS(m1, Matrix::IDENTITY, 0.001f, TEST_LOCATION);
135 int UtcDaliMatrixMoveAssignment(void)
137 Matrix m0(Matrix::IDENTITY);
140 DALI_TEST_EQUALS(m1, Matrix::IDENTITY, 0.001f, TEST_LOCATION);
145 int UtcDaliMatrixAssignP(void)
147 Matrix a(Matrix::IDENTITY);
149 DALI_TEST_EQUALS(a, b, 0.001, TEST_LOCATION);
153 int UtcDaliMatrixAssign02P(void)
155 Matrix a(Matrix::IDENTITY);
156 a = a; // self assign does the do nothing branch
157 DALI_TEST_EQUALS(Matrix(Matrix::IDENTITY), a, 0.001, TEST_LOCATION);
161 int UtcDaliMatrixSetIdentityP(void)
163 float els[] = {0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f, 12.0f, 13.0f, 14.0f, 15.0f};
167 DALI_TEST_EQUALS(m, Matrix::IDENTITY, 0.001f, TEST_LOCATION);
171 int UtcDaliMatrixSetIdentityAndScaleP(void)
173 float els[] = {0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f, 12.0f, 13.0f, 14.0f, 15.0f};
175 m.SetIdentityAndScale(Vector3(4.0f, 4.0f, 4.0f));
177 float els2[] = {4.0f, 0.0f, 0.0f, 0.0f, 0.0f, 4.0f, 0.0f, 0.0f, 0.0f, 0.0f, 4.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f};
180 DALI_TEST_EQUALS(m, r, 0.001f, TEST_LOCATION);
184 int UtcDaliMatrixInvertTransformP(void)
186 for(int i = 0; i < 1000; ++i)
189 Vector3 axis(cosf(f * 0.001f), cosf(f * 0.02f), cosf(f * 0.03f));
191 Vector3 center(f, cosf(f) * 100.0f, cosf(f * 0.5f) * 50.0f);
195 m0.SetTransformComponents(Vector3::ONE, Quaternion(Radian(1.0f), axis), center);
198 m0.InvertTransform(m1);
201 Matrix::Multiply(m2, m0, m1);
203 DALI_TEST_EQUALS(m2, Matrix::IDENTITY, 0.001f, TEST_LOCATION);
208 int UtcDaliMatrixInvertTransformN(void)
210 std::string exceptionString("EqualsZero(mMatrix[3]) && EqualsZero(mMatrix[7]) && EqualsZero(mMatrix[11]) && Equals(mMatrix[15], 1.0f");
213 float els[] = {0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f, 12.0f, 13.0f, 14.0f, 15.0f};
217 m.InvertTransform(it);
218 tet_result(TET_FAIL);
220 catch(Dali::DaliException& e)
222 DALI_TEST_PRINT_ASSERT(e);
223 DALI_TEST_ASSERT(e, exceptionString, TEST_LOCATION);
228 float els[] = {0.0f, 1.0f, 2.0f, 0.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f, 12.0f, 13.0f, 14.0f, 15.0f};
232 m.InvertTransform(it);
233 tet_result(TET_FAIL);
235 catch(Dali::DaliException& e)
237 DALI_TEST_PRINT_ASSERT(e);
238 DALI_TEST_ASSERT(e, exceptionString, TEST_LOCATION);
243 float els[] = {0.0f, 1.0f, 2.0f, 0.0f, 4.0f, 5.0f, 6.0f, 0.0f, 8.0f, 9.0f, 10.0f, 11.0f, 12.0f, 13.0f, 14.0f, 15.0f};
247 m.InvertTransform(it);
248 tet_result(TET_FAIL);
250 catch(Dali::DaliException& e)
252 DALI_TEST_PRINT_ASSERT(e);
253 DALI_TEST_ASSERT(e, exceptionString, TEST_LOCATION);
258 float els[] = {0.0f, 1.0f, 2.0f, 0.0f, 4.0f, 5.0f, 6.0f, 0.0f, 8.0f, 9.0f, 10.0f, 0.0f, 12.0f, 13.0f, 14.0f, 15.0f};
262 m.InvertTransform(it);
263 tet_result(TET_FAIL);
265 catch(Dali::DaliException& e)
267 DALI_TEST_PRINT_ASSERT(e);
268 DALI_TEST_ASSERT(e, exceptionString, TEST_LOCATION);
273 int UtcDaliMatrixInvert01P(void)
275 // We're going to invert a whole load of different matrices to make sure we don't
276 // fail on particular orientations.
277 for(int i = 0; i < 1000; ++i)
280 Vector3 axis(cosf(f * 0.001f), cosf(f * 0.02f), cosf(f * 0.03f));
282 Vector3 center(f, cosf(f) * 100.0f, cosf(f * 0.5f) * 50.0f);
286 m0.SetTransformComponents(Vector3::ONE, Quaternion(Radian(1.0f), axis), center);
292 Matrix::Multiply(m2, m0, m1);
294 DALI_TEST_EQUALS(m2, Matrix::IDENTITY, 0.001f, TEST_LOCATION);
296 m1.Invert(); // doube invert - should be back to m0
298 DALI_TEST_EQUALS(m0, m1, 0.001f, TEST_LOCATION);
303 int UtcDaliMatrixInvert02P(void)
305 Matrix m1 = Matrix::IDENTITY;
306 m1.SetXAxis(Vector3(0.0f, 0.0f, 0.0f));
307 DALI_TEST_EQUALS(m1.Invert(), false, TEST_LOCATION);
311 int UtcDaliMatrixTransposeP(void)
314 {0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f, 12.0f, 13.0f, 14.0f, 15.0f};
321 for(int x = 0; x < 4; ++x)
323 for(int y = 0; y < 4; ++y)
325 success &= (m.AsFloat()[x + y * 4] == floats[x * 4 + y]);
329 DALI_TEST_CHECK(success);
333 int UtcDaliMatrixGetXAxisP(void)
335 float els[] = {0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f, 12.0f, 13.0f, 14.0f, 15.0f};
338 DALI_TEST_CHECK(m.GetXAxis() == Vector3(0.0f, 1.0f, 2.0f));
342 int UtcDaliMatrixGetYAxisP(void)
344 float els[] = {0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f, 12.0f, 13.0f, 14.0f, 15.0f};
347 DALI_TEST_CHECK(m.GetYAxis() == Vector3(4.0f, 5.0f, 6.0f));
351 int UtcDaliMatrixGetZAxisP(void)
353 float els[] = {0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f, 12.0f, 13.0f, 14.0f, 15.0f};
356 DALI_TEST_CHECK(m.GetZAxis() == Vector3(8.0f, 9.0f, 10.0f));
360 int UtcDaliMatrixSetXAxisP(void)
363 Vector3 v(2.0f, 3.0f, 4.0f);
366 DALI_TEST_CHECK(m.GetXAxis() == v);
370 int UtcDaliMatrixSetYAxisP(void)
373 Vector3 v(2.0f, 3.0f, 4.0f);
376 DALI_TEST_CHECK(m.GetYAxis() == v);
380 int UtcDaliMatrixSetZAxisP(void)
383 Vector3 v(2.0f, 3.0f, 4.0f);
386 DALI_TEST_CHECK(m.GetZAxis() == v);
390 int UtcDaliMatrixGetTranslationP(void)
392 float els[] = {0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f, 12.0f, 13.0f, 14.0f, 15.0f};
395 DALI_TEST_EQUALS(m.GetTranslation(), Vector4(12.0f, 13.0f, 14.0f, 15.0f), TEST_LOCATION);
399 int UtcDaliMatrixGetTranslation3P(void)
401 float els[] = {0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f, 12.0f, 13.0f, 14.0f, 15.0f};
404 DALI_TEST_EQUALS(m.GetTranslation3(), Vector3(12.0f, 13.0f, 14.0f), TEST_LOCATION);
408 int UtcDaliMatrixSetTranslationP(void)
411 Vector4 v(2.0f, 3.0f, 4.0f, 5.0f);
414 DALI_TEST_CHECK(m.GetTranslation() == v);
418 int UtcDaliMatrixSetTranslation3P(void)
421 Vector3 v(2.0f, 3.0f, 4.0f);
424 DALI_TEST_CHECK(m.GetTranslation3() == v);
428 int UtcDaliMatrixOrthoNormalize0P(void)
430 // OrthoNormalise fixes floating point errors from matrix rotations
434 for(int i = 0; i < 1000; ++i)
437 Vector3 axis(cosf(f * 0.001f), cosf(f * 0.02f), cosf(f * 0.03f));
440 m.SetTransformComponents(Vector3::ONE, Quaternion(Radian(1.0f), axis), Vector3::ZERO);
445 success &= fabsf(m.GetXAxis().Dot(m.GetYAxis())) < 0.001f;
446 success &= fabsf(m.GetYAxis().Dot(m.GetXAxis())) < 0.001f;
447 success &= fabsf(m.GetZAxis().Dot(m.GetYAxis())) < 0.001f;
449 success &= fabsf(m.GetXAxis().Length() - 1.0f) < 0.001f;
450 success &= fabsf(m.GetYAxis().Length() - 1.0f) < 0.001f;
451 success &= fabsf(m.GetZAxis().Length() - 1.0f) < 0.001f;
453 DALI_TEST_CHECK(success);
457 int UtcDaliMatrixOrthoNormalize1P(void)
459 // OrthoNormalize is not flipping the axes and is maintaining the translation
460 for(int i = 0; i < 1000; ++i)
463 Vector3 axis(cosf(f * 0.001f), cosf(f * 0.02f), cosf(f * 0.03f));
465 Vector3 center(10.0f, 15.0f, 5.0f);
469 m0.SetTransformComponents(Vector3::ONE, Quaternion(Radian(1.0f), axis), center);
474 DALI_TEST_EQUALS(m0.GetXAxis(), m1.GetXAxis(), 0.001f, TEST_LOCATION);
475 DALI_TEST_EQUALS(m0.GetYAxis(), m1.GetYAxis(), 0.001f, TEST_LOCATION);
476 DALI_TEST_EQUALS(m0.GetZAxis(), m1.GetZAxis(), 0.001f, TEST_LOCATION);
477 DALI_TEST_EQUALS(m0.GetTranslation(), m1.GetTranslation(), 0.001f, TEST_LOCATION);
482 int UtcDaliMatrixConstAsFloatP(void)
484 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};
487 const float* els = m.AsFloat();
488 const float* init = r;
489 bool initialised = true;
490 for(size_t idx = 0; idx < 16; ++idx, ++els, ++init)
495 DALI_TEST_EQUALS(initialised, true, TEST_LOCATION);
500 int UtcDaliMatrixAsFloatP(void)
502 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};
505 float* els = m.AsFloat();
507 bool initialised = true;
508 for(size_t idx = 0; idx < 16; ++idx, ++els, ++init)
513 DALI_TEST_EQUALS(initialised, true, TEST_LOCATION);
518 int UtcDaliMatrixMultiplyP(void)
520 Matrix m1 = Matrix::IDENTITY;
522 float els[] = {1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.707f, 0.707f, 0.0f, 0.0f, -0.707f, 0.707f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f};
525 Quaternion q(Radian(Degree(45.0f)), Vector3::XAXIS);
527 Matrix::Multiply(m2, m1, q);
529 DALI_TEST_EQUALS(m2, result, 0.01f, TEST_LOCATION);
533 int UtcDaliMatrixOperatorMultiply01P(void)
535 Vector4 v1(2.0f, 5.0f, 4.0f, 0.0f);
537 float els[] = {2.0f, 0.0f, 0.0f, 0.0f, 0.0f, 3.0f, 0.0f, 0.0f, 0.0f, 0.0f, 4.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f};
540 Vector4 v2 = m1 * v1;
541 Vector4 r1(4.0f, 15.0f, 16.0f, 0.0f);
542 DALI_TEST_EQUALS(v2, r1, 0.01f, TEST_LOCATION);
546 int UtcDaliMatrixOperatorMultiply02P(void)
548 TestApplication application;
550 Vector3 position(30.f, 40.f, 50.f);
554 m1.SetTranslation(-position);
556 Vector4 positionV4(position);
558 Vector4 output = m1 * positionV4;
561 DALI_TEST_EQUALS(output, Vector4::ZERO, 0.01f, TEST_LOCATION);
565 int UtcDaliMatrixOperatorMultiply03P(void)
567 const float ll[16] = {1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f};
568 const float rr[16] = {1.0f, 5.0f, 0.0f, 0.0f, 2.0f, 6.0f, 0.0f, 0.0f, 3.0f, 7.0f, 0.0f, 0.0f, 4.0f, 8.0f, 0.0f, 0.0f};
572 const float els[16] = {26.0f, 32.0f, 38.0f, 44.0f, 32.0f, 40.0f, 48.0f, 56.0f, 38.0f, 48.0f, 58.0f, 68.0f, 44.0f, 56.0f, 68.0f, 80.0f};
575 // Get result by operator*
576 Matrix multResult = left * right;
577 DALI_TEST_EQUALS(multResult, result, 0.01f, TEST_LOCATION);
579 // Get result by Multiply API
580 Matrix::Multiply(multResult, right, left);
581 DALI_TEST_EQUALS(multResult, result, 0.01f, TEST_LOCATION);
586 int UtcDaliMatrixOperatorMultiplyAssign01P(void)
588 tet_infoline("Multiplication Assign operator\n");
589 const float ll[16] = {1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 0.0f, 0.0f, 11.0f, 12.0f, 0.0f, 0.0f};
590 const float rr[16] = {1.0f, 5.0f, 9.0f, 10.0f, 2.0f, 6.0f, 11.0f, 12.0f, 3.0f, 7.0f, 0.0f, 0.0f, 4.0f, 8.0f, 0.0f, 0.0f};
593 Matrix copyedLeft(ll);
595 const float els[16] = {217.0f, 242.0f, 38.0f, 44.0f, 263.0f, 294.0f, 48.0f, 56.0f, 38.0f, 48.0f, 58.0f, 68.0f, 44.0f, 56.0f, 68.0f, 80.0f};
598 // Get result by operator*
599 Matrix multResult = left * right;
600 DALI_TEST_EQUALS(multResult, result, 0.01f, TEST_LOCATION);
602 // Get result by operator*=
604 DALI_TEST_EQUALS(left, result, 0.01f, TEST_LOCATION);
609 int UtcDaliMatrixOperatorMultiplyAssign02P(void)
611 tet_infoline("Multiplication Assign operator with self matrix\n");
612 const float ll[16] = {1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 0.0f, 0.0f, 11.0f, 12.0f, 0.0f, 0.0f};
614 Matrix copyedLeft(ll);
616 const float els[16] = {82.0f, 92.0f, 17.0f, 20.0f, 186.0f, 212.0f, 57.0f, 68.0f, 59.0f, 78.0f, 97.0f, 116.0f, 71.0f, 94.0f, 117.0f, 140.0f};
619 // Get result by operator*
620 Matrix multResult = left * copyedLeft;
621 DALI_TEST_EQUALS(multResult, result, 0.01f, TEST_LOCATION);
623 // Get result by operator*=
625 DALI_TEST_EQUALS(left, result, 0.01f, TEST_LOCATION);
630 int UtcDaliMatrixOperatorEqualsP(void)
632 Matrix m1 = Matrix::IDENTITY;
634 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};
636 DALI_TEST_EQUALS(m1 == r2, true, TEST_LOCATION);
638 float* f = m1.AsFloat();
639 for(size_t i = 0; i < 16; i++)
642 DALI_TEST_EQUALS(m1 == r2, false, TEST_LOCATION);
647 int UtcDaliMatrixOperatorNotEqualsP(void)
649 Matrix m1 = Matrix::IDENTITY;
650 float els[] = {2.0f, 0.0f, 0.0f, 0.0f, 0.0f, 3.0f, 0.0f, 0.0f, 0.0f, 0.0f, 4.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f};
653 DALI_TEST_CHECK(m1 != r1);
654 DALI_TEST_CHECK(!(m1 != m1));
658 int UtcDaliMatrixSetTransformComponents01P(void)
660 // Create an arbitrary vector
661 for(float x = -1.0f; x <= 1.0f; x += 0.1f)
663 for(float y = -1.0f; y < 1.0f; y += 0.1f)
665 for(float z = -1.0f; z < 1.0f; z += 0.1f)
667 Vector3 vForward(x, y, z);
668 vForward.Normalize();
670 for(float angle = 5.0f; angle <= 360.0f; angle += 15.0f)
672 Quaternion rotation1(Radian(Degree(angle)), vForward);
674 Matrix m1(rotation1);
675 Matrix result1(false);
676 Vector3 vForward3(vForward.x, vForward.y, vForward.z);
677 result1.SetTransformComponents(Vector3::ONE, Quaternion(Radian(Degree(angle)), vForward3), Vector3::ZERO);
679 DALI_TEST_EQUALS(m1, result1, 0.001, TEST_LOCATION);
682 m2.SetTransformComponents(vForward, Quaternion::IDENTITY, Vector3::ZERO);
684 Matrix result2a(Matrix::IDENTITY);
685 result2a.SetXAxis(result2a.GetXAxis() * vForward[0]);
686 result2a.SetYAxis(result2a.GetYAxis() * vForward[1]);
687 result2a.SetZAxis(result2a.GetZAxis() * vForward[2]);
689 DALI_TEST_EQUALS(m2, result2a, 0.001, TEST_LOCATION);
692 m3.SetTransformComponents(vForward, rotation1, Vector3::ZERO);
694 Matrix result3(Matrix::IDENTITY);
695 result3.SetXAxis(result3.GetXAxis() * vForward[0]);
696 result3.SetYAxis(result3.GetYAxis() * vForward[1]);
697 result3.SetZAxis(result3.GetZAxis() * vForward[2]);
699 Matrix::Multiply(result3, result3, m1);
700 DALI_TEST_EQUALS(m3, result3, 0.001, TEST_LOCATION);
708 int UtcDaliMatrixSetInverseTransformComponent01P(void)
710 // Create an arbitrary vector
711 for(float x = -1.0f; x <= 1.0f; x += 0.1f)
713 for(float y = -1.0f; y < 1.0f; y += 0.1f)
715 for(float z = -1.0f; z < 1.0f; z += 0.1f)
717 Vector3 vForward(x, y, z);
718 vForward.Normalize();
721 Quaternion rotation1(Quaternion::IDENTITY); // test no rotation branch
722 Vector3 scale1(2.0f, 3.0f, 4.0f);
723 Vector3 position1(1.0f, 2.0f, 3.0f);
726 m1.SetTransformComponents(scale1, rotation1, position1);
729 m2.SetInverseTransformComponents(scale1, rotation1, position1);
732 Matrix::Multiply(result, m1, m2);
734 DALI_TEST_EQUALS(result, Matrix::IDENTITY, 0.001, TEST_LOCATION);
742 int UtcDaliMatrixSetInverseTransformComponent02P(void)
744 // Create an arbitrary vector
745 for(float x = -1.0f; x <= 1.0f; x += 0.1f)
747 for(float y = -1.0f; y < 1.0f; y += 0.1f)
749 for(float z = -1.0f; z < 1.0f; z += 0.1f)
751 Vector3 vForward(x, y, z);
752 vForward.Normalize();
754 for(float angle = 5.0f; angle <= 360.0f; angle += 15.0f)
756 Quaternion rotation1(Radian(Degree(angle)), vForward);
757 Matrix rotationMatrix(rotation1); // TEST RELIES ON THIS METHOD WORKING!!!
759 Vector3 position1(5.0f, -6.0f, 7.0f);
762 m1.SetTransformComponents(Vector3::ONE, rotation1, position1);
765 m2.SetInverseTransformComponents(rotationMatrix.GetXAxis(),
766 rotationMatrix.GetYAxis(),
767 rotationMatrix.GetZAxis(),
771 Matrix::Multiply(result, m1, m2);
773 DALI_TEST_EQUALS(result, Matrix::IDENTITY, 0.001, TEST_LOCATION);
781 int UtcDaliMatrixGetTransformComponents01P(void)
783 Matrix m2(Matrix::IDENTITY.AsFloat());
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(1.0f, 1.0f, 1.0f), scale2, 0.001, TEST_LOCATION);
790 DALI_TEST_EQUALS(Quaternion(), q2, 0.001, TEST_LOCATION);
794 int UtcDaliMatrixGetTransformComponents02P(void)
796 // Create an arbitrary vector
797 for(float x = -1.0f; x <= 1.0f; x += 0.1f)
799 for(float y = -1.0f; y < 1.0f; y += 0.1f)
801 for(float z = -1.0f; z < 1.0f; z += 0.1f)
803 Vector3 vForward(x, y, z);
804 vForward.Normalize();
806 for(float angle = 5.0f; angle <= 360.0f; angle += 15.0f)
808 Quaternion rotation1(Radian(Degree(angle)), vForward);
809 Vector3 scale1(2.0f, 3.0f, 4.0f);
810 Vector3 position1(1.0f, 2.0f, 3.0f);
813 m1.SetTransformComponents(scale1, rotation1, position1);
816 Quaternion rotation2;
818 m1.GetTransformComponents(position2, rotation2, scale2);
820 DALI_TEST_EQUALS(position1, position2, 0.001, TEST_LOCATION);
821 DALI_TEST_EQUALS(scale1, scale2, 0.001, TEST_LOCATION);
822 DALI_TEST_EQUALS(rotation1, rotation2, 0.001, TEST_LOCATION);
830 int UtcDaliMatrixGetTransformComponents03P(void)
832 Matrix m2; // zero branch
836 m2.GetTransformComponents(pos2, q2, scale2);
837 DALI_TEST_EQUALS(Vector3(0.0f, 0.0f, 0.0f), pos2, 0.001, TEST_LOCATION);
838 DALI_TEST_EQUALS(Vector3(0.0f, 0.0f, 0.0f), scale2, 0.001, TEST_LOCATION);
839 // DALI_TEST_EQUALS(Quaternion(), q2, 0.001, TEST_LOCATION);
843 int UtcDaliMatrixOStreamOperator(void)
845 std::ostringstream oss;
848 matrix.SetIdentity();
852 std::string expectedOutput = "[ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 ]";
854 DALI_TEST_EQUALS(oss.str(), expectedOutput, TEST_LOCATION);