[英]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.