float teapotX=0, teapotY=0;
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glTranslatef(teapotX,teapotY,0);
glutSolidTeapot(0.3);
glPopMatrix();
glutSwapBuffers();
}
void mouse(int button,int state,int x,int y)
{
printf("%d %d\n",(x-150)/150.0,(y-150)/150.0);
teapotX=(x-150)/150.0;
teapotY=-(y-150)/150.0;
}
讓茶壺可以隨著滑鼠點擊移動


沒有留言:
張貼留言