老師利用框線逐步解是程式的架構
#include <GL/glut.h>
float angle=0;
void motion(int x,int y)
{
angle=x;
glutPostRedisplay();
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glRotated(angle,0,0,1);
glTranslated(0.45,-0.08,0);
glutSolidTeapot(0.3);
glPopMatrix();
glutSwapBuffers();
}
int main(int argc, char *argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("GLUT TRT");
glutDisplayFunc(display);
glutMotionFunc(motion);
glutMainLoop();
}
簡單的旋轉,轉動的角度為滑鼠的座標
加入另外兩個茶壺,旋轉軸為畫面的中心
在新增兩個茶壺作為左手 右手分別往上下做移動旋轉
#include <GL/glut.h>
float angle=0;
void motion(int x,int y)
{
angle=x;
glutPostRedisplay();
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glutSolidTeapot(0.3);
glPushMatrix();
glTranslated(0.5,0.15,0);
glRotated(angle,0,0,1);
glTranslated(0.45,-0.08,0);
glutSolidTeapot(0.3);
glPushMatrix();
glTranslated(0.5,0.15,0);
glRotated(angle,0,0,1);
glTranslated(0.45,-0.08,0);
glutSolidTeapot(0.3);
glPopMatrix();
glPopMatrix();
glPushMatrix();
glTranslated(-0.5,0.15,0);
glRotated(angle,0,0,1);
glTranslated(-0.45,-0.08,0);
glutSolidTeapot(0.3);
glPushMatrix();
glTranslated(-0.5,0.15,0);
glRotated(angle,0,0,1);
glTranslated(-0.45,-0.08,0);
glutSolidTeapot(0.3);
glPopMatrix();
glPopMatrix();
glPopMatrix();
glutSwapBuffers();
}
int main(int argc, char *argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("GLUT TRT");
glutDisplayFunc(display);
glutMotionFunc(motion);
glutMainLoop();
}






沒有留言:
張貼留言