简体   繁体   中英

opengl glrotatef won't rotate properly

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 },

};

在此处输入图片说明

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM