2024年3月14日 星期四

2024-03-14 Week04

 1.freeglut重複之前的步驟,開一個新專案GLUT,輸入10行程式碼,glClearColor(1.0,1.0,0.9,1.0);

    ///清背景的淡黃色glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);///清背景


2.加上周的部分程式碼float angle=0;  glPushMatrix();  glRotatef(angle,0,0,1);   glutSolidTeapot(0.3);

glPopMatrix();  void motion()   glutMotionFunc(motion);


3.加float s=1;  glScalef(s,s,s);   s=1+(x-150)/150.0;縮放
4.新增一個專案week04_keyboard_mouse_motion,用十行+一行(glutKeyboardFunc(keyboard);)

void keyboard(unsigned char key,int x ,int y)

{

    printf("key: %c  x: %d  y: %d\n",key,x,y);

}

,按abcd就會顯示(x,y)的座標

5.再加上glutMouseFunc(mouse);glutMotionFunc(motion);,然後void mouse motion
6.到https://jsyeh.org/3dcg10/下載data,win32解壓縮,把data放到windows開Transformation.exe

,translate/rotate交換2行自轉、公轉

7.新增一個專案week04_translate_rotate_scale貼上week04_keyboard_mouse_motion的程式碼,加這行glutIdleFunc(display);改成讓他自動轉
8. glTranslatef(0.8,0,0);///放到右邊-->glRotatef(angle++,0,0,1);///轉動中--> glScalef(0.3,0.3,0.3);///小小的-->glutSolidTeapot(0.3);///茶壺
9.glClearColor(1.0,1.0,0.9,1.0);///淡黃色背景、glColor3f(0,1,0);///綠色的
10.轉換階層


11.新增一個專案week04_rotate_translate_scale貼上week04_translate_rotate_scale,交換 glTranslatef()、glRotatef()

沒有留言:

張貼留言