Optimize Transform::ToMatrix
This commit is contained in:
parent
a2bef73191
commit
e9883b8fb5
@ -11,11 +11,34 @@ struct Transform
|
|||||||
|
|
||||||
glm::mat4 ToMatrix() const
|
glm::mat4 ToMatrix() const
|
||||||
{
|
{
|
||||||
// TODO: Optimize matrix construction
|
float x = rotation.x;
|
||||||
glm::mat4 translation_mat = glm::translate(glm::mat4(1.0f), position);
|
float y = rotation.y;
|
||||||
glm::mat4 rotation_mat = glm::mat4_cast(rotation);
|
float z = rotation.z;
|
||||||
glm::mat4 scaling_mat = glm::scale(glm::mat4(1.0f), glm::vec3(scale));
|
float w = rotation.w;
|
||||||
return translation_mat * rotation_mat * scaling_mat;
|
|
||||||
|
float x2 = x + x;
|
||||||
|
float y2 = y + y;
|
||||||
|
float z2 = z + z;
|
||||||
|
float xx = x * x2;
|
||||||
|
float xy = x * y2;
|
||||||
|
float xz = x * z2;
|
||||||
|
float yy = y * y2;
|
||||||
|
float yz = y * z2;
|
||||||
|
float zz = z * z2;
|
||||||
|
float wx = w * x2;
|
||||||
|
float wy = w * y2;
|
||||||
|
float wz = w * z2;
|
||||||
|
|
||||||
|
float sx = scale;
|
||||||
|
float sy = scale;
|
||||||
|
float sz = scale;
|
||||||
|
|
||||||
|
return glm::mat4(
|
||||||
|
(1.0f - (yy + zz)) * sx, (xy + wz) * sx, (xz - wy) * sx, 0.0f,
|
||||||
|
(xy - wz) * sy, (1.0f - (xx + zz)) * sy, (yz + wx) * sy, 0.0f,
|
||||||
|
(xz + wy) * sz, (yz - wx) * sz, (1.0f - (xx + yy)) * sz, 0.0f,
|
||||||
|
position.x, position.y, position.z, 1.0f
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetAngles(const glm::vec3& angles_deg)
|
void SetAngles(const glm::vec3& angles_deg)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user