关于C ++:OpenGL glrotatef无法正确旋转

opengl glrotatef won't rotate properly

假设我在点(50,60,20)处有一个图形,并且想在表格的每一侧旋转它。
在下面的图形的基础上,我想将绿色圆圈旋转到右侧,背面和左侧。 我的实现是
glRotatef(plate_rotate, 50, 0, 0);,因为它位于表格的中间,顶点x =50。但是这不起作用。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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


您需要将对象平移到原点,而不是做您正在做的事情... glRotatef中的x,y,z坐标是方向矢量,而不是空间坐标。 glRotatef (90, 1, 0, 0)glRotatef (90, 50, 0, 0)之间没有区别,因为归一化时两个向量都相同。

考虑一下(注意这些事情发生的顺序):

1
2
3
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