Jump to content
  • Advertisement
Sign in to follow this  
raydog

OpenGL gluProject/gluUnProject

This topic is 5204 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

Advertisement
Guest Anonymous Poster
use glOrtho projection for rendering axises

Share this post


Link to post
Share on other sites
That's not exactly helpful. Need a little more explanation than that, either pseudo code or whatever.

And if you mean draw it in 2D using glOrtho, then no, I don't think that is correct.

I think it's drawn in 3D, because the axes has depth, as you can see by the last image showing
the axes being rendered straight on. As well as the axes are clipped by the camera view, when
the camera is pointing somewhere else.

So, if these axes are drawn in 3D, how to determine the lengths of these axes in 3D?

Share this post


Link to post
Share on other sites
glOrtho isn't just used for 2D, it's an orthographic projection. Basically this means that objects don't get smaller when they get further away. But if that's not it, then there's another alternative.
It might be that it's simply done by calculating the distance to the object (can be done by retrieving the modelview matrix and checking the translation) and then just scaling based on this distance. Does that make sense?

Share this post


Link to post
Share on other sites
No, I don't believe the axes are drawn in glOrtho, because then the axes lines would be distorted.
(e.g. the lines wouldn't match with its perspective view grid lines). I am 99.9% certain it is drawn
in 3D, I just don't know how.

Quote:

It might be that it's simply done by calculating the distance to the object (can be done by retrieving the modelview matrix and checking the translation) and then just scaling based on this distance. Does that make sense?


No, not really. :)

The lines are drawn in 3D because:
1. Axes are clipped appropriately.
2. Axes are distorted appropriately.
3. Axes lines show depth as the camera is rotated around them.

The problem is how to calculate their length in 3D, while keeping their screen space 2D length relatively constant.

Share this post


Link to post
Share on other sites
Quote:
Original post by raydog
No, I don't believe the axes are drawn in glOrtho, because then the axes lines would be distorted.
(e.g. the lines wouldn't match with its perspective view grid lines). I am 99.9% certain it is drawn
in 3D, I just don't know how.

Ok, so it's drawn with perspective projection.

Quote:
Quote:

It might be that it's simply done by calculating the distance to the object (can be done by retrieving the modelview matrix and checking the translation) and then just scaling based on this distance. Does that make sense?


No, not really. :)

Ok... :)
Say you have the arrows showing the axis defined at the origin (i.e. so that the arrows meet at (0,0,0).)
You do the viewing transformation (gluLookAt or whatever) and then possibly a modelling transformation (if the arrows can be moved.)
Get the modelview matrix with glGetDoublev or glGetFloatv.
The position of the object relative to the viewer will be stored in the matrix, indices 12, 13 and 14. Use this to calculate the distance from the viewer to the arrows.
Call glScalef with this distance as scale.
Draw the arrows.
You will still see an effect of the perspective projection, but the arrows won't get smaller as they get farther away. Right?

Share this post


Link to post
Share on other sites
If I understand you correctly, you're suggesting that I use the distance from the camera's eye to the origin
of the local axis as function of scale?

I don't think that would work so good, as there can many be different local axes everywhere, and
they all would be at different distances from the camera's eye, giving me different scales.

Share this post


Link to post
Share on other sites
>>If I understand you correctly, you're suggesting that I use the distance from the camera's eye to the origin
of the local axis as function of scale?<<

yes in all the screenshots there is perspction (but very small i guess a FOV 40 degrees) so it seems to be in orthogonal projection.
so as someone suggested, draw the world (grid objects etc) and then for the 3 color axis just measure the distance from the origin to the camera's position and then draw the length of the lines of the axis based on that

Share this post


Link to post
Share on other sites
Quote:
Original post by raydog
I don't think that would work so good, as there can many be different local axes everywhere, and
they all would be at different distances from the camera's eye, giving me different scales.

So what? You will scale them differently, but since they are at different distances I fail to see what the problem is.

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!