[英]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. 假设我在(50,60,20)
点有一个工程图,我想在桌子的每一侧旋转它。 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);
我的实现是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. 因为它位于表格的中间,顶点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 },
};
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. 您需要将对象平移到原点,而不是做您正在做的事... glRotatef
中的x,y,z坐标是方向矢量,而不是空间坐标。 There is no difference between glRotatef (90, 1, 0, 0)
and glRotatef (90, 50, 0, 0)
because both vectors are identical when normalized. 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.