1.於http://jsyeh.org/3dcg10下載windows,data,glut.dll三個檔案
2.將data與glut32.dll放到windows裡面,開啟transformation.exe,可以特過這個程式觀察五選轉的情形。 可以發現物體旋轉是以右手定則作為依據。
3.將上週的程式碼複製貼上
#include <stdio.h>
#include <GL/glut.h>
float teatopX=0, teapotY=0;///Now:茶壺的座標
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);///清畫面
glPushMatrix();///Now:備份矩陣
glTranslatef(teatopX,teapotY, 0);///Now:依照茶壺的座標移動
glutSolidTeapot(0.3);///大小為0.3的茶壺
glPopMatrix();///Now:還原矩陣
glutSwapBuffers();///搭配GLUT_DOUBLE兩倍顯示
}
void mouse(int button, int state, int x, int y)
{
}
void motion (int x, int y)///mouse motion事件
{
teatopX=(x-150)/150.0; teapotY=(150-y)/150.0;///Now:依照motion時的x,y來改teapot的座標
glutPostRedisplay(); ///記得要Redisplay()
}
int main(int argc, char **argv)
{
glutInit(&argc, argv);///初始Initialize你的glut參數設定
glutInitDisplayMode(GLUT_DOUBLE |GLUT_DEPTH);///2個顯示參數
glutCreateWindow("Week03 Mouse");///建立視窗
glutDisplayFunc(display);///顯示函式display()用來畫圖的
glutMouseFunc(mouse);///上面會有mouse()滑鼠事件
glutMotionFunc(motion);///等一下上面會有mouse()滑鼠motion事件
glutMainLoop();///主要的迴圈,用來控制程式
}


沒有留言:
張貼留言