【发布时间】:2019-10-05 17:54:26
【问题描述】:
我想沿路径(正弦波)移动对象,假设对象是过山车。 它通过翻译移动,但我的问题是我还想根据路径旋转该对象。
我在翻译之前尝试过这段代码,但它不起作用。
if (x = -4.8)
{
glRotatef(89, 1, 1, 0);
}
我的只有翻译的代码看起来像这样。 我想在这里沿正弦波添加旋转
void object()
{ glPushMatrix();
glTranslatef(x, y, 0);
glColor3f(0.0f, 0.0f, 0.0f);//Set drawing color
glBegin(GL_QUADS);
glVertex2f(-0.3, 0.1);
glVertex2f(0.3, 0.1);
glVertex2f(0.3, -0.1);
glVertex2f(-0.3, -0.1);
glEnd();
glFlush();
glPopMatrix();
glFlush();
}
void drawsine()
{
glBegin(GL_LINE_STRIP);//Primitive
glColor3f(255, 0, 0);//Set drawing color
int i = 0;
float x = 0, y = 0;
for (x = -5; x < 6; x = x + 0.1)
{
y = (sin(3.142*x)) / 3.142*x;
glVertex2f(x, y);
//int j= 0;
sinex[i] = x;
siney[i] = y;
i++;
}
glEnd();
glFlush();
}
【问题讨论】:
标签: c++ opengl rotation translation opengl-compat