From 8a73b1bfdc359a52a3cf1b104b4e42902866705e Mon Sep 17 00:00:00 2001 From: "Eunki, Hong" Date: Wed, 8 Mar 2023 03:53:10 +0900 Subject: [PATCH] Get world scale more faster Change-Id: Ifb580a830a4798d72da7537cedce83d577ae60d6 Signed-off-by: Eunki, Hong --- automated-tests/src/dali/utc-Dali-Matrix.cpp | 34 +++++++++++++++++++++- .../manager/render-instruction-processor.cpp | 2 +- .../update/manager/transform-manager-property.h | 4 +-- dali/public-api/math/matrix.cpp | 21 +++++++------ dali/public-api/math/matrix.h | 12 +++++++- 5 files changed, 58 insertions(+), 15 deletions(-) diff --git a/automated-tests/src/dali/utc-Dali-Matrix.cpp b/automated-tests/src/dali/utc-Dali-Matrix.cpp index f72dd93..da8e265 100644 --- a/automated-tests/src/dali/utc-Dali-Matrix.cpp +++ b/automated-tests/src/dali/utc-Dali-Matrix.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Samsung Electronics Co., Ltd. + * Copyright (c) 2023 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. @@ -405,6 +405,38 @@ int UtcDaliMatrixGetTranslation3P(void) END_TEST; } +int UtcDaliMatrixGetScale(void) +{ + // Create an arbitrary vector + for(float x = 0.0f; x <= 2.0f; x += 0.1f) + { + for(float y = 0.0f; y < 2.0f; y += 0.1f) + { + for(float z = 0.0f; z < 2.0f; z += 0.1f) + { + Vector3 vScale(x, y, z); + + for(float angle = 5.0f; angle <= 360.0f; angle += 15.0f) + { + Vector3 forward(1.0f, 1.3f, 2.0f); + forward.Normalize(); + + Quaternion rotation1(Radian(Degree(angle)), forward); + Vector3 position1(1.0f, 2.0f, 3.0f); + + Matrix m1(false); + m1.SetTransformComponents(vScale, rotation1, position1); + + Vector3 scale2 = m1.GetScale(); + + DALI_TEST_EQUALS(vScale, scale2, 0.001, TEST_LOCATION); + } + } + } + } + END_TEST; +} + int UtcDaliMatrixSetTranslationP(void) { Matrix m; diff --git a/dali/internal/update/manager/render-instruction-processor.cpp b/dali/internal/update/manager/render-instruction-processor.cpp index 4187b8f..87c3c98 100644 --- a/dali/internal/update/manager/render-instruction-processor.cpp +++ b/dali/internal/update/manager/render-instruction-processor.cpp @@ -216,7 +216,7 @@ inline void AddRendererToRenderList(BufferIndex updateBufferIndex, SetNodeUpdateArea(node, isLayer3d, nodeWorldMatrix, nodeSize, nodeUpdateArea); nodeUpdateAreaSet = true; - const Vector3& scale = node->GetWorldScale(updateBufferIndex); + const Vector3& scale = nodeWorldMatrix.GetScale(); const Vector3& size = Vector3(nodeUpdateArea.z, nodeUpdateArea.w, 1.0f) * scale; if(size.LengthSquared() > Math::MACHINE_EPSILON_1000) diff --git a/dali/internal/update/manager/transform-manager-property.h b/dali/internal/update/manager/transform-manager-property.h index b9600bd..fe5fec4 100644 --- a/dali/internal/update/manager/transform-manager-property.h +++ b/dali/internal/update/manager/transform-manager-property.h @@ -400,9 +400,7 @@ public: } else if(mProperty == TRANSFORM_PROPERTY_WORLD_SCALE) { - Vector3 position; - Quaternion orientation; - worldMatrix.GetTransformComponents(position, orientation, mValue); + mValue = worldMatrix.GetScale(); } } } diff --git a/dali/public-api/math/matrix.cpp b/dali/public-api/math/matrix.cpp index 45b8535..7b810bb 100644 --- a/dali/public-api/math/matrix.cpp +++ b/dali/public-api/math/matrix.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Samsung Electronics Co., Ltd. + * Copyright (c) 2023 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. @@ -561,26 +561,29 @@ void Matrix::SetInverseTransformComponents(const Vector3& xAxis, SetTranslation(inverseTranslation); } +Vector3 Matrix::GetScale() const +{ + // Derive scale from axis lengths. + return Vector3(GetXAxis().Length(), GetYAxis().Length(), GetZAxis().Length()); +} + void Matrix::GetTransformComponents(Vector3& position, Quaternion& rotation, Vector3& scale) const { position = GetTranslation3(); + scale = GetScale(); - // Derive scale from axis lengths. - Vector3 theScale(GetXAxis().Length(), GetYAxis().Length(), GetZAxis().Length()); - scale = theScale; - - if(!(fabs(theScale.x - Vector3::ONE.x) < ROTATION_EPSILON && - fabs(theScale.y - Vector3::ONE.y) < ROTATION_EPSILON && - fabs(theScale.z - Vector3::ONE.z) < ROTATION_EPSILON)) + if(!(fabs(scale.x - Vector3::ONE.x) < ROTATION_EPSILON && + fabs(scale.y - Vector3::ONE.y) < ROTATION_EPSILON && + fabs(scale.z - Vector3::ONE.z) < ROTATION_EPSILON)) { MATH_INCREASE_COUNTER(PerformanceMonitor::MATRIX_MULTIPLYS); MATH_INCREASE_BY(PerformanceMonitor::FLOAT_POINT_MULTIPLY, 9); // Non-identity scale is embedded into rotation matrix. Remove it first: Matrix m(*this); - Vector3 inverseScale(1.0f / theScale.x, 1.0f / theScale.y, 1.0f / theScale.z); + Vector3 inverseScale(1.0f / scale.x, 1.0f / scale.y, 1.0f / scale.z); m.mMatrix[0] *= inverseScale.x; m.mMatrix[1] *= inverseScale.x; m.mMatrix[2] *= inverseScale.x; diff --git a/dali/public-api/math/matrix.h b/dali/public-api/math/matrix.h index bdd80bf..332163d 100644 --- a/dali/public-api/math/matrix.h +++ b/dali/public-api/math/matrix.h @@ -2,7 +2,7 @@ #define DALI_MATRIX_H /* - * Copyright (c) 2022 Samsung Electronics Co., Ltd. + * Copyright (c) 2023 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. @@ -257,6 +257,16 @@ public: } /** + * @brief Gets the x,y and z components of the scale as a Vector3. + * Note that transform scale always has positive components. + * + * This assumes the matrix is a transform matrix. + * @SINCE_2_2.17 + * @return The scale + */ + Vector3 GetScale() const; + + /** * @brief Sets the translation. * * This assumes the matrix is a transform matrix. -- 2.7.4