(1)主題:攝影機,運鏡
(2)主題:投影,矩陣
(3)主題:動畫
(4)期末作品
1.進入http://www.cmlab.csie.ntu.edu.tw/~jsyeh/3dcg10/ ,下載data win32 glut32.dll
2.將windows解壓縮,再把解壓縮的data和glut.dll放到windows的解壓縮檔裡面
3.打開project.exe檔案,調整eye的座標可以改變相機的角度
4.調整center的座標可以改變主角,例如將center的x軸調整到-值,就可以將主角變為右手
5.進入https://www.transmissionzero.co.uk/software/freeglut-devel/下載
freeglut 3.0.0 MinGW Package
7.將data丟入freeglut的bin裡面,再把source裡面的glm.h和glm.c(改成glm.cpp)還有projection.c丟入剛開啟的glut資料夾裡面。
8.在codeblocks裡面add file把glm.cpp匯入,就可以在codeblocks裡面執行project.c的檔案
9.將老師上課的程式碼套用到codeblocks裡面可以出現projection.exe檔案裡面的人物且變成白色
10.套用step02-3的程式碼,將GLfloat light_pos改成0.0, 1.0, -1.0, 0.0
程式碼:
#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=0.5, eyeY=0, eyeZ=0; ///NOW3
void 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, 1.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;
}
11.套用step02-4的程式碼,可以將projection檔案的人物完整的顯示在畫面中
程式碼:
#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=0.5, eyeY=0, eyeZ=0; ///NOW3
void timer(int t)///NOW3
{
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;
}
若把-10,10改成3,3視野就會變小,只能看到部分的手
glMatrixMode(GL_PROJECTION); ///NOW4
glLoadIdentity(); ///NOW4
glOrtho(-1, +1, -1,+1, -10,+10);
沒有留言:
張貼留言