2016年3月21日 星期一

WEEK5

http://www.cmlab.csie.ntu.edu.tw/~jsyeh/3dcg10/
下載data、win32、glut32.dll
基本上跟WEEK3一樣

1.Transformation開啟

glTranslatef位子移動
glRotatef旋轉
glScalef 體積
2.
階層式旋轉
#include <GL/glut.h>
float rotX=0;
void display()
{
    glClearColor(1,1,1,1);
    glClear(GL_COLOR_BUFFER_BIT);
    glPushMatrix();
        glRotatef(rotX, 0,1,0);
        glColor3f(1,0,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);

    glutMainLoop();


}

















3.
階層式移動
#include <GL/glut.h>
float rotX=0,rotY=0;
void display()
{
    glClearColor(1,1,1,1);
    glClear(GL_COLOR_BUFFER_BIT);
    glPushMatrix();
        glRotatef(rotX, 1,0,0);
        glRotatef(rotY, 0,1,0);
        glColor3f(1,0,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);
    glutInitWindowSize(300,300);
    glutCreateWindow("HELLO 3D");

    glutDisplayFunc(display);
    glutMotionFunc(motion);

    glutMainLoop();
}

沒有留言:

張貼留言