Week15 課堂重點
主題:投影矩陣、攝影機與運鏡
下載檔案開始↓
2、解壓縮檔案C:\Users\user\Downloads\windows\data
如圖
3、點開Windows資料夾裡的Projection
II 實作
1、下載Freeglut windows檔案解壓縮
打開project的libglut32.a檔
2、到網站(3D Graphics)下載source檔
解壓縮圖中檔案到code block開的專案資料夾
3、回到libglut32.a檔加入檔案如圖
選擇glm.cpp檔
4、清除libglut32.a中的程式
複製projection.c的程式碼放進main.cpp
5、把在3D Graphics 下載的data放進freeglut的bin資料夾中就OK了
2、還沒打光的成果
3、加上打光程式
投影幕設置問題還看不清楚
4、調整投影大小
2、到網站(3D Graphics)下載source檔
解壓縮圖中檔案到code block開的專案資料夾
3、回到libglut32.a檔加入檔案如圖
選擇glm.cpp檔
4、清除libglut32.a中的程式
複製projection.c的程式碼放進main.cpp
5、把在3D Graphics 下載的data放進freeglut的bin資料夾中就OK了
III 實作
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、還沒打光的成果
3、加上打光程式
#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;
}
投影幕設置問題還看不清楚
4、調整投影大小
#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() ///NOW3
float eyeX=2, eyeY=0, eyeZ=0; ///NOW3
void timer(int t)///NOW3
{
glMatrixMode(GL_PROJECTION); ///NOW4
glLoadIdentity(); ///NOW4
///glOrtho(-1, +1, -1,+1, -10.0,10.0); ///NOW4 你可以看到 -10...+10範圍
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;
}
沒有留言:
張貼留言