2016年3月22日 星期二

WEEK05 Allen這週拜託班草閉嘴

作業一:

教材: jsyeh.org/3dcg10


下載[data][win32] glut32.dll 

移動 glTranslatef
旋轉 glRotatef
縮放 glScalef
以車子為中心旋轉

1.原圖


先旋轉



再移動


旋轉 glRotatef
移動 glTranslatef
縮放 glScalef
Begin End()
2.原圖


先移動


再旋轉


口訣:左耳靠左肩

兩者差別(1)是左右邊在轉(2)整輛車在繞

作業二

mouse 轉動


程式碼:

#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("Hello 3D"); glutDisplayFunc(display); glutMotionFunc(motion); ///glutMouseFunc(mouse); glutMainLoop(); }

作業三:

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

程式碼:

#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()  可以改變視窗大小

沒有留言:

張貼留言