如下圖

2.控制茶壺移動和選轉
#include <GL/glut.h>
float x=0,y=0;
void display()
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glPushMatrix();//備份矩陣,保護程式
glTranslated((x-150)/150.0,-(y-150)/150.0,0);//控制移動
glRotatef(x,1,0,0);//控制選轉
glutSolidTeapot(0.3);
glutSwapBuffers();
glPopMatrix();//還原矩陣
}
void motion(int nowx,int nowy)//用滑鼠來設定x,y
{
x=nowx;y=nowy;
display();
}
int main(int argc,char ** argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
glutCreateWindow("第N個程式");
glutDisplayFunc(display);
glutMotionFunc(motion);//呼叫滑鼠函式
glutMainLoop();
}

歐文是誰
回覆刪除跑跑界的faker
刪除