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.

Recommended Posts

How can I achieve this effect in OpenGL using gluProject and gluUnProject? http://www.geocities.com/raydog314

Share on other sites
use glOrtho projection for rendering axises

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 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 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 on other sites
Quote:
 Original post by raydogNo, 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 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 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 on other sites
Quote:
 Original post by raydogI 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 on other sites
why not simply "AxisLength *= DistanceToCamera"

or something similar...?

1. 1
Rutin
69
2. 2
3. 3
4. 4
5. 5

• 21
• 10
• 33
• 20
• 9
• Forum Statistics

• Total Topics
633430
• Total Posts
3011831
• Who's Online (See full list)

There are no registered users currently online

×