# How can I draw a coordinate axes fixed on the left-lower of the graphics window?

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.

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

Originally posted by V-man:
[b]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[/b]

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,T,T), 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.

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).

Originally posted by jwatte:
[b]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).[/b]

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.

Originally posted by amhigh:
[b] 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,T,T), 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. [/b]

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();