Week 15 Camera 攝影機、投影、運鏡
第一堂課
下載windows.zip data.zip 並解壓縮
開啟檔案
開啟新的GLUT 專案 Week15-1_gluLookAt
.
新增程式碼
float eyeX = 0, eyeY = 0;
void motion(int x, int y)
{
eyeX = 3*(x-320)/320.0;
eyeY = 3*(240-y)/240.0;
glLoadIdentity();
gluLookAt(eyeX, eyeY, 3, 0, 0, -6, 0, 1, 0);
glutPostRedisplay();
}
第二堂課
gluPerspective(fovy, aspect, zNear, zFar)
fov:視野張開的角度
aspect:長寬比
開啟新GLUT專案 week15-2_gluPerspective
新增程式碼glOrtho(-ar*3, ar*3, -1.0*3, 1.0*3, 2.0, 100.0);
第三堂課
開啟新專案week15-3_gluPerspective_gluLookAt
#include <GL/glut.h>
void display(){
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glutSolidTeapot( 0.3 );
glutSwapBuffers();
}
void motion(int x, int y){
glLoadIdentity();
float eyeX = (x-150)/150.0, eyeY = (150-y)/150.0;
gluLookAt(eyeX,eyeY,1, 0, 0, 0, 0, 1,0);
glutPostRedisplay();
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
glutCreateWindow("week15");
glutMotionFunc(motion);
glutDisplayFunc(display);
glutMainLoop();
}
#include <GL/glut.h>
void display(){
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glutSolidTeapot( 0.3 );
glutSwapBuffers();
}
void motion(int x, int y){
glLoadIdentity();
float eyeX = (x-150)/150.0, eyeY = (150-y)/150.0;
gluLookAt(eyeX,eyeY,1, 0, 0, 0, 0, 1,0);
glutPostRedisplay();
}
void reshape(int w,int h){
float ar = w / (float) h;
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(60, ar,0.01,1000);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(0,0,1, 0,0,0, 0,1,0);
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
glutCreateWindow("week15");
glutReshapeFunc(reshape);
glutMotionFunc(motion);
glutDisplayFunc(display);
glutMainLoop();
}
沒有留言:
張貼留言