Skip to content
Snippets Groups Projects
Commit 035a4566 authored by Joseph Walton-Rivers's avatar Joseph Walton-Rivers
Browse files

more cleanup of the Tranform component

parent a4d9b349
No related branches found
No related tags found
No related merge requests found
......@@ -53,6 +53,10 @@ namespace fggl::math {
constexpr static const math::mat4 IDENTITY_M4 {1.0F};
constexpr static const math::quat IDENTITY_Q {1.0F, 0.0, 0.0, 0.0};
constexpr static const math::vec3 AXIS_X { 1.0F, 0.0F, 0.0F };
constexpr static const math::vec3 AXIS_Y { 0.0F, 1.0F, 0.0F };
constexpr static const math::vec3 AXIS_Z { 0.0F, 0.0F, 1.0F };
// fastFloor from OpenSimplex2
inline int fastFloor(double x) {
int xi = (int) x;
......@@ -160,10 +164,11 @@ namespace fggl::math {
return m_euler;
}
inline mat4 model() const {
const glm::mat4 transformX = glm::rotate( math::IDENTITY_M4,glm::radians(m_euler.x), glm::vec3(1.0f, 0.0f, 0.0f) );
const glm::mat4 transformY = glm::rotate( math::IDENTITY_M4, glm::radians(m_euler.y), glm::vec3(0.0f, 1.0f, 0.0f) );
const glm::mat4 transformZ = glm::rotate( math::IDENTITY_M4, glm::radians(m_euler.z), glm::vec3(0.0f, 0.0f, 1.0f) );
[[nodiscard]]
inline mat4 local() const {
const glm::mat4 transformX = glm::rotate( math::IDENTITY_M4,glm::radians(m_euler.x), AXIS_X );
const glm::mat4 transformY = glm::rotate( math::IDENTITY_M4, glm::radians(m_euler.y), AXIS_Y );
const glm::mat4 transformZ = glm::rotate( math::IDENTITY_M4, glm::radians(m_euler.z), AXIS_Z );
const auto rotation = transformY * transformX * transformZ;
return glm::translate(math::IDENTITY_M4, m_origin)
......@@ -171,12 +176,20 @@ namespace fggl::math {
* glm::scale( math::IDENTITY_M4, m_scale );
}
[[nodiscard]]
inline mat4 model() const {
return local();
}
inline void update(const math::mat4& parent) {
m_model = parent * local();
}
private:
mat4 m_model; // us -> world
vec3 m_origin;
vec3 m_euler;
vec3 m_scale;
};
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment