View Full Version : How to Add a Compass in My Programme

05-18-2002, 12:23 AM
I am a learner of OpenGL,and use it to write a full-screen programme with big scene,in which user can walk around.Now I want to add a compass(A box and Needle)at the right-top conner of the screen to indicate the direction.I known how to draw the appearance
of the compass but do not known how to make some setting before drawing the compass.
Can you give me some code or advice?Any help are appreciated!

05-18-2002, 01:24 AM

You got the rotation of your "Player" arount the y-axis.

So this is the rotation in degrees.

Let's say 0-degree are East,...

To draw the compass simply draw in ortho mode a texture of your compass with the rotation around the Z-axis. You should use a masked texture (-->Nehe tutorial Masking)

Now you have an Texture that rotaes if you user rotates, so you can draw the needle with GL_LINES.

05-18-2002, 03:00 AM
Thanks a lot!
Now my doubt is "how to make the compass at the corner of the screen when user roam around".Or rather,how to draw a circle there when user roam:the circle is still at the corner,keep immobility,not associated with the 3D volume!

05-18-2002, 04:03 AM
Just render them seperately. draw your scene and your character, then glLoadIdentity(), glPushMatrix(), translate to the upper corner, draw your compass, glPopMatrix()

05-18-2002, 05:36 PM
Thank you very much!
I have finished my idea!

05-19-2002, 04:19 AM
I had a similar problem ( a while ago - but didn't solve it ).
Drawing a radar - knew how to do it but had a little problem - no way of calculating the Y rotation - used relaive rotation with quaternions so no way too do somthing like y += 30.0f http://www.opengl.org/discussion_boards/ubb/wink.gif)

05-21-2002, 08:08 PM
I do not really known clearly about what you want for my poor english.The code i wrote is as below,i expect this is helpful for you:
// Reset The Current Modelview Matrix
// Save The Current MODELVIEW Matrix
// Translate To The Object's Location
// you can add some other code for the setting of the needle .....
// draw the need of the compass
// you can add some other code for the setting of the Box .....
// Restore The Current MODELVIEW Matrix

[This message has been edited by zjkw (edited 05-21-2002).]