Apply rotations in the correct order

This commit is contained in:
Dane Johnson
2021-01-20 22:17:33 -06:00
parent 7ac961ea42
commit 6f03ed7295
2 changed files with 10 additions and 6 deletions

View File

@@ -27,8 +27,11 @@ void Transform::Translate(cfloat x, cfloat y, cfloat z) {
Vector3 Transform::Forward() {
Vector3 forward(0.0f, 0.0f, -1.0f);
Matrix mat(1.0f);
mat = glm::rotate(mat, this->rotation.x, Vector3(1.0f, 0.0f, 0.0f));
mat = glm::rotate(mat, this->rotation.y, Vector3(0.0f, 1.0f, 0.0f));
mat = glm::rotate(mat, this->rotation.z, Vector3(0.0f, 0.0f, 1.0f));
return mat * glm::vec4(forward, 1.0f);
mat = glm::rotate(mat, this->rotation.y, Vector3(0.0f, 1.0f, 0.0f));
mat = glm::rotate(mat, this->rotation.x, Vector3(1.0f, 0.0f, 0.0f));
return glm::vec3(mat * glm::vec4(forward, 1.0f));
}