1.攝影機.運鏡.投影
到 http://www.cmlab.csie.ntu.edu.tw/~jsyeh/3dcg10/--> 下載: windows.zip, data.zip, glut32.dll (week03
垂直投影
透視投影
gluPerspective( 視野, a, N, F );
gluLookAt( x, y, z, <- 攝影機
x, y, z, <- 中心
x, y, z, ); <- up
-
進入transmission zero 網站,下載 freeglut 3.0.0 MinGW Package
在 CodeBlocks 開啟GLUTproject
寫攝影機.運鏡程式(使用source.zip/projection.c的程式碼):
--
///
改變程式碼(垂直投影):
#include <GL/glut.h>///GLUT 外掛 #include "glm.h"///glm.cpp for 3Dmodel glmReadOBJ(),glmDraw(),glmUnitized()
#include <math.h>///for sin() cos() //NOW3 GLMmodel * pmodel=NULL;//指標 void drawmodel(void){ if (!pmodel) { pmodel = glmReadOBJ("data/al.obj"); if (!pmodel) exit(0); glmUnitize(pmodel); glmFacetNormals(pmodel); glmVertexNormals(pmodel, 90.0); } glmDraw(pmodel, GLM_SMOOTH | GLM_MATERIAL); } void display(void){ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); drawmodel(); glutSwapBuffers(); } float eyeX=0.5, eyeY=0, eyeZ=0; //NOW3 void timer(int t){ glMatrixMode(GL_PROJECTION); ///NOW4 glLoadIdentity(); ///NOW4 glOrtho(-1, +1, -1,+1, -10,+10); ///NOW4 可看-10.+10範圍/// float angle = (t/180.0)*3.1415926; //NOW3 eyeX=0.5*cos(angle); //NOW3 eyeZ=0.5*sin(angle); //NOW3 glutTimerFunc(33, timer, t+1);//NOW3 glMatrixMode(GL_MODELVIEW);//NOW3 glLoadIdentity();//NOW3 gluLookAt( eyeX, eyeY, eyeZ,///eye //NOW3 0, 0, 0,///center //NOW3 0, 1, 0);///up //NOW3 glutPostRedisplay();//NOW3 } int main(int argc, char** argv){ glutInit(&argc, argv); glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE); glutInitWindowSize(512,512); glutInitWindowPosition(50, 50); glutCreateWindow("week15"); // glutReshapeFunc(reshape); glutDisplayFunc(display); glutTimerFunc(33, timer, 0);//NOW3 GLfloat light_pos[] = { 0.0, 0.0, 1.0, 0.0 }; glEnable(GL_DEPTH_TEST); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glLightfv(GL_LIGHT0, GL_POSITION, light_pos); glutMainLoop(); return 0; }
改變程式碼(透視投影):
#include <GL/glut.h>///GLUT 外掛 #include "glm.h"///glm.cpp for 3D model glmReadOBJ(), glmDraw(), glmUnitized() #include <math.h>//for sin()cos()//NOW3
GLMmodel * pmodel=NULL;//指標 void drawmodel(void) { if (!pmodel) { pmodel = glmReadOBJ("data/al.obj"); if (!pmodel) exit(0); glmUnitize(pmodel); glmFacetNormals(pmodel); glmVertexNormals(pmodel, 90.0); } glmDraw(pmodel, GLM_SMOOTH | GLM_MATERIAL); } void display(void){ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); drawmodel(); glutSwapBuffers(); } float eyeX=2, eyeY=0, eyeZ=0; //NOW3 void timer(int t){ glMatrixMode(GL_PROJECTION); ///NOW4 glLoadIdentity(); ///NOW4 gluPerspective(60, 1.0, 0.001, 1000);///NOW5/// float angle = (t/180.0)*3.1415926; //NOW3 eyeX=2*cos(angle); //NOW3 eyeZ=2*sin(angle); //NOW3 glutTimerFunc(33, timer, t+1);//NOW3 glMatrixMode(GL_MODELVIEW);//NOW3 glLoadIdentity();//NOW3 gluLookAt( eyeX, eyeY, eyeZ,//eye ///NOW3 0, 0, 0,//center ///NOW3 0, 1, 0);//up ///NOW3 glutPostRedisplay();//NOW3 } int main(int argc, char** argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE); glutInitWindowSize(512,512); glutInitWindowPosition(50, 50); glutCreateWindow("week15"); // glutReshapeFunc(reshape); glutDisplayFunc(display); glutTimerFunc(33, timer, 0);//NOW3 GLfloat light_pos[] = { 0.0, 0.0, 1.0, 0.0 }; glEnable(GL_DEPTH_TEST); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glLightfv(GL_LIGHT0, GL_POSITION, light_pos); glutMainLoop(); return 0; }
沒有留言:
張貼留言