From 3cd610dfe0829a2a43c0549be6e4c69ff01b62a7 Mon Sep 17 00:00:00 2001 From: "Eunki, Hong" Date: Tue, 26 Jul 2022 19:21:40 +0900 Subject: [PATCH] Add operator for Matirx3 * Vector3 We might need to multiply for some non-transition matrix. Change-Id: I5a8aa02ce8c1e68b623aea07d9e7540f7074368f Signed-off-by: Eunki, Hong --- automated-tests/src/dali/utc-Dali-Matrix3.cpp | 22 +++++++++++++++++++++- dali/public-api/math/matrix3.cpp | 9 ++++++++- dali/public-api/math/matrix3.h | 13 ++++++++++++- 3 files changed, 41 insertions(+), 3 deletions(-) diff --git a/automated-tests/src/dali/utc-Dali-Matrix3.cpp b/automated-tests/src/dali/utc-Dali-Matrix3.cpp index fe2ee41..1f84030 100644 --- a/automated-tests/src/dali/utc-Dali-Matrix3.cpp +++ b/automated-tests/src/dali/utc-Dali-Matrix3.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020 Samsung Electronics Co., Ltd. + * Copyright (c) 2022 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -313,6 +313,26 @@ int UtcDaliMatrix3Multiply(void) END_TEST; } +int UtcDaliMatrix3OperatorMultiply01P(void) +{ + Vector3 v1(2.0f, 5.0f, 4.0f); + + Vector3 v2 = m1 * v1; + Vector3 r1(-37.2f, 118.8f, 13.2f); + DALI_TEST_EQUALS(v2, r1, 0.01f, TEST_LOCATION); + END_TEST; +} + +int UtcDaliMatrix3OperatorMultiply02P(void) +{ + Vector3 v1(2.0f, 5.0f, 4.0f); + + Vector3 v2 = m6 * v1; + Vector3 r1(88.668f, 35.2f, -340.65f); + DALI_TEST_EQUALS(v2, r1, 0.01f, TEST_LOCATION); + END_TEST; +} + int UtcDaliMatrix3EqualityOperator(void) { Matrix3 m1(0.0f, 3.0f, 6.0f, 12.0f, 15.0f, 18.0f, 24.0f, 27.0f, 30.0f); diff --git a/dali/public-api/math/matrix3.cpp b/dali/public-api/math/matrix3.cpp index 5fc44e7..118cc90 100644 --- a/dali/public-api/math/matrix3.cpp +++ b/dali/public-api/math/matrix3.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020 Samsung Electronics Co., Ltd. + * Copyright (c) 2022 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -276,6 +276,13 @@ void Matrix3::Multiply(Matrix3& result, const Matrix3& lhs, const Matrix3& rhs) } } +Vector3 Matrix3::operator*(const Vector3& rhs) const +{ + return Vector3(rhs.x * mElements[S00] + rhs.y * mElements[S10] + rhs.z * mElements[S20], + rhs.x * mElements[S01] + rhs.y * mElements[S11] + rhs.z * mElements[S21], + rhs.x * mElements[S02] + rhs.y * mElements[S12] + rhs.z * mElements[S22]); +} + bool Matrix3::operator==(const Matrix3& rhs) const { return ( diff --git a/dali/public-api/math/matrix3.h b/dali/public-api/math/matrix3.h index 8876bc1..47d51fb 100644 --- a/dali/public-api/math/matrix3.h +++ b/dali/public-api/math/matrix3.h @@ -2,7 +2,7 @@ #define DALI_MATRIX3_H /* - * Copyright (c) 2020 Samsung Electronics Co., Ltd. + * Copyright (c) 2022 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -260,6 +260,17 @@ public: */ static void Multiply(Matrix3& result, const Matrix3& lhs, const Matrix3& rhs); + /** + * @brief The multiplication operator. + * + * Returned Vector = This Matrix * rhs + * + * @SINCE_2_1.34 + * @param[in] rhs The Vector3 to multiply this by + * @return A Vector3 containing the result + */ + Vector3 operator*(const Vector3& rhs) const; + private: float mElements[9]; ///< The elements of the matrix }; -- 2.7.4