2016年3月22日 星期二

Week 05 陳心瑜

一樣到教材 jsyeh.org/3dcg10
下載3個檔案>Transformation
去做交換Swap,寫下差別!


右鍵練習不同的旋轉!

(1)主題:旋轉&移動
(2)教材做Swap交換
   去做交換Swap(右下角,右鍵),寫下差別(順序不一樣結果不一樣)
    (A)以車子為中心點
         移動glTranslatef 移動旋轉縮小的車子 x:鏡頭水平移動  y:鏡頭垂直移動  z:鏡頭前後移動





     旋轉glRotate 旋轉縮小的車子 a:360度旋轉 bcd旋轉的方向
     縮放glScalef 縮小的車子 x:鏡頭水平縮放  y:鏡頭垂直縮放  z:鏡頭前後縮放
     glBegin(),glEnd()
      
 (B)以整個空間為中心點(右鍵選擇[x]Swap translate/rotate)
     旋轉glRotate 旋轉移動縮小的車子
     移動glTranslatef 移動縮小的車子
     縮放glScalef 縮小的車子
     glBegin(),glEnd()


(3)mouse轉動(滑鼠移動旋轉)
Buffer 繪圖暫存記憶體空間
DoubleBuffer兩倍記憶體空間
#include<GL/glut.h>
float rotX=0;
void display()
{
     glClearColor(0,1,1,1);
     glClear(GL_COLOR_BUFFER_BIT);
     glPushMatrix();
     glRotatef(rotX,0,1,0);
     glColor3f(1,0,1);
     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_DEPTH | GLUT_DEPTH);
    glutCreateWindow("hello");

    glutDisplayFunc(display);
    glutMotionFunc(motion);

    //glutMotionFunc(mouse);
glutMainLoop();

}















(4)階層式旋轉
Push and Pop
Push :將資料放入記憶體中
Pop : 將資料從記憶體中彈出
#include <GL/glut.h>
float rotX=0,rotY=0;  //轉X跟Y
void display()
{
    glClearColor(1,1,1,1);
    glClear(GL_COLOR_BUFFER_BIT);
    glPushMatrix();
        glRotatef(rotX,0,1,0);
        glRotatef(rotY,1,0,0);  //轉X軸
        glColor3f(1,0,0);
        glutSolidTeapot(0.3);
    glPopMatrix();
    glutSwapBuffers();
}
void motion(int x,int y)
{
    rotX=x;
    rotY=y;  //代入滑鼠y值移動量
    display();
}
int main (int argc,char**argv)
{
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
    glutInitWindowSize(400,400);  //視窗大小
    glutInitWindowPosition(700,0);  //視窗跳出之位置

    glutCreateWindow("hello3D");
    glutDisplayFunc(display);
    glutMotionFunc(motion);
    glutMainLoop();

}

































(5)階層式移動


沒有留言:

張貼留言