roating a 2D mesh (glpoints)

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

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).

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

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

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

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

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&lt;128; ++z) {
    	 int zz = z * cos (tdir) + x * sin(tdir);
        float smple_z = scale * (zz - 64);

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!

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

btw, why are you using gltranslate twice?

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

I’m not sure about the coordinates but I could also draw in a FBO. But even like that the 2D drawing (3D is ok) is not visible…sigh.

           			if( DreiDimensional ){
				glBegin(GL_TRIANGLE_STRIP);
						// draw vertex 0
				        glColor3f(rgb[0], rgb[1], rgb[2]);
						glVertex3f(terrainMap[x][z][0], terrainMap[x][z][1], terrainMap[x][z][2]);

						// draw vertex 1
					    glColor3f(rgb[0], rgb[1], rgb[2]);
						glVertex3f(terrainMap[x+1][z][0], terrainMap[x+1][z][1], terrainMap[x+1][z][2]);

						// draw vertex 2
					    glColor3f(rgb[0], rgb[1], rgb[2]);
						glVertex3f(terrainMap[x][z+1][0], terrainMap[x][z+1][1], terrainMap[x][z+1][2]);

						// draw vertex 3
					    glColor3f(rgb[0], rgb[1], rgb[2]);
						glVertex3f(terrainMap[x+1][z+1][0], terrainMap[x+1][z+1][1], terrainMap[x+1][z+1][2]);

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

// // glVertex2f(z, x);
glEnd();
}

Nothing seems to be wrong with it. But i can’t really find the bug i think… I need some more info:
Which platform do you use?
Did you use singe buffer or double buffer? If double, dont forget to use a function which swaps the buffers (that is accoridng to your platform). Please tell me as much about your oontext which you are rendering in.

It’s a plugin (dll) for an OpenGl App so buffering, camera etc. is handled by that.

Yea, weird especially as above in FBO I don’t understand why nothing is visible. Couly you tell me how to use terrainMap with
glpoints in only 2D? I’ve tried without success, maybe it needs only a little something? Rotate 3D around x works but I need a higher resolution…

why are adding 1 to the array?
SO terrainvertex[x+1][z][0]?
This doenst mean x coordinate goes up one, unless you defined the array previously… If you render like this withough defining the value of the array itself, it will aal be set to NULL or unknown value. Please tell me, probably the problem is over here.

No, as I said 3D in FBO is ok so I need to make also glpoints visible in FBO.

Figured it out without FBO but the mesh is to pixelated, not usable?

pixelated? You mean it contains too much jaggies? or that it appears to be really “pixelly” when you zoom out> Because I had that too. YOu should use anti-aliasing (any technique you want) and use the alpha blender.

Anyway, the rotation works now?

Dardan