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 10 of 16

Thread: roating a 2D mesh (glpoints)

Hybrid View

  1. #1
    Intern Contributor
    Join Date
    May 2008
    Posts
    67

    roating a 2D mesh (glpoints)

    Hi
    how to rotate a 2D mesh (glpoints, glVertex2f) with a given angle?
    Many thanks
    Michael

  2. #2
    Intern Newbie
    Join Date
    Feb 2012
    Posts
    32

    Re: roating a 2D mesh (glpoints)

    Hi Michael,

    You just use he basic OpenGL matrix system:
    glRotated(double angx, double angy, double angz);
    This can be used for both 2D and 3D rotations.
    Remember to put glPushMatrix(); and end with glPopMatrix(); if this rotation is a local rotation (so not the world matrix).

  3. #3
    Intern Contributor
    Join Date
    May 2008
    Posts
    67

    Re: roating a 2D mesh (glpoints)

    glRotatef(GetDataf(psi), 0, 1, 0);//heading

    Hmm, so why I cannot see anything anymore after adding the above line?

  4. #4
    Intern Newbie
    Join Date
    Feb 2012
    Posts
    32

    Re: roating a 2D mesh (glpoints)

    Well, if you can give some more info about the way you render.
    Calling glRotatef after glLoadIdentity will rotate it once. your variable needs to increase, so like glRotated(rot,0,0,0); rot++ (or how it is done in the language you are using).
    Please post a part of your source, it's quite unclear how you want to perform this action

  5. #5
    Intern Contributor
    Join Date
    May 2008
    Posts
    67

    Re: roating a 2D mesh (glpoints)

    Hi
    glMatrixMode(GL_MODELVIEW);
    glPushMatrix();
    glLoadIdentity();
    glDisable(GL_TEXTURE_2D);

    glTranslatef(local_lat, local_lon, local_alt);
    glRotatef(GetDataf(psi), 0, 1, 0);//heading
    glTranslatef(-local_lat, -local_lon, -local_alt);

    draw and popmatrix. If I comment the last three lines I see the glpoints but not as above nor without gltranslations.
    Many thanks

  6. #6
    Intern Contributor
    Join Date
    May 2008
    Posts
    67

    Re: roating a 2D mesh (glpoints)

    As a result I tried as below. tdir is the angle. But the rotation is not centered in the 128x128 mesh to draw.
    Thanks
    for (x=0; x<128; ++x) {
    int xx = x * cos(tdir) - z * sin(tdir);
    float smple_x = scale * (xx - 64);

    for (z=0; z<128; ++z) {
    int zz = z * cos (tdir) + x * sin(tdir);
    float smple_z = scale * (zz - 64);

  7. #7
    Intern Newbie
    Join Date
    Feb 2012
    Posts
    32

    Re: roating a 2D mesh (glpoints)

    oh i see the problem I think. You shouldn't put loadidentity between PushMatrix and Popmatrix, because then only the translations claled between this will be reset to the 0 matrix (so the standard matrix). If you want continous translation, make sure the variables increase, and put the loadIdentity DIRECTLY after Matrixmode (at least, I assume you want to only translate the object between push and pop matrix)

    Good luck!

  8. #8
    Intern Newbie
    Join Date
    Feb 2012
    Posts
    32

    Re: roating a 2D mesh (glpoints)

    btw, why are you using gltranslate twice?

Posting Permissions

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