【问题标题】:opengl glrotatef won't rotate properlyopengl glrotatef 无法正确旋转
【发布时间】:2014-10-04 20:37:01
【问题描述】:

假设我在(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 },

};

【问题讨论】:

  • 什么是centerglRotate()?那不是OpenGL函数。你是说glRotate()吗?
  • 请在您的问题中提供更多详细信息:目前无法回答。特别是,提供centerglRotatef 的代码,以及使用它的完整场景。
  • 对不起,我的意思是 glRotatef

标签: c++ opengl graphics rotation


【解决方案1】:

您需要将您的对象转换到原点,而不是做您正在做的事情...glRotatef 中的 x、y、z 坐标是方向矢量而不是空间坐标。 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

【讨论】:

    猜你喜欢
    • 2012-05-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-21
    • 2021-07-24
    • 2022-06-16
    • 1970-01-01
    • 2012-12-14
    相关资源
    最近更新 更多