---------------------------------------------------------------------------------------------
Week4 2018/03/23
(1)複習上週mouse 移動
(1)複習上週mouse 移動
(2)主題:移動
主題:旋轉
主題:縮放
(3)範例:Transformation.exe
(4)期中考題
(3)範例:Transformation.exe
(4)期中考題
----------------------------------------------------------------------------------------------
Class practice1 試試看別人的程式如何動
--與上週week03一樣方式開啟Class practice1
https://2018graphicsa.blogspot.tw/2018/03/week-03.html
△老師讓大家下載 data.zip, windows.zip, glut32.dll 這3個檔案的網址在 http://jsyeh.org/3dcg10
1.開起網址
2.下載以下三個檔案,並且解壓縮
1.開起網址
2.下載以下三個檔案,並且解壓縮
3.打開 windows -> 把glut32.dll 黨複製到其中
4.打開 shapes.exe -> 執行
△把glut.dll、data檔案丟入windows裡面才可開啟Transformation.exe
4.打開 shapes.exe -> 執行
△把glut.dll、data檔案丟入windows裡面才可開啟Transformation.exe
△左上、右上視窗 點右鍵 可以轉換功能或樣式
△點選下方數字 長按 字數上下移動可以改變數字大小
----------------------------------------------------------------------------------------------
Class practice2 複習上週mouse 移動
1.貼上week03 的Class practice3 Motion 程式碼,會呈現一個茶壺可以移動
2.程式碼修改 : (紅色部分為程式重點)
#include <GL/glut.h>
float teapotX=0, teapotY=0, angle=0;
///Now: 茶壺的座標,rotate旋轉要的angle
int oldX=0, oldY=0, nowRotate=0;
///Now: 紀錄mouse在哪裡按下去,oldX, oldY 幫忙紀錄舊的資訊
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);///(8)清理畫面
glPushMatrix();///備份矩陣
glTranslatef(teapotX, teapotY, 0);///依照茶壺的座標移動
glRotatef(angle, 0,0,1); ///Now: 茶壺要旋轉角度
glutSolidTeapot(0.3);///(9)大小為0.3的茶壺
glPopMatrix();///還原矩陣
glutSwapBuffers();///(10)交換double buffers來顯示畫出的畫面
}
void motion(int x, int y)
{
if(nowRotate==1)angle += (x-oldX);
///Now: 按了左鍵,旋轉的角度,變成可以接續轉(利用增加方式)
else ///Now: 按了右鍵
{
teapotX += (x-oldX)/150.0;///Now: 移動x座標,可以接續移動(利用增加方式)
teapotY += (oldY-y)/150.0;///Now: 移動y座標,可以接續移動(利用增加方式)
}
oldX = x;
oldY = y; ///Now: 紀錄移動後新的位置
glutPostRedisplay();///請3M Post便利貼,貼出來說,有礦石,要記得Redisplay()
}
void mouse(int button, int state, int x, int y)
{
if(button==GLUT_LEFT_BUTTON && state==GLUT_DOWN)
nowRotate=1; ///Now: 左鍵做旋轉
if(button==GLUT_RIGHT_BUTTON && state==GLUT_DOWN)
nowRotate=0; ///Now: 右鍵是移動
oldX = x;
oldY = y; ///Now: 紀錄按下去的點在哪裡
}
int main(int argc, char **argv)///(2)主要的函式 main
{///這個參數的意思,是把作業系統的參數,塞進來
glutInit(&argc, argv);///(3)初始Initialize你的glut參數設定
glutInitDisplayMode(GLUT_DOUBLE);///(4)顯示模式:double buffers(以後老師會再教其他的)
glutCreateWindow("Week03 Mouse");///(5)建立視窗
glutMouseFunc(mouse);///Now: 滑鼠Mouse事件使用
glutMotionFunc(motion);///滑鼠motion事件使用
glutDisplayFunc(display);///(6)顯示函式display()用來畫圖的
glutMainLoop();///(7)主要的迴圈,用來控制程式
}





沒有留言:
張貼留言