Click here to Skip to main content
15,936,897 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi there,
I have an openGL application that works nice: moving the scene, panning, zooming etc works well. Now I like to display a small coordinate system marker (3 arrows) in the bottom/left corner of the view area - which stays there, no matter how the scene is moved, panned or zoomed. I guess I need to tie an OGL object on raster coordinates, but what I tried is either not visible, or is still moved with the scene.

Can please anyone point me into the right direction ? thank you
Matthias
Posted

Howdy,

I haven't used the function myself, though it seems that gluUnproject would be a function you need to use.

using gluUnproject - NeHe[^]
http://www.opengl.org/sdk/docs/man/xhtml/gluUnProject.xml[^]

I guess you'd just (arbitrarily?) select a depth, then substitute the mouse coords for the known desired coords of your coord system marker. (using the nehe example)
 
Share this answer
 
Comments
matthiasD42 18-Apr-12 2:14am    
Hi, thanks, gluUnproject() works well - but I'm experiencing a funny behaviour: my GL scene is scaled into -1 ... +1 coordinates and my coordinate system marker arrows have length of 0.1. The depth winZ=0 creates a huge arrow, only the base part is visible. Changing winZ towards 1.0 shows a very exponential behaviour: the optimum values for winZ=0.9997 - its ok for my, but I'd like understand this, is this because depth is related to the perspective of my view ?
thanks again, Matthias
enhzflep 18-Apr-12 2:38am    
Hi. Great!
Sorry, I'm not sure of the answer and am a little hazy to really think the problem through at the moment.

However, since the screen-coords depend on a 1/Z relationships somewhere (in the viewing transofrm) it seems that this is likely the case. Recalling the old demo-effect of a 3d star-field, at a great distance from the camera the stars will be grouped around the center of the screen. The changes in screen x,y as compared to the change in 3d z pos is the greatest when objects are closest to the camera. That is to say, as they draw nearer, the stars creep creep slowly towards the edges of the screen. As the distance from the camera decreases, the stars move more and more rapidly towards the screen edge.

Perhaps it would be worth considering drawing the axis-marker without perspective? It seems that this is the default (only?) behaviour for 3d content creation programs - e.g Blender, Maya, 3DS Max
It sure would make positioning it dead easy - just draw at ~(-0.8, -0.8, arbitraryZ) and you'd still have 0.1 units (5% of screen width) between the marker and the edge of the screen.

Cheers!
Simon.
You can do it with drawing lines (glBegin(GL_LINES)) . You should do it after drawing all other scene data. And also make sure that your scene transformations will not effect the axis drawing.

it will be like this

glPushMatrix()
DrawScene() // All scene drawing goes here.
glPopMatrix()
glPushMatrix()
glTranslatef( adjust the coordinates such that axis are at correct position)
DrawAxis() // draw axis will use lines.
glPopMatrix()

This will work. One more thing , don't mix up Opengl with GDI.
if you still want to modifu frame buffer use glDrawPixels

Hopes this helps

jkchan
cgmath.blogspot.com[^]
 
Share this answer
 
Comments
Madhan Mohan Reddy P 15-Apr-13 7:38am    
Hey , I am getting infinite lines for my coordinate system.. can anybody tell me why ?

code snippet
double[] m = new double[16];
gl.GetDoublev(gl.MODELVIEW_MATRIX, m);
gl.LoadIdentity();
gl.PushMatrix();
gl.Translated(CurrentViewPortData.clipX - dd * 0.8, CurrentViewPortData.clipY - dd * 0.8, CurrentViewPortData.sphereRadius * 49.0);
gl.MultMatrixd(m);

gl.LineWidth(2.000000f);
gl.MatrixMode(gl.MODELVIEW);
gl.Begin(gl.LINES);
{
gl.Color3f(1.000000f, 0.000000f, 0.000000f);
gl.Vertex3d(0, 0, 0);
gl.Vertex3d(1, 0, 0);
gl.Color3f(0.000000f, 1.000000f, 0.000000f);
gl.Vertex3d(0, 0, 0);
gl.Vertex3d(0, 1, 0);
gl.Color3f(0.000000f, 0.000000f, 1.000000f);
gl.Vertex3d(0, 0, 0);
gl.Vertex3d(0, 0, 1);
}
gl.End();
gl.PopMatrix();

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900