# Thread: roating a 2D mesh (glpoints)

1. ## roating a 2D mesh (glpoints)

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

2. ## 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. ## Re: roating a 2D mesh (glpoints)

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

4. ## Re: roating a 2D mesh (glpoints)

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. ## Re: roating a 2D mesh (glpoints)

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

glTranslatef(local_lat, local_lon, local_alt);
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. ## 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. ## 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. ## 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
•