Week3 2018/03/16
(1)複習上週回圈HW
(2)Q&A,動手做
(3)主題:滑鼠(mouse)鍵盤
(4) (主題):移動Translate
(5)寫 zuvio 問卷回答
----------------------------------------------------------------------------------------------
Class practice1 複習上週的迴圈
△老師讓大家下載 data.zip, windows.zip, glut32.dll 這3個檔案的網址在 http://jsyeh.org/3dcg10
1.開起網址
2.下載以下三個檔案,並且解壓縮
3.打開 windows -> 把glut32.dll 黨複製到其中
4.打開 shapes.exe -> 執行
△把glut.dll、data檔案丟入windows裡面才可開啟shapes
△左右邊視窗點右鍵可以轉換功能
△點選左邊數字常按左邊的字數上下移動可以改變數字大小
△老師在 FB "2018電腦圖學" 中,有另外教如何利用不同程式做出不同的圖,可參考
Class practice2 Mouse
1.打開 codeBlock 裡面的 GLUT (week01有複習到)
2.打出茶壺的程式 (week02有複習到)
3.改寫程式 :
#include <stdio.h>
#include <GL/glut.h>
void display()
{
glClear(GL_COLOR_BUFFER_BIT);///(8)清理畫面
glutSolidTeapot(0.3);///(9)大小為0.3的茶壺
glutSwapBuffers();///(10)交換double buffers來顯示畫出的畫面
}
void mouse(int button,int state,int x, int y)
{
///button: 左、中、右鍵, state: 按下去/彈起來, x,y:mouse位置
printf("%d %d %d %d\n", button,state,x,y);
}
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);
///glutMouseFunc(motion);
glutDisplayFunc(display);///(6)顯示函式display()用來畫圖的
glutMainLoop();///(7)主要的迴圈,用來控制程式
}
4.下列為變成浮點數印出的程式:
#include <stdio.h>
#include <GL/glut.h>
void display()
{
glClear(GL_COLOR_BUFFER_BIT);///(8)清理畫面
glutSolidTeapot(0.3);///(9)大小為0.3的茶壺
glutSwapBuffers();///(10)交換double buffers來顯示畫出的畫面
}
void mouse(int button,int state,int x, int y)
{
///button: 左、中、右鍵, state: 按下去/彈起來, x,y:mouse位置
///printf("%d %d %d %d\n", button,state,x,y);
if(state==GLUT_DOWN) printf(" glVertex2f(%f, %f);\n", (x-150)/150.0,(150-y)/150.0);///如果mouse往下,才印程式
}
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);
///glutMouseFunc(motion);
glutDisplayFunc(display);///(6)顯示函式display()用來畫圖的
glutMainLoop();///(7)主要的迴圈,用來控制程式
}
----------------------------------------------------------------------------------------------
Class practice3 Motion移動,但滑鼠上永遠都有茶壺,有Bog
1.打出下列程式:
#include <stdio.h>
#include <GL/glut.h>
float teapotX=0, teapotY=0;///Now: 茶壺的座標
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);///(8)清理畫面
glPushMatrix();///Now: 備份矩陣
glTranslatef(teapotX, teapotY, 0);///Now: 依照茶壺的座標移動
glutSolidTeapot(0.3);///(9)大小為0.3的茶壺
glPopMatrix();///Now: 還原矩陣
glutSwapBuffers();///(10)交換double buffers來顯示畫出的畫面
}
void motion(int x, int y)
{
teapotX=(x-150)/150.0;teapotY=(150-y)/150.0;///Now: 依照motion時的 x,y 來改teapot的座標
glutPostRedisplay();///Now: 請3M Post便利貼,貼出來說,有礦石,要記得Redisplay()
}
int main(int argc, char **argv)///(2)主要的函式 main
{///這個參數的意思,是把作業系統的參數,塞進來
glutInit(&argc, argv);///(3)初始Initialize你的glut參數設定
glutInitDisplayMode(GLUT_DOUBLE);///(4)顯示模式:double buffers(以後老師會再教其他的)
glutCreateWindow("Week03 Mouse");///(5)建立視窗
glutMotionFunc(motion);///Now: 滑鼠motion事件使用
glutDisplayFunc(display);///(6)顯示函式display()用來畫圖的
glutMainLoop();///(7)主要的迴圈,用來控制程式
}
△BOG:移動滑鼠的時候,點手把時,圖會立刻跳成壺的正中心,week04會教如何把此BOG移除!!!








沒有留言:
張貼留言