2016年3月22日 星期二

week 05 劉正威

1.主題:旋轉&移動

jsyeh/3dcg10下載data win32 glut32.dill

打開transformation

在下方黑色畫面點右鍵選[s] swap translate/rotate

2.找出不一樣的地方(旋轉移動、移動旋轉)

(旋轉移動)→車子在轉
先縮放

旋轉

再移動

(移動旋轉)→車子繞中心轉
先縮放

移動

再旋轉

3.mouse轉動

利用滑鼠轉動茶壺


程式碼:
#include <GL/glut.h>
float rotX=0;
void display()
{
    glClearColor(0,0,1,0);
    glClear(GL_COLOR_BUFFER_BIT);
    glPushMatrix();
    glRotated(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("hellow3D");
    glutDisplayFunc(display);
    glutMotionFunc(motion);
    glutMainLoop();
}

4.階層式旋轉

上下左右旋轉

程式碼:
#include <GL/glut.h>
float rotX=0,rotY=0;
void display()
{
    glClearColor(0,0,1,0);
    glClear(GL_COLOR_BUFFER_BIT);
    glPushMatrix();
    glRotated(rotX,0,1,0);
    glRotated(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("hellow3D");
    glutDisplayFunc(display);
    glutMotionFunc(motion);
    glutMainLoop();
}

5.檔案開啟的位置與視窗大小


程式碼:
#include <GL/glut.h>
float rotX=0,rotY=0;
void display()
{
    glClearColor(0,0,1,0);
    glClear(GL_COLOR_BUFFER_BIT);
    glPushMatrix();
    glRotated(rotX,0,1,0);
    glRotated(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);
    glutInitWindowSize(400,400);
    glutInitWindowPosition(600,100);
    glutCreateWindow("hellow3D");
    glutDisplayFunc(display);
    glutMotionFunc(motion);
    glutMainLoop();
}

沒有留言:

張貼留言