diff --git a/CMakeLists.txt b/CMakeLists.txt index a80f56a..f48157e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -28,7 +28,7 @@ add_library(openglu SHARED ${include_files} ${source_files} "cpp.hint" - "src/transformable.cpp") +) target_compile_definitions(openglu PRIVATE OGLU_BUILD_DLL) @@ -48,7 +48,6 @@ if(${build_documentation}) COMMAND ${DOXYGEN_EXECUTABLE} "${CMAKE_BINARY_DIR}/doxyfile" WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} COMMENT "Building documentation..." - VERBATIM ) endif() diff --git a/examples/debug/CMakeLists.txt b/examples/debug/CMakeLists.txt index 60ca621..a48be0d 100644 --- a/examples/debug/CMakeLists.txt +++ b/examples/debug/CMakeLists.txt @@ -1,4 +1,4 @@ -add_executable(debug "main.cpp") +add_executable(debug "main.cpp" "shaders/fragmentShader.frag" "shaders/vertexShader.vert") find_package(glfw3 REQUIRED) diff --git a/examples/debug/main.cpp b/examples/debug/main.cpp index 3794886..cfdad20 100644 --- a/examples/debug/main.cpp +++ b/examples/debug/main.cpp @@ -86,13 +86,11 @@ int main(int argc, char** argv) oglu::Texture crate = oglu::MakeTexture("assets/crate.jpg"); oglu::Texture opengl = oglu::MakeTexture("assets/opengl.png"); - glm::mat4 view = glm::mat4(1.0f); - view = glm::translate(view, glm::vec3(0.0f, 0.0f, -5.0f)); - - glm::mat4 projection; - projection = glm::perspective(glm::radians(45.f), 1.0f, 0.1f, 100.0f); + oglu::Camera camera; + camera.Move(0.0f, 0.0f, -5.0f); // Window loop + float t = 0.0f; while (!glfwWindowShouldClose(window)) { processInput(window); @@ -101,15 +99,14 @@ int main(int argc, char** argv) square.Rotate(6.0f, 0.0f, 0.0f); square2.Rotate(-6.0f, 0.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); shader->Use(); shader->SetUniform("texture1", crate, 0); shader->SetUniform("texture2", opengl, 1); shader->SetUniform("model", square); - shader->SetUniformMatrix4fv("view", 1, GL_FALSE, glm::value_ptr(view)); - shader->SetUniformMatrix4fv("projection", 1, GL_FALSE, glm::value_ptr(projection)); + shader->SetUniform("view", camera); + shader->SetUniformMatrix4fv("projection", 1, GL_FALSE, camera.GetProjectionMatrix()); square.Render(); @@ -118,6 +115,8 @@ int main(int argc, char** argv) glfwSwapBuffers(window); glfwPollEvents(); + + t += 0.1f; } glfwTerminate(); diff --git a/examples/model_loading/main.cpp b/examples/model_loading/main.cpp index 0ec4612..e53cfe8 100644 --- a/examples/model_loading/main.cpp +++ b/examples/model_loading/main.cpp @@ -72,6 +72,8 @@ int main(int argc, char** argv) oglu::Enable(GL_DEPTH_TEST); oglu::Camera camera(45.0f, 1.0f, 0.1f, 100.0f); + camera.Move(0.0f, -5.0f, -10.0f); + camera.LookAt(glm::value_ptr(glm::make_vec3(utah.GetPosition()) + glm::vec3(0.0f, 2.0f, 0.0f))); float t = 0.0f; @@ -82,12 +84,11 @@ int main(int argc, char** argv) oglu::ClearScreen(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT, oglu::Color(0.29f, 0.13f, 0.23f)); - camera.SetPosition(10.0f * cosf(t), -5.0f, 10.0f * sinf(t)); - camera.LookAt(utah); + utah.Rotate(0.0f, 10.0f, 0.0f); shader->Use(); shader->SetUniform("model", utah); - shader->SetUniformMatrix4fv("view", 1, GL_FALSE, camera.GetMatrix()); + shader->SetUniform("view", camera); shader->SetUniformMatrix4fv("projection", 1, GL_FALSE, camera.GetProjectionMatrix()); oglu::PolygonMode(GL_FRONT_AND_BACK, GL_LINE); diff --git a/include/camera.hpp b/include/camera.hpp index d87adc8..e5e51e1 100644 --- a/include/camera.hpp +++ b/include/camera.hpp @@ -78,6 +78,16 @@ namespace oglu */ void LookAt(const GLfloat* target); + /** + * @brief Have camera face at a certain position. + * + * This will adjust the camera's rotation in order to put the + * specified coordinate at the center of the screen. + * + * @param[in] target 3D vector with the target position + */ + void LookAt(const glm::vec3& target); + /** * @brief Have camera face at a certain position. * diff --git a/include/transformable.hpp b/include/transformable.hpp index 165faf7..c2e1a59 100644 --- a/include/transformable.hpp +++ b/include/transformable.hpp @@ -10,6 +10,8 @@ #define TRANSFORMABLE_HPP #include +#include +#include namespace oglu { @@ -48,7 +50,7 @@ namespace oglu * @param[in] y New y position * @param[in] z New z position */ - void SetPosition(float x, float y, float z); + virtual void SetPosition(float x, float y, float z); /** * @brief Sets the position. @@ -58,7 +60,17 @@ namespace oglu * * @param[in] position An array of floats containing three scalars */ - void SetPosition(const float* position); + virtual void SetPosition(const float* position); + + /** + * @brief Sets the position. + * + * This sets an absolute position, means that it resets any previous + * translations. + * + * @param[in] position A 3D position vector + */ + virtual void SetPosition(const glm::vec3& position); /** * @brief Sets the rotation. @@ -70,7 +82,7 @@ namespace oglu * @param[in] rotY New rotation around y axis * @param[in] rotZ New rotation around z axis */ - void SetRotation(float rotX, float rotY, float rotZ); + virtual void SetRotation(float rotX, float rotY, float rotZ); /** * @brief Sets the rotation. @@ -80,7 +92,17 @@ namespace oglu * * @param[in] rotation An array of floats containing three scalars */ - void SetRotation(const float* rotation); + virtual void SetRotation(const float* rotation); + + /** + * @brief Sets the rotation. + * + * This sets an absolute rotation, means that it resets any previous + * rotations. + * + * @param[in] rotation A glm::vec3 containing Euler angles + */ + virtual void SetRotation(const glm::vec3& rotation); /** * @brief Sets the rotation. @@ -93,7 +115,7 @@ namespace oglu * @param[in] yAxis The y component of the rotation axis * @param[in] zAxis The z component of the rotation axis */ - void SetRotation(float angle, float xAxis, float yAxis, float zAxis); + virtual void SetRotation(float angle, float xAxis, float yAxis, float zAxis); /** * @brief Sets the rotation. @@ -104,7 +126,18 @@ namespace oglu * @param[in] angle The angle to rotate by * @param[in] axis An array of floats containing the three rotation axis components */ - void SetRotation(float angle, const float* axis); + virtual void SetRotation(float angle, const float* axis); + + /** + * @brief Sets the rotation. + * + * This sets an absolute rotation, means that it resets any previous + * rotations. + * + * @param[in] angle The angle to rotate by + * @param[in] axis The axis to rotate around + */ + virtual void SetRotation(float angle, const glm::vec3& axis); /** * @brief Sets the scaling. @@ -116,7 +149,7 @@ namespace oglu * @param[in] scaleY The scaling in y direction * @param[in] scaleZ The scaling in z direction */ - void SetScale(float scaleX, float scaleY, float scaleZ); + virtual void SetScale(float scaleX, float scaleY, float scaleZ); /** * @brief Sets the scaling. @@ -126,7 +159,17 @@ namespace oglu * * @param[in] scale An array of floats containing three scalars */ - void SetScale(const float* scale); + virtual void SetScale(const float* scale); + + /** + * @brief Sets the scaling. + * + * This sets an absolute scaling, means that it resets any previous + * scaling. + * + * @param[in] scale A 3D scaling vector + */ + virtual void SetScale(const glm::vec3& scale); /** * @brief Performs a translation. @@ -138,7 +181,7 @@ namespace oglu * @param[in] y Offset along the y axis * @param[in] z Offset along the z axis */ - void Move(float x, float y, float z); + virtual void Move(float x, float y, float z); /** * @brief Performs a translation. @@ -148,7 +191,17 @@ namespace oglu * * @param[in] position An array of floats containing the offset values */ - void Move(const float* translation); + virtual void Move(const float* translation); + + /** + * @brief Performs a translation. + * + * This function applies a translation to the object, it operates + * operates on the current position. + * + * @param[in] position A 3D displacement vector + */ + virtual void Move(const glm::vec3& translation); /** * @brief Performs a rotation. @@ -160,7 +213,7 @@ namespace oglu * @param[in] rotY Rotation around the y axis * @param[in] rotZ Rotation around the z axis */ - void Rotate(float rotX, float rotY, float rotZ); + virtual void Rotate(float rotX, float rotY, float rotZ); /** * @brief Performs a rotation. @@ -170,7 +223,17 @@ namespace oglu * * @param[in] rotation An array of floats containing the rotation values */ - void Rotate(const float* rotation); + virtual void Rotate(const float* rotation); + + /** + * @brief Performs a rotation. + * + * This function applies a rotation to the object, it operates + * operates on the current rotation. + * + * @param[in] rotation An 3D vector containing Euler angles + */ + virtual void Rotate(const glm::vec3& rotation); /** * @brief Performs a rotation. @@ -183,7 +246,7 @@ namespace oglu * @param[in] yAxis y component of the rotation axis * @param[in] zAxis z component of the rotation axis */ - void Rotate(float angle, float xAxis, float yAxis, float zAxis); + virtual void Rotate(float angle, float xAxis, float yAxis, float zAxis); /** * @brief Performs a rotation. @@ -192,9 +255,20 @@ namespace oglu * operates on the current rotation. * * @param[in] angle The angle to rotate by - * @param[in] An array of floats containing the components of the rotation axis + * @param[in] axis An array of floats containing the components of the rotation axis */ - void Rotate(float angle, const float* axis); + virtual void Rotate(float angle, const float* axis); + + /** + * @brief Performs a rotation. + * + * This function applies a rotation to the object, it operates + * operates on the current rotation. + * + * @param[in] angle The angle to rotate by + * @param[in] axis The axis to rotate around + */ + virtual void Rotate(float angle, const glm::vec3& axis); /** * @brief Performs scaling. @@ -206,7 +280,7 @@ namespace oglu * @param[in] scaleX Scaling in y direction * @param[in] scaleX Scaling in z direction */ - void Scale(float scaleX, float scaleY, float scaleZ); + virtual void Scale(float scaleX, float scaleY, float scaleZ); /** * @brief Performs scaling. @@ -216,54 +290,56 @@ namespace oglu * * @param[in] scale An array of floats containing three scaling values */ - void Scale(const float* scale); + virtual void Scale(const float* scale); + + /** + * @brief Performs scaling. + * + * This function applies scaling to the object, it operates + * operates on the current scaling. + * + * @param[in] scale A 3D scaling vector + */ + virtual void Scale(const glm::vec3& scale); /** * @brief Returns a transformation matrix. * - * Internally, this function multiplies the translation, rotation, - * and scaling matrices into one transformation matrix which is - * then returned. - * - * This multiplication is only performed when a change occured to one - * of those matrices (so when there was a translation, rotation or scaling). - * So it is okay to call this function multiple times without huge performance - * loss, as long as no transformations occur inbetween. - * * @return An array of 16 floats representing the transformation matrix */ - const float* GetMatrix(); + virtual const glm::mat4& GetMatrix(); /** * @brief Get position as a 3D vector. * * @returns A pointer to an array of floats */ - const float* GetPosition() const; + virtual const glm::vec3& GetPosition() const; /** * @brief Get rotation as a matrix. * * @returns A pointer to a 4x4 matrix */ - const float* GetRotation() const; + virtual const glm::quat& GetRotation() const; /** * @brief Get scaling as a 3D vector. * * @returns A pointer to an array of floats */ - const float* GetScaling() const; + virtual const glm::vec3& GetScaling() const; protected: // TODO: Separate translation, rotation and scaling matrices. // Combine them only when the user wants the transformation matrix - float* position; ///< Position vector - float* rotation; ///< Rotation matrix - float* scaling; ///< Scaling vector + glm::mat4 transformation; - float* transformation; - bool calculateMatrix; ///< Wether GetMatrix() needs to re-calculate the transformation matrix + glm::vec3 scale; + glm::quat orientation; + glm::vec3 translation; + glm::vec3 skew; + glm::vec4 perspective; }; } diff --git a/src/camera.cpp b/src/camera.cpp index 4e7ee94..107d03a 100644 --- a/src/camera.cpp +++ b/src/camera.cpp @@ -13,6 +13,10 @@ namespace oglu Camera::Camera() : fov(45.0f), aspectRatio(0.0f), zNear(0.1f), zFar(100.0f), projection(new float[16]{ 0.0f }) { + GLint viewport[4]; + glGetIntegerv(GL_VIEWPORT, viewport); + aspectRatio = (float)viewport[2] / (float)viewport[3]; + memcpy( projection, glm::value_ptr(glm::perspective(glm::radians(fov), aspectRatio, zNear, zFar)), @@ -53,37 +57,18 @@ namespace oglu void Camera::LookAt(GLfloat x, GLfloat y, GLfloat z) { - glm::mat4 newTransform = glm::lookAt(glm::make_vec3(position), glm::vec3(x, y, z), glm::vec3(0.0f, 1.0f, 0.0f)); - glm::vec3 scale; - glm::vec3 pos; - glm::quat rot; - glm::vec3 skew; - glm::vec4 pers; - glm::decompose(newTransform, scale, rot, pos, skew, pers); - - memcpy( - position, - glm::value_ptr(pos), - 3 * sizeof(float) - ); - - memcpy( - rotation, - glm::value_ptr(glm::toMat4(rot)), - 16 * sizeof(float) - ); - - memcpy( - scaling, - glm::value_ptr(scale), - 3 * sizeof(float) - ); - calculateMatrix = true; + LookAt(glm::vec3(x, y, z)); } void Camera::LookAt(const GLfloat* target) { - LookAt(target[0], target[1], target[2]); + LookAt(glm::make_vec3(target)); + } + + void Camera::LookAt(const glm::vec3& target) + { + transformation = glm::lookAt(translation, target, glm::vec3(0.0f, 1.0f, 0.0f)); + glm::decompose(transformation, scale, orientation, translation, skew, perspective); } void Camera::LookAt(const Transformable& target) diff --git a/src/shader.cpp b/src/shader.cpp index 5a19faa..03f88de 100644 --- a/src/shader.cpp +++ b/src/shader.cpp @@ -9,6 +9,8 @@ #include #include +#include + namespace oglu { AbstractShader::AbstractShader(const AbstractShader& other) : @@ -254,7 +256,7 @@ namespace oglu void AbstractShader::SetUniform(GLint location, Transformable& v0, GLboolean transpose) { - glUniformMatrix4fv(location, 1, transpose, v0.GetMatrix()); + glUniformMatrix4fv(location, 1, transpose, glm::value_ptr(v0.GetMatrix())); } void AbstractShader::SetUniform1fv(const GLchar* name, GLsizei count, const GLfloat* value) diff --git a/src/transformable.cpp b/src/transformable.cpp index b12110c..18c9be1 100644 --- a/src/transformable.cpp +++ b/src/transformable.cpp @@ -2,266 +2,182 @@ #include -#include #include +#include +#include #include namespace oglu { oglu::Transformable::Transformable() : - position(new float[3]{ 0.f }), rotation(new float[16]), scaling(new float[3]{ 1.f, 1.f, 1.f }), transformation(new float[16]), calculateMatrix(false) + transformation(glm::mat4(1.0f)) { - glm::mat4 identity(1.0f); - memcpy( - rotation, - glm::value_ptr(identity), - 16 * sizeof(float) - ); - memcpy( - transformation, - glm::value_ptr(identity), - 16 * sizeof(float) - ); + glm::decompose(transformation, scale, orientation, translation, skew, perspective); } Transformable::Transformable(const Transformable& other) : - position(new float[3]), rotation(new float[16]), scaling(new float[3]), transformation(new float[16]), calculateMatrix(true) + transformation(other.transformation) { - memcpy( - this->position, - other.position, - 3 * sizeof(float) - ); - - memcpy( - this->rotation, - other.rotation, - 16 * sizeof(float) - ); - - memcpy( - this->scaling, - other.scaling, - 3 * sizeof(float) - ); + glm::decompose(transformation, scale, orientation, translation, skew, perspective); } Transformable::~Transformable() { - delete[] scaling; - delete[] rotation; - delete[] position; } void Transformable::SetPosition(float x, float y, float z) { - this->position[0] = x; - this->position[1] = y; - this->position[2] = z; - calculateMatrix = true; + SetPosition(glm::vec3(x, y, z)); } void Transformable::SetPosition(const float* translation) { - memcpy( - this->position, - translation, - 3 * sizeof(float) - ); - calculateMatrix = true; + SetPosition(glm::make_vec3(translation)); + } + + void Transformable::SetPosition(const glm::vec3& position) + { + glm::decompose(transformation, scale, orientation, this->translation, skew, perspective); + this->translation = translation - this->translation; + transformation = glm::translate(transformation, this->translation); } void Transformable::SetRotation(float rotX, float rotY, float rotZ) { - // TODO: Using rotation matrices is stupid. Eventually this could (should) be done with quaternions - // For now we'll just risk gimbal locking the model - memcpy( - this->rotation, - glm::value_ptr( - glm::rotate( - glm::rotate( - glm::rotate( - glm::mat4(1.0f), glm::radians(rotX), glm::vec3(1.0f, 0.0f, 0.0f) - ), glm::radians(rotY), glm::vec3(0.0f, 1.0f, 0.0f) - ), glm::radians(rotZ), glm::vec3(0.0f, 0.0f, 1.0f) - ) - ), - 16 * sizeof(float) - ); - calculateMatrix = true; + SetRotation(glm::vec3(rotX, rotY, rotZ)); } void Transformable::SetRotation(const float* rotation) { - memcpy( - this->rotation, - glm::value_ptr( - glm::rotate( - glm::rotate( - glm::rotate( - glm::mat4(1.0f), glm::radians(rotation[0]), glm::vec3(1.0f, 0.0f, 0.0f) - ), glm::radians(rotation[1]), glm::vec3(0.0f, 1.0f, 0.0f) - ), glm::radians(rotation[2]), glm::vec3(0.0f, 0.0f, 1.0f) - ) - ), - 16 * sizeof(float) - ); - calculateMatrix = true; + SetRotation(glm::make_vec3(rotation)); + } + + void Transformable::SetRotation(const glm::vec3& rotation) + { + glm::decompose(transformation, scale, orientation, translation, skew, perspective); + orientation = glm::quat(glm::radians(rotation)) * (-orientation); + transformation = glm::rotate(transformation, glm::angle(orientation), glm::axis(orientation)); } void Transformable::SetRotation(float angle, float xAxis, float yAxis, float zAxis) { - memcpy( - this->rotation, - glm::value_ptr(glm::rotate(glm::mat4(1.0f), glm::radians(angle), glm::vec3(xAxis, yAxis, zAxis))), - 16 * sizeof(float) - ); - calculateMatrix = true; + SetRotation(angle, glm::vec3(xAxis, yAxis, zAxis)); } void Transformable::SetRotation(float angle, const float* axis) { - memcpy( - this->rotation, - glm::value_ptr(glm::rotate(glm::mat4(1.0f), glm::radians(angle), glm::make_vec3(axis))), - 16 * sizeof(float) - ); - calculateMatrix = true; + SetRotation(angle, glm::make_vec3(axis)); + } + + void Transformable::SetRotation(float angle, const glm::vec3& axis) + { + glm::decompose(transformation, scale, orientation, translation, skew, perspective); + orientation = glm::angleAxis(glm::radians(angle), axis) * (-orientation); + transformation = glm::rotate(transformation, glm::angle(orientation), glm::axis(orientation)); } void Transformable::SetScale(float scaleX, float scaleY, float scaleZ) { - this->scaling[0] = scaleX; - this->scaling[1] = scaleY; - this->scaling[2] = scaleZ; - calculateMatrix = true; + SetScale(glm::vec3(scaleX, scaleY, scaleZ)); } void Transformable::SetScale(const float* scale) { - memcpy( - this->scaling, - scale, - 3 * sizeof(float) - ); - calculateMatrix = true; + SetScale(glm::make_vec3(scale)); + } + + void Transformable::SetScale(const glm::vec3& scale) + { + glm::decompose(transformation, this->scale, orientation, translation, skew, perspective); + this->scale = scale / this->scale; + if (this->scale.x == INFINITY) this->scale.x = scale.x; + if (this->scale.y == INFINITY) this->scale.y = scale.y; + if (this->scale.z == INFINITY) this->scale.z = scale.z; + transformation = glm::scale(transformation, this->scale); } void Transformable::Move(float x, float y, float z) { - this->position[0] += x; - this->position[1] += y; - this->position[2] += z; - calculateMatrix = true; + Move(glm::vec3(x, y, z)); } void Transformable::Move(const float* translation) { - this->position[0] += translation[0]; - this->position[1] += translation[1]; - this->position[2] += translation[2]; - calculateMatrix = true; + Move(glm::make_vec3(translation)); + } + + void Transformable::Move(const glm::vec3& translation) + { + transformation = glm::translate(transformation, translation); + glm::decompose(transformation, scale, orientation, this->translation, skew, perspective); } void Transformable::Rotate(float rotX, float rotY, float rotZ) { - memcpy( - this->rotation, - glm::value_ptr( - glm::rotate( - glm::rotate( - glm::rotate( - glm::make_mat4(this->rotation), glm::radians(rotX), glm::vec3(1.0f, 0.0f, 0.0f) - ), glm::radians(rotY), glm::vec3(0.0f, 1.0f, 0.0f) - ), glm::radians(rotZ), glm::vec3(0.0f, 0.0f, 1.0f) - ) - ), - 16 * sizeof(float) - ); - calculateMatrix = true; + Rotate(glm::vec3(rotX, rotY, rotZ)); } void Transformable::Rotate(const float* rotation) { - memcpy( - this->rotation, - glm::value_ptr( - glm::rotate( - glm::rotate( - glm::rotate( - glm::make_mat4(this->rotation), glm::radians(rotation[0]), glm::vec3(1.0f, 0.0f, 0.0f) - ), glm::radians(rotation[1]), glm::vec3(0.0f, 1.0f, 0.0f) - ), glm::radians(rotation[2]), glm::vec3(0.0f, 0.0f, 1.0f) - ) - ), - 16 * sizeof(float) - ); - calculateMatrix = true; + Rotate(glm::make_vec3(rotation)); + } + + void Transformable::Rotate(const glm::vec3& rotation) + { + glm::quat rot = glm::quat(glm::radians(rotation)); + transformation = glm::rotate(transformation, glm::angle(rot), glm::axis(rot)); + glm::decompose(transformation, scale, orientation, translation, skew, perspective); } void Transformable::Rotate(float angle, float xAxis, float yAxis, float zAxis) { - memcpy( - this->rotation, - glm::value_ptr(glm::rotate(glm::make_mat4(this->rotation), glm::radians(angle), glm::vec3(xAxis, yAxis, zAxis))), - 16 * sizeof(float) - ); - calculateMatrix = true; + Rotate(angle, glm::vec3(xAxis, yAxis, zAxis)); } void Transformable::Rotate(float angle, const float* axis) { - memcpy( - this->rotation, - glm::value_ptr(glm::rotate(glm::make_mat4(this->rotation), glm::radians(angle), glm::make_vec3(axis))), - 16 * sizeof(float) - ); - calculateMatrix = true; + Rotate(angle, glm::make_vec3(axis)); + } + + void Transformable::Rotate(float angle, const glm::vec3& axis) + { + transformation = glm::rotate(transformation, glm::radians(angle), axis); + glm::decompose(transformation, scale, orientation, translation, skew, perspective); } void Transformable::Scale(float scaleX, float scaleY, float scaleZ) { - this->scaling[0] += scaleX; - this->scaling[1] += scaleY; - this->scaling[2] += scaleZ; - calculateMatrix = true; + Scale(glm::vec3(scaleX, scaleY, scaleZ)); } void Transformable::Scale(const float* scale) { - this->scaling[0] += scale[0]; - this->scaling[1] += scale[1]; - this->scaling[2] += scale[2]; - calculateMatrix = true; + Scale(glm::make_vec3(scale)); } - const float* Transformable::GetMatrix() + void Transformable::Scale(const glm::vec3& scale) { - if (calculateMatrix) - { - memcpy( - transformation, - glm::value_ptr(glm::translate(glm::mat4(1.0f), glm::make_vec3(position)) * glm::make_mat4(rotation) * glm::scale(glm::mat4(1.0f), glm::make_vec3(scaling))), - 16 * sizeof(float) - ); - calculateMatrix = false; - } + transformation = glm::scale(transformation, scale); + glm::decompose(transformation, this->scale, orientation, translation, skew, perspective); + } + const glm::mat4& Transformable::GetMatrix() + { return transformation; } - const float* Transformable::GetPosition() const + const glm::vec3& Transformable::GetPosition() const { - return position; + return translation; } - const float* Transformable::GetRotation() const + const glm::quat& Transformable::GetRotation() const { - return rotation; + return orientation; } - const float* Transformable::GetScaling() const + const glm::vec3& Transformable::GetScaling() const { - return scaling; + return scale; } }