/*
- * 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.
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;
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)
}
else if(mProperty == TRANSFORM_PROPERTY_WORLD_SCALE)
{
- Vector3 position;
- Quaternion orientation;
- worldMatrix.GetTransformComponents(position, orientation, mValue);
+ mValue = worldMatrix.GetScale();
}
}
}
/*
- * 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.
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;
#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.
}
/**
+ * @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.