Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++ OpenGL
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 17-Apr-12 14:15pm
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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)
  Permalink  
Comments
matthiasD42 at 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 at 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.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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[^]
  Permalink  
Comments
Madhan Mohan Reddy at 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)

  Print Answers RSS
0 OriginalGriff 515
1 Maciej Los 340
2 Richard MacCutchan 265
3 BillWoodruff 225
4 Mathew Soji 155
0 OriginalGriff 8,804
1 Sergey Alexandrovich Kryukov 7,457
2 DamithSL 5,689
3 Maciej Los 5,279
4 Manas Bhardwaj 4,986


Advertise | Privacy | Mobile
Web01 | 2.8.1411028.1 | Last Updated 18 Apr 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100