PDA

View Full Version : Reading the state of the model matrix

Nelne
06-12-2011, 06:14 AM
Hi,

I've been trying to get my hands on the state of the model matrix. I found some recommendations from old discussion and here's what I did to test them:

GLdouble modelMatrix[16];

glPushMatrix();
cout << "Before transformations" << endl;
glGetDoublev(GL_MODELVIEW, modelMatrix);
for(int i = 0; i < 16; i++)
{
if(i % 4 == 0)
cout << endl;
cout << modelMatrix[i] << " ";
}
cout << endl;

glTranslatef(1.0f, 2.0f, 3.0f);
glRotatef(shoot_angle_y, 0.0f, 1.0f, 0.0f);
glRotatef(shoot_angle_x, 1.0f, 0.0f, 0.0f);
glTranslatef(0.0f, -2.0f, -1.0f);

cout << "After transformations" << endl;
glGetDoublev(GL_MODELVIEW, modelMatrix);
for(int i = 0; i < 16; i++)
{
if(i % 4 == 0)
cout << endl;
cout << modelMatrix[i] << " ";
}
cout << endl;

glutSolidSphere(0.27f, 32, 32);

cout << "After drawing something" << endl;
glGetDoublev(GL_MODELVIEW, modelMatrix);
for(int i = 0; i < 16; i++)
{
if(i % 4 == 0)
cout << endl;
cout << modelMatrix[i] << " ";
}
cout << endl;
glPopMatrix();

The problem is all the loops print this:

-9.25596e+061 -9.25596e+061 -9.25596e+061 -9.25596e+061
-9.25596e+061 -9.25596e+061 -9.25596e+061 -9.25596e+061
-9.25596e+061 -9.25596e+061 -9.25596e+061 -9.25596e+061
-9.25596e+061 -9.25596e+061 -9.25596e+061 -9.25596e+061

So it seems like I'm either unable to change the state of the matrix or I still don't know how to read it. Probably the latter one since the vertices do move accordingly. Please help me. Do I do something wrong in my code or have I misunderstood something?

ravage
06-12-2011, 12:06 PM
glGetDoublev(GL_MODELVIEW_MATRIX, modelMatrix);