Optimize Transform::ToMatrix
This commit is contained in:
parent
a2bef73191
commit
e9883b8fb5
@ -11,11 +11,34 @@ struct Transform
|
||||
|
||||
glm::mat4 ToMatrix() const
|
||||
{
|
||||
// TODO: Optimize matrix construction
|
||||
glm::mat4 translation_mat = glm::translate(glm::mat4(1.0f), position);
|
||||
glm::mat4 rotation_mat = glm::mat4_cast(rotation);
|
||||
glm::mat4 scaling_mat = glm::scale(glm::mat4(1.0f), glm::vec3(scale));
|
||||
return translation_mat * rotation_mat * scaling_mat;
|
||||
float x = rotation.x;
|
||||
float y = rotation.y;
|
||||
float z = rotation.z;
|
||||
float w = rotation.w;
|
||||
|
||||
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)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user