2019年3月14日 星期四

彥の圖學筆記 Week04

電腦圖學

2019-03-14 Week04

(1) 主題: 移動 Translate

重複上一週做過的事情,進入小葉老師的網站下載範例(http://www.cmlab.csie.ntu.edu.tw/~jsyeh/3dcg10/)

> 下載05/04的Examples: [data]、[win32]、glut32.dll三個連結 > 將[win32]解壓縮
> 把[data]、glut32.dll、丟進[win32]的資料夾裡 > 點開範例Transformation.exe
(點橘色超連結字體下載)

(2) 示範: glTranslatef(x,y,z)

(2) 主題: 滑鼠


程式碼(物件跟隨滑鼠座標)

#include <GL/glut.h>
float x=0, y=0;///滑鼠motion
void display()
{
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
    glPushMatrix();///備份矩陣
        glTranslatef( (x-150)/150.0, -(y-150)/150.0, 0);///滑鼠motion
        glutSolidTeapot(0.3);
    ///glVertex2f( (x-150)/150.0, -(y-150)/150.0, 0);
    glPopMatrix();///還原矩陣,才不會在下次有舊的殘值
    glutSwapBuffers();
}
void motion(int nowX, int nowY)///滑鼠motion
{///滑鼠motion
    x=nowX; y=nowY;///滑鼠motion
    display();///滑鼠motion 馬上更新
}///滑鼠motion
int main(int argc, char**argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
    glutCreateWindow("weeek04");
    glutDisplayFunc(display);
    glutMotionFunc(motion);///滑鼠motion

    glutMainLoop();
}

(3) 期中考題: 60%
1. glPushMatrix();///備份矩陣
2. glPopMatrix();///還原矩陣,才不會在下次有舊的殘值
3. glTranslatef(x, y, z);///滑鼠motion
4. glBegin();///開始畫 glEnd();///結束
5. glColor3f(a, b, c);///顏色
6. glVertex2f(x, y, z);///頂點



沒有留言:

張貼留言