mikethebike

02-25-2012, 12:21 AM

Hi

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

Many thanks

Michael

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

Many thanks

Michael

View Full Version : roating a 2D mesh (glpoints)

mikethebike

02-25-2012, 12:21 AM

Hi

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

Many thanks

Michael

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

Many thanks

Michael

Dardan

02-25-2012, 06:10 AM

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

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

mikethebike

02-25-2012, 08:19 AM

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

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

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

Dardan

02-26-2012, 07:42 AM

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

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

mikethebike

02-26-2012, 11:30 PM

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

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

mikethebike

02-26-2012, 11:37 PM

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

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

Dardan

02-27-2012, 08:22 AM

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!

Good luck!

Dardan

02-27-2012, 08:25 AM

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

Dardan

Dardan

02-27-2012, 08:26 AM

btw, why are you using gltranslate twice?

mikethebike

02-28-2012, 12:00 AM

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

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

mikethebike

02-28-2012, 01:17 AM

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();

}

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();

}

Dardan

02-28-2012, 11:43 AM

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.

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.

mikethebike

02-28-2012, 11:32 PM

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

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

Dardan

02-29-2012, 09:24 AM

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.

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.

mikethebike

02-29-2012, 11:02 PM

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?

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

Dardan

03-01-2012, 08:48 AM

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

Anyway, the rotation works now?

Dardan

Powered by vBulletin® Version 4.2.3 Copyright © 2018 vBulletin Solutions, Inc. All rights reserved.