Monday, October 3, 2022
HomeGame Developmentopengl - How you can calculate angles after subsequent rotations?

opengl – How you can calculate angles after subsequent rotations?


I’ve a category that manipulates a mannequin matrix in opengl:

class ModelObject {
personal:
    mat4 ScaleMatrix;
    mat4 RotationMatrix;
    mat4 TranslationMatrix;

public:
    vec3 angles;
    float dimension;
    vec3 pos;
    . . .
}

I’ve a operate that rotates object round its native 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;
}

However I can’t work out how one can make it change angles property accurately. Many formulation that calculate last euler angles don’t work correctly. Right here is one other operate that additionally rotates object, however round international axises

void rotate(vec3 angles)
{
    mat4 newRotation = toMat4(quat(angles));
    RotationMatrix = newRotation * RotationMatrix;

    this->angles += angles;
}

I would like rotateLocal additionally to be syncronized with angles

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments