Getting the eye coordinates of an object

Started by
3 comments, last by myranalis 15 years, 11 months ago
I apologise for a very basic post but I haven't been able to figure this one out on my own. I've got basic cubes that I've scaled, translated, rotated... I want to be able to find out what the final coordinates of the cube are after all these transformations have been applied. I *thought* I could use something like the code below to get the matrix that was being applied to my object vertexes and multiply it with the vertex of interest to get its final location, but I think the results in the modelview array are not sensible for the parameters I've put in for the transformations. Using only scaling and translating, I get a matrix of all 0s. When I add the rotation I get the matrix below. Note: the transformations draw correctly on screen and I haven't got any errors from OpenGL. Am I on the right track? Id appreciate any feedback someone can give me! Thanks, Anna Code to get the modelview matrix: glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glRotatef(90, 0.0, 1.0, 0.0); glTranslatef(1.0, 1.0, 1.0); glScalef(3.0, 1.0, 1.0); GLfloat modelview[16]; glGetFloatv(GL_MODELVIEW_MATRIX, modelview); ModelView matrix with rotation 0: -2147483648 1: 0 2: 0 3: 0 4: 0 5: 0 6: 0 7: 0 8: 0 9: 0 10: -1073741824 11: 0 12: 0 13: 0 14: 0 15: 0
Advertisement
I don't see anything wrong with the code you posted, so the error must be some place else. Perhaps in the code that prints the array?
That code is:

printf("modelview matrix\n");
for (int i = 0; i < 16; i++)
printf("%d: %d \n", i, modelview);
Try this instead:
printf("modelview matrix\n");for (int i = 0; i < 16; i++)  printf("%d: %f \n", i, modelview);

%d is for integers, but you've got an array of floats.
Or if you're using C++, this is much better:
std::cout << "modelview matrix\n";for (int i = 0; i < 16; i++)  std::cout << i << ": " << modelview << "\n";

Ack! I spent all day researching the modelview matrix and its my dodgy c++ !

thank you!

This topic is closed to new replies.

Advertisement