Get world scale more faster 38/289438/2
authorEunki, Hong <eunkiki.hong@samsung.com>
Tue, 7 Mar 2023 18:53:10 +0000 (03:53 +0900)
committerEunki, Hong <eunkiki.hong@samsung.com>
Thu, 9 Mar 2023 06:23:14 +0000 (15:23 +0900)
Change-Id: Ifb580a830a4798d72da7537cedce83d577ae60d6
Signed-off-by: Eunki, Hong <eunkiki.hong@samsung.com>
automated-tests/src/dali/utc-Dali-Matrix.cpp
dali/internal/update/manager/render-instruction-processor.cpp
dali/internal/update/manager/transform-manager-property.h
dali/public-api/math/matrix.cpp
dali/public-api/math/matrix.h

index f72dd93..da8e265 100644 (file)
@@ -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;
index 4187b8f..87c3c98 100644 (file)
@@ -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)
index b9600bd..fe5fec4 100644 (file)
@@ -400,9 +400,7 @@ public:
       }
       else if(mProperty == TRANSFORM_PROPERTY_WORLD_SCALE)
       {
-        Vector3    position;
-        Quaternion orientation;
-        worldMatrix.GetTransformComponents(position, orientation, mValue);
+        mValue = worldMatrix.GetScale();
       }
     }
   }
index 45b8535..7b810bb 100644 (file)
@@ -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;
index bdd80bf..332163d 100644 (file)
@@ -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.