Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 7 of 7

Thread: How to Add a Compass in My Programme

  1. #1
    Junior Member Newbie
    Join Date
    Apr 2002
    Location
    wuhan,huibei,china
    Posts
    12

    How to Add a Compass in My Programme

    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!
    A OpenGL fan

  2. #2
    Intern Newbie
    Join Date
    Mar 2002
    Location
    Vienna Austria
    Posts
    33

    Re: How to Add a Compass in My Programme

    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.
    ***EOF***

  3. #3
    Junior Member Newbie
    Join Date
    Apr 2002
    Location
    wuhan,huibei,china
    Posts
    12

    Re: How to Add a Compass in My Programme

    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!
    A OpenGL fan

  4. #4
    Junior Member Newbie
    Join Date
    May 2002
    Posts
    14

    Re: How to Add a Compass in My Programme

    Just render them seperately. draw your scene and your character, then glLoadIdentity(), glPushMatrix(), translate to the upper corner, draw your compass, glPopMatrix()

  5. #5
    Junior Member Newbie
    Join Date
    Apr 2002
    Location
    wuhan,huibei,china
    Posts
    12

    Re: How to Add a Compass in My Programme

    Thank you very much!
    I have finished my idea!
    A OpenGL fan

  6. #6
    Intern Newbie
    Join Date
    Apr 2002
    Posts
    48

    Re: How to Add a Compass in My Programme

    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 )

  7. #7
    Junior Member Newbie
    Join Date
    Apr 2002
    Location
    wuhan,huibei,china
    Posts
    12

    Re: How to Add a Compass in My Programme

    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).]
    A OpenGL fan

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •