Solved

# How can I use the Model Matrix to determine where and how was a vector rotated?

Posted on 2003-02-18
Medium Priority
740 Views
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_MATRIX, 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.

0
Question by:jaisor
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points

LVL 5

Accepted Solution

Insolence earned 800 total points
ID: 7985419
That code works perfectly for what you are doing.  Your code is all messed up somewhere else!  If you rotating the velocity vector for the particle make sure that you are not rotating the entire world with it.  =P
0

Author Comment

ID: 7985426
Thank you master for your infinite wizdom. You were right I was messing up somewhere else and not taking the global matrix in consideration.
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

As game developers, we quickly learn that Artificial Intelligence (AI) doesn’t need to be so tough.  To reference Space Ghost: “Moltar, I have a giant brain that is able to reduce any complex machine into a simple yes or no answer. (http://www.youtu…
Recently, in one of the tech-blogs I usually read, I saw a post about the best-selling video games through history. The first place in the list is for the classic, extremely addictive Tetris. Well, a long time ago, in a galaxy far far away, I was…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
###### Suggested Courses
Course of the Month9 days, 9 hours left to enroll