1.載windows.zip data.zip glut32.dll
將glut32.dll和data放進windows資料夾
啟動transformation
2.讓茶壺跟著滑鼠移動
code:
#include <stdio.h>
#include <GL/glut.h>
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(); //搭配GLUT_DOUBLE兩倍顯示
}
void motion(int x, int y) //mouse motion 事件
{
teapotX = (x-150)/150.0; // 依照motion時的x來改teapot的座標
teapotY = (150-y)/150.0;// 依照motion時的y來改teapot的座標
glutPostRedisplay(); //重畫畫面
}
int main(int argc, char** argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("Week03 Mouse");
glutDisplayFunc(display);
//glutMouseFunc(mouse);
glutMotionFunc(motion);
glutMainLoop();//主要GLUT迴圈
}
沒有留言:
張貼留言