Here's my code:
vec4 qx, qy, qz;
mat4 mx, my, mz;
// rotating using quaternions
glm_quat(qx, to_radians(a->rx), 1.0f, 0.0f, 0.0f);
glm_quat(qy, to_radians(a->ry), 0.0f, 1.0f, 0.0f);
glm_quat(qz, to_radians(a->rz), 0.0f, 0.0f, 1.0f);
// turning the quaternions into matrices
glm_quat_mat4(qx, mx);
glm_quat_mat4(qy, my);
glm_quat_mat4(qz, mz);
mat4 trans = {
1, 0, 0, 0,
0, 1, 0, 0,
0, 0, 1, 0,
0, 0, 0, 1
};
mat4 rot = {
1, 0, 0, 0,
0, 1, 0, 0,
0, 0, 1, 0,
0, 0, 0, 1
};
mat4 final;
// combining the rotations into one.
glm_mat4_mulN((mat4* []){&mx, &my, &mz}, 3, rot);
// translating the `trans` matrix.
glm_translate(trans, (vec3){ a->x, a->y, a->z });
// finally combining the translation with the rotation into one.
glm_mat4_mul(trans, rot, final);
My desired behavior is that the object rotates around its center, but here is what happens instead:
So , it seems that my object is rotating around some weird other undefined point. I have no idea why this happens.
Any ideas? Thank you.