2016年6月7日 星期二

Week16 03160224

課堂作業一:
1.jsyeh.org/3dcg10 載 5/18 PDF*2

2.Camera運鏡
開啟貝殼專案加入include & lib
加入 freeglut , opengl32, glu32 ,gdi32 ,winmm


程式碼
#include <GL/glut.h>
void display()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glPushMatrix();
        glutSolidTeapot(0.5);
    glPopMatrix();
    glutSwapBuffers();
}
void resize(int w,int h)
{
    glViewport(0,0,(GLsizei)w,(GLsizei)h);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(65.0,(GLdouble)w/h,1.0,100.0);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    gluLookAt(0.0,0.0,5.0
              ,0.0,0.0,0.0
              ,0.0,1.0,0.0);
}
int main(int argc, char**argv)
{
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("camera");
    glutDisplayFunc(display);
    //glutMotionFunc(motion);
    glutReshapeFunc(resize);

    glutMainLoop();

}



調整camera

程式碼
#include <GL/glut.h>
void display()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glPushMatrix();
        glutSolidTeapot(0.9);
    glPopMatrix();
    glutSwapBuffers();
}
void resize(int w,int h)
{
    glViewport(0,0,(GLsizei)w,(GLsizei)h);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(65.0,(GLdouble)w/h,1.0,100.0);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    gluLookAt(0.0,0.0,5.0
              ,0.0,0.0,0.0
              ,0.0,1.0,0.0);
}
void motion(int x, int y)
{
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    gluLookAt(x/100.0,y/100.0,5.0,
              0.0,0.0,0.0,
              0.0,1.0,0.0);
    glutPostRedisplay();
}
int main(int argc, char**argv)
{
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("camera");
    glutDisplayFunc(display);
    glutMotionFunc(motion);
    glutReshapeFunc(resize);

    glutMainLoop();

}

沒有留言:

張貼留言