Jump to content
  • Advertisement
Sign in to follow this  
humpolec

OpenGL OpenGL and coordinate transformations

This topic is 3708 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 see OpenGL has a very convenient set of matrix operations, which allows programmer to render an arbitrary object in whatever position/rotation/scale they want... but what if I want to actually know the coordinates in some common reference system? For example, I render a complex 3D model at a given position and rotated by a given angle, and want to know world coordinates of its points (for example, to perform collision detection). Is there a way I can use OpenGL for that, or do I have to do all the math again myself? And if I have to do it myself, what is the most common way to do it in C++? Write my own set of functions, or is there some simple library for that?

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by humpolec
I see OpenGL has a very convenient set of matrix operations, which allows programmer to render an arbitrary object in whatever position/rotation/scale they want...
but what if I want to actually know the coordinates in some common reference system? For example, I render a complex 3D model at a given position and rotated by a given angle, and want to know world coordinates of its points (for example, to perform collision detection). Is there a way I can use OpenGL for that, or do I have to do all the math again myself?
And if I have to do it myself, what is the most common way to do it in C++? Write my own set of functions, or is there some simple library for that?
You'll need to do the math yourself. Note however that collision detection is usually performed using simplified collision proxies (such as boxes, spheres, etc.) rather than the actual geometry itself.

As for how to do this, you can write your own code, or use an existing math library. There's no 'standard' to speak of when it comes to C++ and OpenGL, but you can find a list of free math libraries here.

Share this post


Link to post
Share on other sites
To answer to your first question, you can get the result matrix of the OpenGL stack via
float pMatrix[16];
glFlush();
glMatrixMode(GL_MODELVIEW);
glGetFloatv(GL_MODELVIEW_MATRIX, pMatrix);

Then you just have muplitply your point with the matrix to get the position in 3D space. (Or you can get the result by doing a glTranslate of your point as the last operation in the OpenGL Stack and read the translation from the matrix).

That's for your question, personnaly, I think that it's best (and faster) to no use the OpenGL stack since you will certainly need the real position of your object in 3D space for your application and glGetFloatv is not the fastest way to have it. ^^

Doing the math by yourself is not really hard but you may have to do some SSE/SSE2 code (available in C++) to get the best performance or you can use Boost which is well known to be quite powerfull.

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!