gpt4 book ai didi

c++ - opengl glrotatef 无法正确旋转

转载 作者:行者123 更新时间:2023-11-30 04:00:38 25 4
gpt4 key购买 nike

假设我在点 (50,60,20) 处画了一幅画,我想在 table 的每一侧旋转它。在下图的基础上,我想将绿色圆圈旋转到右侧、背面和左侧。我的实现是 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 },

};

enter image description here

最佳答案

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

改为考虑这个(注意这些事情发生的顺序):

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

关于c++ - opengl glrotatef 无法正确旋转,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26196945/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com