Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Page 1 of 2 12 LastLast
Results 1 to 10 of 15

Thread: Drawing XYZ axis

  1. #1
    Junior Member Newbie
    Join Date
    Aug 2003
    Location
    Karlsruhe, Germany
    Posts
    1

    Drawing XYZ axis

    Hi,

    I'm trying to draw a set of XYZ axis in the corner of the screen which will show the orientation. I want these to rotate when the rest of my scene rotates, but to stay in the same position when I translate my scene. i can draw the axis fine although when I move the scene they also move.

    any suggestions much appreciated

    Cheers

  2. #2
    Intern Contributor
    Join Date
    Jul 2002
    Location
    Southampton, PA, USA
    Posts
    61

    Re: Drawing XYZ axis

    glRotate*(x...)
    glRotate*(y...)
    glRotate*(z...)

    glPushMatrix()

    glTranslate*(x,y,z)

    Draw_Scene()

    glPopMatrix()

    Draw_XYZ_Axis()

  3. #3
    Junior Member Newbie
    Join Date
    Jul 2010
    Posts
    9

    Re: Drawing XYZ axis

    Hi,

    7 years later I try to do the same!
    I want a little coordinate system in the left corner of my canvas that shows the current rotation of the world coordinate system. That means: only the rotating stuff is effecting the three drawn axis, whereas everything that is not related to rotating for instance translating or zooming should not do anything to the little coordinate system, so it stays forever there in the corner.
    how would you realize it?. I am using webgl (opengl es 2.0).


    cheeeers!

  4. #4
    Senior Member OpenGL Guru Dark Photon's Avatar
    Join Date
    Oct 2004
    Location
    Druidia
    Posts
    3,124

    Re: Drawing XYZ axis

    Take unit axis vectors, multiply by modelview, normalize (in case modelview has scales).

    If your modelview doesn't have scales or shears, you can just grab the axis vectors out of the upper-left 3x3. Same as multiply by unit vectors.

  5. #5
    Junior Member Newbie
    Join Date
    Jul 2010
    Posts
    9

    Re: Drawing XYZ axis

    Quote Originally Posted by Dark Photon
    Take unit axis vectors, multiply by modelview, normalize (in case modelview has scales).

    If your modelview doesn't have scales or shears, you can just grab the axis vectors out of the upper-left 3x3. Same as multiply by unit vectors.
    what? i thought this a beginner forum..
    not i don't have any scales or shears in my mvmatrix.

    can someone explain in more detail pleae ?

    thank you

  6. #6
    Senior Member OpenGL Pro Ilian Dinev's Avatar
    Join Date
    Jan 2008
    Location
    Watford, UK
    Posts
    1,269

    Re: Drawing XYZ axis

    Your modelview matrix:

    R R R t
    R R R t
    R R R t
    t t t t

    Copy the R parts into a 3x3 matrix.
    Multiply that matrix by vectors vec3(1,0,0), vec3(0,1,0), vec3(0,0,1). The results will be 3 vec3 vectors, rotated the way you want.
    Also, you'll note those vectors are identical with columns from the matrix. (that's why Dark Photon mentioned you can simply use those columns)

    Setup the projection to be orthographic or whatever, and set the viewport to cover only a small area from the bottom-left or wherever you want the axes to be drawn.

    Draw 3 lines, starting from vec3(0,0,0) and ending with each of those 3 vectors you calculated before. Done


    P.S. if you had scales and shears, you'd simply have to normalize the 3 vectors (otherwise - if you're just doing rotation and translation, they happen to be already normalized)

  7. #7
    Junior Member Newbie
    Join Date
    Jul 2010
    Posts
    9

    Re: Drawing XYZ axis

    thank you for explaining that, now everything is much clearer!

    Quote Originally Posted by Ilian Dinev
    Setup the projection to be orthographic or whatever, and set the viewport to cover only a small area from the bottom-left or wherever you want the axes to be drawn.
    that means i have to set multiple viewports?

  8. #8
    Senior Member OpenGL Pro Ilian Dinev's Avatar
    Join Date
    Jan 2008
    Location
    Watford, UK
    Posts
    1,269

    Re: Drawing XYZ axis

    Not really. It's kinda like "okay gpu, now I'll draw only on this rectangle". Don't forget to restore the viewport ASAP, though; nasties happen otherwise .
    The alternative would be to create a nice projection/modelview matrix that will transform everything to the specific corner. It's preferable, but I can't compose/recall the maths for it right now.

  9. #9
    Junior Member Newbie
    Join Date
    Jul 2010
    Posts
    9

    Re: Drawing XYZ axis

    Quote Originally Posted by Ilian Dinev
    Setup the projection to be orthographic or whatever, and set the viewport to cover only a small area from the bottom-left or wherever you want the axes to be drawn.
    Don't forget to restore the viewport ASAP
    I'm failing setting up this steps.. how do I set only a small area of the viewport and when to do it?

  10. #10
    Senior Member OpenGL Pro Ilian Dinev's Avatar
    Join Date
    Jan 2008
    Location
    Watford, UK
    Posts
    1,269

    Re: Drawing XYZ axis

    glViewport(0,0,100,100);

Posting Permissions

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