Reowrd transformations yet again

This commit is contained in:
Robert 2021-01-23 20:09:59 +01:00
parent 83b5453088
commit 25021db694
3 changed files with 105 additions and 28 deletions

View file

@ -7,6 +7,7 @@
#include <glm/glm.hpp> #include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp> #include <glm/gtc/matrix_transform.hpp>
#include <glm/gtc/type_ptr.hpp> #include <glm/gtc/type_ptr.hpp>
#include <glm/gtx/string_cast.hpp>
void framebuffer_size_callback(GLFWwindow* window, int width, int height) 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); square.Move(-0.6f, 0.0f, 0.0f);
square2.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 // Create a shader
oglu::Shader shader; oglu::Shader shader;
@ -97,16 +101,17 @@ int main(int argc, char** argv)
// Window loop // Window loop
oglu::Enable(GL_DEPTH_TEST); oglu::Enable(GL_DEPTH_TEST);
float t = 0.0f; float t = 0.0f;
while (!glfwWindowShouldClose(window)) while (!glfwWindowShouldClose(window))
{ {
processInput(window); processInput(window);
oglu::ClearScreen(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT, oglu::Color(0.29f, 0.13f, 0.23f)); 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); square.Pitch(6.0f);
// camera.Pan(1.f); square2.Pitch(-6.0f);
shader->Use(); shader->Use();
shader->SetUniform("texture1", crate, 0); shader->SetUniform("texture1", crate, 0);

View file

@ -78,11 +78,11 @@ namespace oglu
* This sets an absolute rotation, means that it resets any previous * This sets an absolute rotation, means that it resets any previous
* rotations. * rotations.
* *
* @param[in] rotX New rotation around x axis * @param[in] pitch New pitch
* @param[in] rotY New rotation around y axis * @param[in] yaw New yaw
* @param[in] rotZ New rotation around z axis * @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. * @brief Sets the rotation.
@ -92,7 +92,7 @@ namespace oglu
* *
* @param[in] rotation An array of floats containing three scalars * @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. * @brief Sets the rotation.
@ -102,7 +102,28 @@ namespace oglu
* *
* @param[in] rotation A glm::vec3 containing Euler angles * @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. * @brief Sets the rotation.
@ -209,11 +230,11 @@ namespace oglu
* This function applies a rotation to the object, it operates * This function applies a rotation to the object, it operates
* operates on the current rotation. * operates on the current rotation.
* *
* @param[in] rotX Rotation around the x axis * @param[in] pitch Pitching
* @param[in] rotY Rotation around the y axis * @param[in] yaw Yawing
* @param[in] rotZ Rotation around the z axis * @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. * @brief Performs a rotation.
@ -223,7 +244,7 @@ namespace oglu
* *
* @param[in] rotation An array of floats containing the rotation values * @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. * @brief Performs a rotation.
@ -233,7 +254,28 @@ namespace oglu
* *
* @param[in] rotation An 3D vector containing Euler angles * @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. * @brief Performs a rotation.

View file

@ -41,22 +41,37 @@ namespace oglu
recalculateMatrix = true; 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; 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) void Transformable::SetRotation(float angle, float xAxis, float yAxis, float zAxis)
{ {
SetRotation(angle, glm::vec3(xAxis, yAxis, zAxis)); SetRotation(angle, glm::vec3(xAxis, yAxis, zAxis));
@ -105,22 +120,37 @@ namespace oglu
recalculateMatrix = true; 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; 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) void Transformable::Rotate(float angle, float xAxis, float yAxis, float zAxis)
{ {
Rotate(angle, glm::vec3(xAxis, yAxis, zAxis)); Rotate(angle, glm::vec3(xAxis, yAxis, zAxis));