jaisor
asked on
How can I use the Model Matrix to determine where and how was a vector rotated?
Here is my problem. I know the rotation (angleX, angleY) of a vector, and I can create a matrix that completes that rotation or I can use glRotatef() and let OpenGL make the matrix for me. Then I can retrieve that matrix with let say
glGetDoublev(GL_MODELVIEW_ MATRIX, modelMatrix);
After that I try to apply that matrix to a vector - and to retrieve the new vector coordinates and there comes the problem - IT IS NEVER ACCURATE. If I let opengl transform the vector everything works fine, but when I try to multiply my vector with the matrix - the new coordinates are off.
Here is the part of my code:
void Rotate(GLfloat angle, GLfloat x, GLfloat y, CVector3D &vView)
{
GLfloat n[16];
glPushMatrix();
glRotatef(angle,x,y,0.0);
glGetFloatv(GL_MODELVIEW_M ATRIX, n);
glPopMatrix();
GLfloat v1[4],v2[4];
v1[0] = vView.X();
v1[1] = vView.Y();
v1[2] = vView.Z();
v1[3] = 1;
GLfloat sum;
int index, alpha;
for (index = 0; index < 4; index++)
{
sum= 0;
for (alpha = 0; alpha < 4; alpha++)
sum += n[index + alpha*4] * v1[alpha];
v2[index] = (float)sum;
}
vView = CVector3D(v2[0], v2[1], v2[2]);
}
This function is supposed to rotate the velocity vector for the particle from a rotation angle.
Please help
glGetDoublev(GL_MODELVIEW_
After that I try to apply that matrix to a vector - and to retrieve the new vector coordinates and there comes the problem - IT IS NEVER ACCURATE. If I let opengl transform the vector everything works fine, but when I try to multiply my vector with the matrix - the new coordinates are off.
Here is the part of my code:
void Rotate(GLfloat angle, GLfloat x, GLfloat y, CVector3D &vView)
{
GLfloat n[16];
glPushMatrix();
glRotatef(angle,x,y,0.0);
glGetFloatv(GL_MODELVIEW_M
glPopMatrix();
GLfloat v1[4],v2[4];
v1[0] = vView.X();
v1[1] = vView.Y();
v1[2] = vView.Z();
v1[3] = 1;
GLfloat sum;
int index, alpha;
for (index = 0; index < 4; index++)
{
sum= 0;
for (alpha = 0; alpha < 4; alpha++)
sum += n[index + alpha*4] * v1[alpha];
v2[index] = (float)sum;
}
vView = CVector3D(v2[0], v2[1], v2[2]);
}
This function is supposed to rotate the velocity vector for the particle from a rotation angle.
Please help
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER