2015年3月26日 星期四

02163042_王冠閔_week05

(1).自製3D模型

長方形雛形
glBegin(GL_LINE_LOOP);//畫線
            glVertex3f(0.2, 0.2, 0.8);
            glVertex3f(0.2, -0.2, 0.8);
            glVertex3f(-0.2,-0.2, 0.8);
            glVertex3f(-0.2, 0.2, 0.8);
        glEnd();
        glBegin(GL_LINE_LOOP);//畫線
            glVertex3f(0.2, 0.2, -0.8);
            glVertex3f(0.2, -0.2, -0.8);
            glVertex3f(-0.2, -0.2, -0.8);
            glVertex3f(-0.2, 0.2, -0.8);
        glEnd();
        glBegin(GL_QUAD_STRIP);//畫方形
            glVertex3f(0.2, 0.2, 0.8);
            glVertex3f(0.2, 0.2, -0.8);
            glVertex3f(0.2, -0.2, 0.8);
            glVertex3f(0.2, -0.2, -0.8);
            glVertex3f(-0.2, -0.2, 0.8);
            glVertex3f(-0.2, -0.2, -0.8);
            glVertex3f(-0.2, 0.2, 0.8);
            glVertex3f(-0.2, 0.2, -0.8);
        glEnd();

長方型透視圖:
glBegin(GL_LINE_LOOP);
glBegin(GL_LINE_LOOP);
glBegin(GL_LINES);



長方形填滿圖+黑色線:
glBegin(GL_POLYGON);
glBegin(GL_POLYGON);
glBegin(GL_QUAD_STRIP);




(2).利用滑鼠旋轉

簡單的滑鼠移動:
加一個void
void motion(int x,int y)
{
    printf("%d %d\n", x, y);
    angle = x;
    angle2 = y;
}
在int main 底下加一行:
glutMotionFunc(motion);///滑鼠移動

(例外):開啟3D深度測試

開啟一個3D的深度測試:

glEnable(GL_DEPTH_TEST);///開啟3D深度測試
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
在 int main底下加一行
glutInitDisplayMode(GLUT_DEPTH);///讓顯示具有3D深度的功能





沒有留言:

張貼留言