2016年3月22日 星期二

Week05

Class Work 1

教材:http://www.cmlab.csie.ntu.edu.tw/~jsyeh/3dcg10/
Download: win32, data, glut32.dll
Open :Transformation

點選前
先畫出車子,在做縮放,接者在旋轉,最後在把旋轉及縮放後的車子移動。


點選後
先畫出車子,做縮放,接者移動,最後做旋轉。

差異:點選後的Translatef在下,旋轉的範圍較大,像是整個車子在鍋子裡,整個鍋子一起轉
         (前者,以車子的中心旋轉,後者,車子繞著鍋子中心轉)。

Class Work 2



Source Code:
#include<GL/glut.h>
float rotX=0;

void display()
{
    glClearColor(0,0,1,1);
    glClear(GL_COLOR_BUFFER_BIT);
    glPushMatrix();
        glRotatef(rotX,0,1,0);
        glColor3f(1,1,0);
        glutSolidTeapot(0.3);
    glPopMatrix();
    glutSwapBuffers();

}

void motion(int x, int y)
{
    rotX = x;
    display();
}

int main(int argc, char**argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
    glutCreateWindow("Hi~");

    glutDisplayFunc(display);
    glutMotionFunc(motion);

    glutMainLoop();

}


Class Work 3

Q1: Buffer?
       Buffer就是類似遮罩,像是畫圖的時候,畫了山,在畫房子,可是房子會擋住山的一部份,所以必須把重複的地方擦掉。
Q2: Double?
       Double就是用兩個記憶體做事,一個畫圖,另一個先用來類似假動作,等到圖畫完,再把畫面換到畫好圖的地方。 



Class Work 4

Q1: Push&Pop?
       舉例來說,假如有一個罐子,Push就是把東西放進去,Pop就是把東西拿出來。
Q2: Matrix?
       It is useful to be able to save the current transformation. We can push the current state on a stack, and then make new scale, translations, rotations. Then pop out.




Source Code:
#include<GL/glut.h>

float rotX=0, rotY=0;
void display()
{
    glClearColor(0,0,1,1);
    glClear(GL_COLOR_BUFFER_BIT);
    glPushMatrix();
        glRotatef(rotX,0,1,0);
        glRotatef(rotY,1,0,0);
        glColor3f(1,1,0);
        glutSolidTeapot(0.3);
    glPopMatrix();
    glutSwapBuffers();

}

void motion(int x, int y)
{
    rotX = x;
    rotY = y;
    display();
}
int main(int argc, char**argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
    glutCreateWindow("Hi~");

    glutDisplayFunc(display);
    glutMotionFunc(motion);

    glutMainLoop();

}

補充:
glutInitWindowPosition() 可以改變視窗顯視位置
glutInitWindowSize()  可以改變視窗大小

沒有留言:

張貼留言