繁体   English   中英

opengl glrotatef无法正确旋转

[英]opengl glrotatef won't rotate properly

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

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

};

在此处输入图片说明

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

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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