PDA

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



zjkw
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!

stryx
05-18-2002, 01:24 AM
Well,

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.

zjkw
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!

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

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

CopyCat
05-19-2002, 04:19 AM
Hi
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)

zjkw
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
glLoadIdentity();
// Save The Current MODELVIEW Matrix
glPushMatrix();
// Translate To The Object's Location
glTranslatef(fxPos,fyPos,0.0f);
glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);
// you can add some other code for the setting of the needle .....
// draw the need of the compass
glCallList(m_nNeedleList);
// you can add some other code for the setting of the Box .....
glCallList(m_nBoxList);
// Restore The Current MODELVIEW Matrix
glPopMatrix();


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