athanggupte / ApexGameEngine

Apex Game Engine
MIT License
4 stars 1 forks source link

Improve rotation transformation using Quaternions #34

Closed athanggupte closed 2 years ago

athanggupte commented 2 years ago

Currently in TransformComponent the final rotation matrix is calculated by multiplying rotation matrices with respect to each axis as seen here.

This is inefficient and also has improper rotation effect as rotation in Z axis us applied after Y axis which is after X axis.

An alternative is to convert the Euler angles to quaternion and to get the Mat4 from that.

P.S. this might not solve the axis precedence issue.

#define GLM_ENABLE_EXPERIMENTAL
#include <glm/gtx/quaternion.hpp>

glm::mat4 rotationMatrix = glm::toMat4(glm::quat(rotation));