I have a class that manipulates a model matrix in opengl:
class ModelObject {
private:
mat4 ScaleMatrix;
mat4 RotationMatrix;
mat4 TranslationMatrix;
public:
vec3 angles;
float size;
vec3 pos;
. . .
}
I have a function that rotates object around its local axises
void rotateLocal(vec3 euler_angles)
{
quat qY = angleAxis(euler_angles.y, getUpv());
mat4 rY = toMat4(qY);
RotationMatrix = rY * RotationMatrix;
quat qZ = angleAxis(euler_angles.z, getFrontv());
mat4 rZ = toMat4(qZ);
RotationMatrix = rZ * RotationMatrix;
quat qX = angleAxis(euler_angles.x, getRightv());
mat4 rX = toMat4(qX);
RotationMatrix = rX * RotationMatrix;
}
But I cannot figure out how to make it change angles property correctly. Many formulas that calculate final euler angles do not work properly. Here is another function that also rotates object, but around global axises
void rotate(vec3 angles)
{
mat4 newRotation = toMat4(quat(angles));
RotationMatrix = newRotation * RotationMatrix;
this->angles += angles;
}
I want rotateLocal also to be syncronized with angles