opengl平移,旋转顺序
来源:学生作业帮 编辑:百度作业网作业帮 分类:综合作业 时间:2024/08/18 23:51:31
opengl平移,旋转顺序
void display(void)
{
glClear (GL_COLOR_BUFFER_BIT);
glColor3f (1.0,1.0,1.0);
glPushMatrix();
glutWireSphere(1.0,20,16); /* draw sun */
glRotatef ((GLfloat) year,0.0,1.0,0.0);
glTranslatef (2.0,0.0,0.0);
glRotatef ((GLfloat) day,0.0,1.0,0.0);
glutWireSphere(0.2,10,8); /* draw smaller planet */
glPopMatrix();
glutSwapBuffers();
}
行星和太阳的实例,为什么 先glRotatef ((GLfloat) year,0.0,1.0,0.0);再glTranslatef (2.0,0.0,0.0);旋转和平移的顺序如何确定?
void display(void)
{
glClear (GL_COLOR_BUFFER_BIT);
glColor3f (1.0,1.0,1.0);
glPushMatrix();
glutWireSphere(1.0,20,16); /* draw sun */
glRotatef ((GLfloat) year,0.0,1.0,0.0);
glTranslatef (2.0,0.0,0.0);
glRotatef ((GLfloat) day,0.0,1.0,0.0);
glutWireSphere(0.2,10,8); /* draw smaller planet */
glPopMatrix();
glutSwapBuffers();
}
行星和太阳的实例,为什么 先glRotatef ((GLfloat) year,0.0,1.0,0.0);再glTranslatef (2.0,0.0,0.0);旋转和平移的顺序如何确定?
![opengl平移,旋转顺序](/uploads/image/z/19981901-29-1.jpg?t=opengl%E5%B9%B3%E7%A7%BB%2C%E6%97%8B%E8%BD%AC%E9%A1%BA%E5%BA%8F)
绘制物体前最靠近物体的操作是最先执行的操作,
执行顺序与代码顺序相反,
比如,
本代码中,
画出smaller planet后,
先执行Rotatef(day...),也就是自转,
再Translatef,移到圆周轨道上去,
最后Rotatef(year...).公转.
执行顺序与代码顺序相反,
比如,
本代码中,
画出smaller planet后,
先执行Rotatef(day...),也就是自转,
再Translatef,移到圆周轨道上去,
最后Rotatef(year...).公转.