執行Transformation.exe
(1)到http://www.cmlab.csie.ntu.edu.tw/~jsyeh/3dcg10/網站下載[data][win32]glut32.dll 三個檔案
(2)將[win32]解壓縮並將 [data] glut32.dll丟進[win32]中
(3)點擊Transformation.exe 即可執行
<hint>其中glRotatef的座標旋轉式依照右手定則並以xyz軸分別做為旋轉的依據
套用上述概念延升到上周teapot茶壺程式碼中使茶壺能夠旋轉並移動
以下是這週程式碼
#include <stdio.h>
#include <GL/glut.h>
float teapotX=0, teapotY=0,angle=0;
int oldX=0,oldY=0,nowRotate=0;
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();//備份矩陣
glTranslatef(teapotX, teapotY, 0); //依照茶壺的座標移動
glRotatef(angle,0,0,1);
glutSolidTeapot(0.3);
glPopMatrix();//還原矩陣
glutSwapBuffers(); //搭配GLUT_DOUBLE兩倍顯示
}
void motion(int x, int y) //mouse motion 事件
{
if(nowRotate==1)angle+=(x-oldX);
else{
teapotX+=(x-oldX)/150.0;
teapotY+=(oldY-y)/150.0;
}
oldX=x; oldY=y;
//teapotX = (x-150)/150.0; // 依照motion時的x來改teapot的座標
//teapotY = (150-y)/150.0;// 依照motion時的y來改teapot的座標
glutPostRedisplay(); //重畫畫面
}
void mouse(int button,int state,int x,int y)
{
if(button==GLUT_LEFT_BUTTON&&state==GLUT_DOWN)nowRotate=1;
if(button==GLUT_RIGHT_BUTTON&&state==GLUT_DOWN)nowRotate=0;
oldX=x; oldY=y;
}
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迴圈
}
--------------------------------------------------------------------------------------------------------------------------
這週老師還有透露了中考考題





沒有留言:
張貼留言