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 16

Thread: roating a 2D mesh (glpoints)

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

    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
    77

    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
    77

    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
    77

    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)

    If you want to centre you rotation to a local object (so if you want an object ot rotate around its axis), please note to pout the matrix operations in the right order. I assume you have an adequate knowledge of Matrix Manipulations and calculations, so i you want to rotate the object around itself, it depens on how you are usign your matrices. Please try to turn the functions gltranslate and glrotate around according to their order. If none work, I'll take a more detailed look at the source you posted.

    Dardan

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

    Re: roating a 2D mesh (glpoints)

    btw, why are you using gltranslate twice?

  10. #10
    Intern Contributor
    Join Date
    May 2008
    Posts
    77

    Re: roating a 2D mesh (glpoints)

    Thanks but still the same after moving loadidentity. I draw as below but with glrotate and/or gltranslate nothing is visible.

    glBegin(GL_POINTS);
    glColor3f(rgb[0], rgb[1], rgb[2]);
    glVertex2f(z + 1059, x + 749);
    glEnd();

    I thought I'd need gltranslate twice for the camera? Well any
    combinations are not visible.
    Many thanks again

    Michael

Posting Permissions

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