Week03 複習上周進度,移動
從jsyeh.org/3dcg10網站裡下載3個檔案
data.zip windows.zip glut32.dll
解壓縮windows.zip並把glut32.dll丟進資料夾裡
開啟shapes
按右鍵Toggle big vertex 放超大頂點
在右邊按右鍵選擇POLYGON[g]
接著複習上周的程式碼
#include<stdio.h>
#include<GL/glut.h>
///(1)我們要使用比較高級的GLUT (OpenGl User Toolkit)
void display()
{
glClear(GL_COLOR_BUFFER_BIT);///清畫面
glutSolidTeapot(0.3);///大小為0.3的茶壺
glutSwapBuffers(); /// 交換double buffers來顯示畫面
}
int main(int argc , char **argv)///主要函式
{///這個參數的意思是,把作業系統參數塞進來
glutInit(&argc,argv);///初始Iniitialize你的參數設定
glutInitDisplayMode(GLUT_DOUBLE);///顯示模式:double buffers
glutCreateWindow("week02 Triangle");///建立視窗
glutDisplayFunc(display);///顯式函式display()用來畫圖的
glutMainLoop();///主要的迴圈,用來控制程式
}
在改寫程式,讓cmd可以出現滑鼠座標
#include<stdio.h>
#include<GL/glut.h>
///(1)我們要使用比較高級的GLUT (OpenGl User Toolkit)
void display()
{
glClear(GL_COLOR_BUFFER_BIT);///清畫面
glutSolidTeapot(0.3);///大小為0.3的茶壺
glutSwapBuffers(); /// 交換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)///主要函式
{///這個參數的意思是,把作業系統參數塞進來
glutInit(&argc,argv);///初始Iniitialize你的參數設定
glutInitDisplayMode(GLUT_DOUBLE);///顯示模式:double buffers
glutCreateWindow("week02 Triangle");///建立視窗
glutMouseFunc(mouse);
glutDisplayFunc(display);///顯式函式display()用來畫圖的
glutMainLoop();///主要的迴圈,用來控制程式
}
把顯示變成浮點數(較精確),並讓茶壺動起來
#include<stdio.h>
#include<GL/glut.h>
///(1)我們要使用比較高級的GLUT (OpenGl User Toolkit)
float teapotX=0, teapotY=0;///茶壺的座標
void display()
{
glClear(GL_COLOR_BUFFER_BIT);///清畫面
glPushMatrix(); ///Now: 備份矩陣
glTranslatef(teapotX, teapotY, 0); ///Now: 依照茶壺的座標移動
glutSolidTeapot(0.3);///大小為0.3的茶壺
glPopMatrix();///還原矩陣
glutSwapBuffers(); /// 交換double buffers來顯示畫面
}
void mouse(int button, int state , int x , int y){
if(state==GLUT_DOWN) ///按鍵才印
{
printf(" glVertex2f(%f, %f);\n", (x-150)/150.0,(150-y)/150.0);
///將圖分成象限,座標有正負也變成浮點數
}
}
void motion(int x, int y)///滑鼠移動
{
teapotX=(x-150)/150.0;teapotY=(150-y)/150.0;
glutPostRedisplay();
}
int main(int argc , char **argv)///主要函式
{///這個參數的意思是,把作業系統參數塞進來
glutInit(&argc,argv);///初始Iniitialize你的參數設定
glutInitDisplayMode(GLUT_DOUBLE);///顯示模式:double buffers
glutCreateWindow("week02 Triangle");///建立視窗
glutMouseFunc(mouse);
glutMotionFunc(motion);移動函式
glutDisplayFunc(display);///顯式函式display()用來畫圖的
glutMainLoop();///主要的迴圈,用來控制程式
}








沒有留言:
張貼留言