kored
November 19, 2023, 7:54pm
1
My cube has the right proportions when rotated around the x, y, or z axis, exclusively.
However, when I combine the axes, the cube distorts during rotation.
What would cause this?
My code for this rotation, looks like this:
void OpenGLClass::MatrixRotationXYZ(
float* matrix, const float& angle) {
matrix[0] = cosf(angle); matrix[1] = sinf(angle); matrix[2] = -sinf(angle); matrix[3] = 0.0f;
matrix[4] = -sinf(angle); matrix[5] = cosf(angle); matrix[6] = -sinf(angle); matrix[7] = 0.0f;
matrix[8] = sinf(angle); matrix[9] = sinf(angle); matrix[10] = cosf(angle); matrix[11] = 0.0f;
matrix[12] = 0.0f; matrix[13] = 0.0f; matrix[14] = 0.0f; matrix[15] = 1.0f;
return;
}
Might it have anything to do with my PerspectiveFovLHMatrix?
matrix[0] = 1.0f / (screenAspect * tan(fieldOfView * 0.5f));
matrix[1] = 0.0f;
matrix[2] = 0.0f;
matrix[3] = 0.0f;
matrix[4] = 0.0f;
matrix[5] = 1.0f / tan(fieldOfView * 0.5f);
matrix[6] = 0.0f;
matrix[7] = 0.0f;
matrix[8] = 0.0f;
matrix[9] = 0.0f;
matrix[10] = screenDepth / (screenDepth - screenNear);
matrix[11] = 1.0f;
matrix[12] = 0.0f;
matrix[13] = 0.0f;
matrix[14] = (-screenNear * screenDepth) / (screenDepth - screenNear);
matrix[15] = 0.0f;
Or, something else?
That does not look like a rotation matrix to me, see e.g. this article .
kored
November 19, 2023, 11:52pm
3
It sure doesn’t.
Someone said to just combine the x, y, and z rotations, so I tried something, without knowing what I was doing.
Your link was very helpful. Especially General 3D Rotations .
I got something.
Only, it’s not exactly the rotation I was looking for, but now I know what I am doing, and the cube maintains proper proportion.
void OpenGLClass::MatrixRotationXYZ(
float* matrix, const float& angle, const float& angleX, const float& angleY, const float& angleZ) {
matrix[0] = cosf(angle) * cosf(angle);
matrix[1] = cosf(angle) * sinf(angle) * sinf(angle) - sinf(angle) * cosf(angle);
matrix[2] = cosf(angle) * sinf(angle) * cosf(angle) + sinf(angle) * sinf(angle);
matrix[3] = 0.0f;
matrix[4] = sinf(angle) * cosf(angle);
matrix[5] = sinf(angle) * sinf(angle) * sinf(angle) + cosf(angle) * cosf(angle);
matrix[6] = sinf(angle) * sinf(angle) * cosf(angle) - cosf(angle) * sinf(angle);
matrix[7] = 0.0f;
matrix[8] = -sinf(angle);
matrix[9] = cosf(angle) * sinf(angle);
matrix[10] = cosf(angle) * cosf(angle);
matrix[11] = 0.0f;
matrix[12] = 0.0f;
matrix[13] = 0.0f;
matrix[14] = 0.0f;
matrix[15] = 1.0f;
return;
}
Thanks.
Another Khronos forums success story, woo!