Jump to content
  • Advertisement
Sign in to follow this  
myranalis

OpenGL Getting the eye coordinates of an object

This topic is 3720 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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";

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!