Hey all, I’m having an annoying problem and so I decided to register to see if anybody can help me
I’m new to openGL, so go easy on me
What I am doing is trying to rotate a rigid body, in this case a cube made of quads. I am using a rotation matrix to rotate the body.
Now if I use glMultMatrixd(), the cube rotates perfectly. But, if my understanding is correct, that simply rotates the world and not the cube, and so technically isn’t correct. Never the less, I am working on collision detection and response, so I need to be able to access the rotated vertices of the rigid body, which glMultMatrixd() won’t let me do.
Instead, I want to rotate each vertex of the cube by the rotation matrix. This works fine unless the cube is rotating about all three axis, in which case it will lose one axis of rotation.
Here is a video where you can see the problem. YouTube - Rotation Problem
The rotation matrix is the same when using both methods.
Does anybody know what might be causing this?
Here is the code, the matrix is a 3X3 matrix by the way.
for (int i = 0; i < 24; i++)
{
vertex = *vertices[i];
// Rotate the vertex
vertex = orientation * vertex;
// Apply the vertex
glVertex3f( vertex.x(), vertex.y(), vertex.z());
}
// Multiplying a matrix by a vector
inline Vector operator* (const matrixn3& m, const Vector& v)
{
Vector res;
res.x() = m.c(1,1) * v.x() + m.c(1,2) * v.y() + m.c(1,3) * v.z();
res.y() = m.c(2,1) * v.x() + m.c(2,2) * v.y() + m.c(2,3) * v.z();
res.z() = m.c(3,1) * v.x() + m.c(3,2) * v.y() + m.c(3,3) * v.z();
return res;
}