(1).主題 : 攝影機 , 運鏡
(2).主題 : 投影 , 矩陣
(3).複習 : 移動位置 v.s. 轉動
(4).複習 : 背景貼圖
(5).期末作品
1.
先到http://www.cmlab.csie.ntu.edu.tw/~jsyeh/3dcg10/下載3個並且解壓縮
data 跟win32.dll方到window資料夾
執行project.exe
觀察glLookAt的三組參數改變之後的圖形變化
2.codeblocks建立glut專案
下載freeglut
複製libfreeglut.a改成libglut32.a(跟第一周一樣)
一直下一步
主題一:攝影機運鏡
(1)先出來空白模型
#include <GL/glut.h>///GLUT 外掛
#include "glm.h"///glm.cpp for 3D model glmReadOBJ(), glmDraw(), glmUnitized()
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();
}
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);
glutMainLoop();
return 0;
}
(2)加上打光
#include <GL/glut.h>///GLUT 外掛
#include "glm.h"///glm.cpp for 3D model glmReadOBJ(), glmDraw(), glmUnitized()
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();
}
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);
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;
}
(3)Timer函式與運鏡
#include <GL/glut.h>///GLUT 外掛#include "glm.h"///glm.cpp for 3D model glmReadOBJ(), glmDraw(), glmUnitized()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();}#include <math.h>///for sin() cos() ///NOW3float eyeX=0.5, eyeY=0, eyeZ=0; ///NOW3void timer(int t)///NOW3{ 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;}
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;}
主題二:投影矩陣
在timer函式中加上這三行
就像是檢查視野寬廣度
範圍中才能看得到
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-1,+1,-1,+1,-10,+10);
glLoadIdentity();
glOrtho(-1,+1,-1,+1,-10,+10);
.複習 : 移動位置 v.s. 轉動
.複習 : 背景貼圖
.期末作品
沒有留言:
張貼留言