2015年5月20日 星期三

2015/5/20week13 課堂作業 黃志楷

今日目標:投影矩陣,攝影機運鏡

目標:垂直投影


#include<GL/glut.h>
void display()
{
    glPushMatrix();
        glutSolidTeapot(100);
    glPopMatrix();
    glFlush();
}
int main(int argc,char *argv[])
{
    glutInit(&argc,argv);
    glutInitWindowSize(800,600);
    glutCreateWindow("02160421");
    glutDisplayFunc(display);
    glViewport(0,0,800,600);
    glMatrixMode(GL_PROJECTION);
    glOrtho(-400,400,-300,300,-1000,1000);
    glMatrixMode(GL_MODELVIEW);
    glutMainLoop();
}


目標:拖動視窗大小,物件不會變動大小

#include<GL/glut.h>
void display()
{
    glPushMatrix();
        glutSolidTeapot(100);
    glPopMatrix();
    glFlush();
}
void reshape(int w,int h)
{
    glViewport(0,0,w,h);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(-w/2,w/2,-h/2,h/2,-1000,1000);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
}
int main(int argc,char *argv[])
{
    glutInit(&argc,argv);
    glutInitWindowSize(400,300);
    glutCreateWindow("02160421");
    glutDisplayFunc(display);
    glutReshapeFunc(reshape);
    glutMainLoop();
}

目標:進行運鏡


#include<GL/glut.h>
float eyex=-100,eyey=80,eyez=-200;
void display()
{
    GLfloat pos[]={0,0,200,0};
    glLightfv(GL_LIGHT0,GL_POSITION,pos);
    glEnable(GL_LIGHT0);
    glEnable(GL_NORMALIZE);
    glEnable(GL_LIGHTING);

    glEnable(GL_DEPTH_TEST);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glPushMatrix();
        gluLookAt(eyex,eyey,eyez,0,0,0,0,1,0);
        glPushMatrix();
        glutSolidTeapot(100);
    glPopMatrix();
    glPopMatrix();
    glFlush();
}
void motion(int x,int y)
{
    eyex=x-400;
    eyey=300-y;
    glutPostRedisplay();
}
void reshape(int w,int h)
{
    glViewport(0,0,w,h);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(90,w/h,0.001,10000);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
}
void timer(int t)
{
    glutTimerFunc(20,timer,t+1);
    eyex+=2;
    if(eyex>300)eyey+=4;
    glutPostRedisplay();
}
int main(int argc,char *argv[])
{
    glutInit(&argc,argv);
    glutInitWindowSize(800,600);
    glutCreateWindow("02160421");
    glutDisplayFunc(display);
    glutReshapeFunc(reshape);
    glutMotionFunc(motion);
    glutTimerFunc(0,timer,0);
    glutMainLoop();
}



沒有留言:

張貼留言