diff --git a/core/Transform.cpp b/core/Transform.cpp index 271e404..44055fc 100644 --- a/core/Transform.cpp +++ b/core/Transform.cpp @@ -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)); } diff --git a/demo/main.lua b/demo/main.lua index de1e94c..ab8fdb5 100644 --- a/demo/main.lua +++ b/demo/main.lua @@ -61,6 +61,9 @@ end function update(delta) local cam_forwards = camera.transform:Forward() + local cam_rotation = camera.transform.rotation + print (cam_forwards.x, cam_forwards.y, cam_forwards.z) + print (cam_rotation.x, cam_rotation.y, cam_rotation.z) local move_vec = couch.Vector3() move_vec = camera.transform.position + cam_forwards * delta * vz * SPEED @@ -69,7 +72,7 @@ function update(delta) camera.transform.rotation.y = camera.transform.rotation.y - cam_rot_x * delta cam_rot_x = 0.0 camera.transform.rotation.x = camera.transform.rotation.x - cam_rot_y * delta - camera.transform.rotation.x = min(max(camera.transform.rotation.x, -3.14), 3.14) + camera.transform.rotation.x = min(max(camera.transform.rotation.x, -3.14 / 2.0), 3.14 / 2.0) cam_rot_y = 0.0 local loc = ball1.transform.position @@ -81,8 +84,6 @@ function update(delta) ball1.transform.position.y = ball1.transform.position.y + ballvy * delta ball.transform.rotation.z = ball.transform.rotation.z + 1.0 * delta; - ball.transform.rotation.y = ball.transform.rotation.y + 1.0 * delta; - ball.transform.rotation.x = ball.transform.rotation.x + 1.0 * delta; end function onkey(key, code, action, mod)