opengl glrotatef won't rotate properly

monkey doodle

Suppose I had a drawing at point (50,60,20) and I wanted to rotate this in each side of a table. Base of the drawing below, I want to rotate the green circle to the right side, back side, and left side. My implementation was glRotatef(plate_rotate, 50, 0, 0); since this would be in the middle to the table, with a vertex x = 50. however this does not work.

glRotatef(90, 50, 0, 0); would not work. 


Table dimension 
int xL = 25;
int xR = 75;

int yT = 60;
int yB = 55;

int zF = 25;
int zB = -25;



static float tableTop[8][3] =
{
    { xL, yT, zF },
    { xR, yT, zF },
    { xR, yT, zB },
    { xL, yT, zB },
    //bottom
    { xL, yB, zF },
    { xR, yB, zF },
    { xR, yB, zB },
    { xL, yB, zB },

};

enter image description here

Andon M. Coleman

You need to translate your object to the origin, rather than doing what you're doing... the x,y,z coordinates in glRotatef are a direction vector not a spatial coordinate. There is no difference between glRotatef (90, 1, 0, 0) and glRotatef (90, 50, 0, 0) because both vectors are identical when normalized.

Consider this instead (pay attention to the order in which these things happen):

glTranslatef ( 50.0f, 0.0f, 0.0f);               // 3. Move back
glRotatef    (plate_rotate, 1.0f, 0.0f, 0.0f);   // 2. Rotate around X-axis
glTranslatef (-50.0f, 0.0f, 0.0f);               // 1. Move X=50 to origin

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related