From 25021db69426c2ef839e798c32c38140e608c97e Mon Sep 17 00:00:00 2001 From: Robert Date: Sat, 23 Jan 2021 20:09:59 +0100 Subject: [PATCH] Reowrd transformations yet again --- examples/debug/main.cpp | 13 +++++--- include/transformable.hpp | 66 ++++++++++++++++++++++++++++++++------- src/transformable.cpp | 54 +++++++++++++++++++++++++------- 3 files changed, 105 insertions(+), 28 deletions(-) diff --git a/examples/debug/main.cpp b/examples/debug/main.cpp index 8d412a9..16d07bf 100644 --- a/examples/debug/main.cpp +++ b/examples/debug/main.cpp @@ -7,6 +7,7 @@ #include #include #include +#include void framebuffer_size_callback(GLFWwindow* window, int width, int height) { @@ -70,7 +71,10 @@ int main(int argc, char** argv) square.Move(-0.6f, 0.0f, 0.0f); square2.Move(0.6f, 0.0f, 0.0f); - square.Rotate(0.0f, 0.0f, 45.0f); + //square.GlobalRotate(45.0f, 0.0f, 0.0f); + //square.GlobalRotate(0.0f, 0.0f, 45.0f); + + //square.SetGlobalRotation(45.0f, 0.0f, 45.0f); // Create a shader oglu::Shader shader; @@ -97,16 +101,17 @@ int main(int argc, char** argv) // Window loop oglu::Enable(GL_DEPTH_TEST); float t = 0.0f; + while (!glfwWindowShouldClose(window)) { processInput(window); oglu::ClearScreen(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT, oglu::Color(0.29f, 0.13f, 0.23f)); - view = glm::rotate(view, glm::radians(1.0f), glm::vec3(0.0f, 1.0f, 0.0f)); + // view = glm::rotate(view, glm::radians(1.0f), glm::vec3(0.0f, 1.0f, 0.0f)); - // camera.Rotate(0.0f, 1.0f, 0.0f); - // camera.Pan(1.f); + square.Pitch(6.0f); + square2.Pitch(-6.0f); shader->Use(); shader->SetUniform("texture1", crate, 0); diff --git a/include/transformable.hpp b/include/transformable.hpp index 33db5c6..e8e89bf 100644 --- a/include/transformable.hpp +++ b/include/transformable.hpp @@ -78,11 +78,11 @@ namespace oglu * This sets an absolute rotation, means that it resets any previous * rotations. * - * @param[in] rotX New rotation around x axis - * @param[in] rotY New rotation around y axis - * @param[in] rotZ New rotation around z axis + * @param[in] pitch New pitch + * @param[in] yaw New yaw + * @param[in] roll New roll */ - virtual void SetRotation(float rotX, float rotY, float rotZ); + virtual void SetRotation(float pitch, float yaw, float roll); /** * @brief Sets the rotation. @@ -92,7 +92,7 @@ namespace oglu * * @param[in] rotation An array of floats containing three scalars */ - virtual void SetRotation(const float* rotation); + virtual void SetRotation(const float* pitchYawRoll); /** * @brief Sets the rotation. @@ -102,7 +102,28 @@ namespace oglu * * @param[in] rotation A glm::vec3 containing Euler angles */ - virtual void SetRotation(const glm::vec3& rotation); + virtual void SetRotation(const glm::vec3 & pitchYawRoll); + + /** + * @brief Set pitch. + * + * @param[in] angle Angle to set pitch to + */ + virtual void SetPitch(float angle); + + /** + * @brief Set yaw. + * + * @param[in] angle Angle to set yaw to + */ + virtual void SetYaw(float angle); + + /** + * @brief Set roll. + * + * @param[in] angle Angle to set roll to + */ + virtual void SetRoll(float angle); /** * @brief Sets the rotation. @@ -209,11 +230,11 @@ namespace oglu * This function applies a rotation to the object, it operates * operates on the current rotation. * - * @param[in] rotX Rotation around the x axis - * @param[in] rotY Rotation around the y axis - * @param[in] rotZ Rotation around the z axis + * @param[in] pitch Pitching + * @param[in] yaw Yawing + * @param[in] roll Rolling */ - virtual void Rotate(float rotX, float rotY, float rotZ); + virtual void Rotate(float pitch, float yaw, float roll); /** * @brief Performs a rotation. @@ -223,7 +244,7 @@ namespace oglu * * @param[in] rotation An array of floats containing the rotation values */ - virtual void Rotate(const float* rotation); + virtual void Rotate(const float* pitchYawRoll); /** * @brief Performs a rotation. @@ -233,7 +254,28 @@ namespace oglu * * @param[in] rotation An 3D vector containing Euler angles */ - virtual void Rotate(const glm::vec3& rotation); + virtual void Rotate(const glm::vec3& pitchYawRoll); + + /** + * @brief Pitch the object. + * + * @param[in] angle Angle to pitch by + */ + virtual void Pitch(float angle); + + /** + * @brief Yaw the object. + * + * @param[in] angle Angle to yaw by + */ + virtual void Yaw(float angle); + + /** + * @brief Roll the object. + * + * @param[in] angle Angle to roll by + */ + virtual void Roll(float angle); /** * @brief Performs a rotation. diff --git a/src/transformable.cpp b/src/transformable.cpp index d8b1e96..3f51968 100644 --- a/src/transformable.cpp +++ b/src/transformable.cpp @@ -41,22 +41,37 @@ namespace oglu recalculateMatrix = true; } - void Transformable::SetRotation(float rotX, float rotY, float rotZ) + void Transformable::SetRotation(float pitch, float yaw, float roll) { - SetRotation(glm::vec3(rotX, rotY, rotZ)); + SetRotation(glm::vec3(pitch, yaw, roll)); } - void Transformable::SetRotation(const float* rotation) + void Transformable::SetRotation(const float* pitchYawRoll) { - SetRotation(glm::make_vec3(rotation)); + SetRotation(glm::make_vec3(pitchYawRoll)); } - void Transformable::SetRotation(const glm::vec3& rotation) + void Transformable::SetRotation(const glm::vec3& pitchYawRoll) { - orientation = glm::quat(glm::radians(rotation)); + orientation = glm::quat(glm::radians(pitchYawRoll)); recalculateMatrix = true; } + inline void Transformable::SetPitch(float angle) + { + SetRotation(glm::vec3(angle, 0.0f, 0.0f)); + } + + inline void Transformable::SetYaw(float angle) + { + SetRotation(glm::vec3(0.0f, angle, 0.0f)); + } + + inline void Transformable::SetRoll(float angle) + { + SetRotation(glm::vec3(0.0f, 0.0f, angle)); + } + void Transformable::SetRotation(float angle, float xAxis, float yAxis, float zAxis) { SetRotation(angle, glm::vec3(xAxis, yAxis, zAxis)); @@ -105,22 +120,37 @@ namespace oglu recalculateMatrix = true; } - void Transformable::Rotate(float rotX, float rotY, float rotZ) + void Transformable::Rotate(float pitch, float yaw, float roll) { - Rotate(glm::vec3(rotX, rotY, rotZ)); + Rotate(glm::vec3(pitch, yaw, roll)); } - void Transformable::Rotate(const float* rotation) + void Transformable::Rotate(const float* pitchYawRoll) { - Rotate(glm::make_vec3(rotation)); + Rotate(glm::make_vec3(pitchYawRoll)); } - void Transformable::Rotate(const glm::vec3& rotation) + void Transformable::Rotate(const glm::vec3& pitchYawRoll) { - orientation *= glm::quat(glm::radians(rotation)); + orientation *= glm::quat(glm::radians(pitchYawRoll)); recalculateMatrix = true; } + inline void Transformable::Pitch(float angle) + { + Rotate(glm::vec3(angle, 0.0f, 0.0f)); + } + + inline void Transformable::Yaw(float angle) + { + Rotate(glm::vec3(0.0f, angle, 0.0f)); + } + + inline void Transformable::Roll(float angle) + { + Rotate(glm::vec3(0.0f, 0.0f, angle)); + } + void Transformable::Rotate(float angle, float xAxis, float yAxis, float zAxis) { Rotate(angle, glm::vec3(xAxis, yAxis, zAxis));