主題1.1:移動Translate
1.到jsyeh.org/3dcg10 下載win32、data/將兩者解壓縮/並將data丟到windows資料夾裡
2.接著就可以打開Transformation.exe,會出現以下的畫面
glTotatef 可調整角度
glScalef 可調整縮放
3..打開一個新的專案,並輸入基本設定的程式
#include <GL/glut.h>
void display()
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glutSwapBuffers();
}
int main(int argc,char**argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("自行設定");
glutDisplayFunc(display);
glutMainLoop();
}
程式碼如下:
#include <GL/glut.h>
void display()
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glColor3f(1,0,0);
glutSolidTeapot(0.3);
glPopMatrix();
glutSwapBuffers();
}
int main(int argc,char**argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
glutCreateWindow("Residual_hope");
glutDisplayFunc(display);
glutMainLoop();
}
主題1.2:座標換算
1.自訂一個函式,使其只要輸入該函式、座標位置便可創造一個紅色茶壺
void myTeapot(float x,float y)
{
glPushMatrix();///push備份矩陣
glTranslatef(x,y,0);
glutSolidTeapot(0.3);
glPopMatrix();///pop還原矩陣
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glColor3f(1,0,0);///red
myTeapot(+0.5,+0.5);
myTeapot(-0.5,+0.5);
myTeapot(+0.5,-0.5);
myTeapot(-0.5,-0.5);
glutSwapBuffers();
}
主題2.2:滑鼠事件
1.寫一個滑鼠的外掛程式
void mouse(int button,int state,int x,int y)
{
printf("%d %d %d %d\n",button,state,x,y);
}
並在下方增加glutMouseFunc() 這個基本設定
2.用滑鼠事件配合創造出來的茶壺做出一個能用滑鼠控制茶壺位置的程式
口訣:減一半、除一半,y倒過來
建立一個mousex=0,mousey=0/扣除中心點,除以中心點/將滑鼠事件函式改成物件隨滑鼠移動
3.1先設置出一個n,用來計算有幾個點
3.2寫一個迴圈用來搭配陣列 mx[i],my[i]
3.3滑鼠用printf()印出程式碼
沒有留言:
張貼留言