PDA

View Full Version : How can I draw a coordinate axes fixed on the left-lower of the graphics window?



amhigh
12-21-2002, 06:46 AM
Hi Everyone:

I am using the MFC to write a graphics application using OpenGL on Window XP. I want draw a coordinate axes (the X-Y-Z coordinate) fixed on my left-lower corner of my application. In other word, even an object is very far away from the origin, when this object is ploted (on the center of the screen), on the left-lower corner of the screen, there will be always a coordinate axes to show the orentation. How can do this request? If I rotate the object, the axes on the left-lower corner will rotate, but if I zoom or translate the object, the coordinate axes will stand still on the left-lower coner. How can I do this?

Also, if I know how to draw the "X","Y","Z" on the screen, how can I put the X-Y-Z at the end of these axes (the coordiate system on the left-lower corner)?

Thanks for all the hints and suggestion.

V-man
12-21-2002, 07:12 AM
You can switch to an orthographic projection, turn off z tests, and draw your axis. You can make a texture with the needed letters and then and draw the letters on the arrows.

That's one way.

V-man

amhigh
12-21-2002, 08:00 AM
Originally posted by V-man:
You can switch to an orthographic projection, turn off z tests, and draw your axis. You can make a texture with the needed letters and then and draw the letters on the arrows.

That's one way.

V-man

Thanks,
Would that be possible to have more detail description?

I am using the ortho3d projection. Let say I have an object to plot, and because it is very far away from the origin, and in order to plot this object in the center of the graphics screen, I have obtained a transformation matrix that I can rotate with the center of this object (hence, it will not get out of the screen when rotate). But this transformation (4 by 4 matrix) contains the translation (T[12],T[13],T[14]), rotation and scaling information. I try to use this transformation matrix and set the T12=T13=T14 = 0 (no translation), and T0=T5=T10=1 (no scaling) to my axis to be ploted on the left low corner, but it does not work. Any more detail suggestions and hints?

Thanks.

jwatte
12-21-2002, 08:06 AM
Set the modelview to identity.

Run the screen location you want to base your axes at through the inverse of the projection matrix. This gives you X and Y for the base.

Decide on a Z value to base your axes at. This should be far enough in that an axis pointing towards the viewer doesn't get clipped. You now have X, Y and Z for the base of your three lines.

For each axis, take the unit vector (1,0,0 for X, etc) and transform it through the inverse transpose of your camera matrix (which you have to keep track of separately, to keep it separate from the model matrix). The first end of the line for this axis is at the point you got above; the second is at the value of that point plus this transformed coordinate (which should still be a unit vector, with orientation applied).

amhigh
12-21-2002, 02:43 PM
Originally posted by jwatte:
Set the modelview to identity.

Run the screen location you want to base your axes at through the inverse of the projection matrix. This gives you X and Y for the base.

Decide on a Z value to base your axes at. This should be far enough in that an axis pointing towards the viewer doesn't get clipped. You now have X, Y and Z for the base of your three lines.

For each axis, take the unit vector (1,0,0 for X, etc) and transform it through the inverse transpose of your camera matrix (which you have to keep track of separately, to keep it separate from the model matrix). The first end of the line for this axis is at the point you got above; the second is at the value of that point plus this transformed coordinate (which should still be a unit vector, with orientation applied).

Set the ModelView Matrix to indenty for what? I try to pushmatrix, then set it to identity, draw the axes, then popmatrix. But this axis never be the left low corner of the screen! And it does not fix in the left low corner, if I rotate, this axis rotate with the origin, and get moved from the left low corner.

I also try to use the glprint (the Nehe's example) to draw the X,Y,Z. But it requres the glRaster2d, if I rotate the coordinate, I did not know how to set the raster position for the location of X Y and Z.

Would you please send me some short example code?

Thanks.

V-man
12-21-2002, 05:55 PM
Originally posted by amhigh:
Thanks,
Would that be possible to have more detail description?

I am using the ortho3d projection. Let say I have an object to plot, and because it is very far away from the origin, and in order to plot this object in the center of the graphics screen, I have obtained a transformation matrix that I can rotate with the center of this object (hence, it will not get out of the screen when rotate). But this transformation (4 by 4 matrix) contains the translation (T[12],T[13],T[14]), rotation and scaling information. I try to use this transformation matrix and set the T12=T13=T14 = 0 (no translation), and T0=T5=T10=1 (no scaling) to my axis to be ploted on the left low corner, but it does not work. Any more detail suggestions and hints?

Thanks.


I think you are trying to nullify the previous transform by applying additional transform to your modelview matrix.
Nothing wrong with that, but there is a simpler approach

glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
//apply Ortho projection if you wish
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
Draw the axis and text
........
........
........

J P
12-24-2002, 03:47 AM
amhigh,

Try this MFC example
http://www.mfcogl.com/OpenGL%20-%20draw%20cylinder%20between%202%20pts.htm

It has an csys axis drawing function with arrowheads and x, y, z letters and is very easy to use. It is used multiple times one of which is stationary. All you would have to do is rescale it and translate it to the corner of your choice. It is simple but it might be all that you need.