❤攝影機的運鏡❤
1.先下載老師給的data,win32,glut32.dll,source
http://www.cmlab.csie.ntu.edu.tw/~jsyeh/3dcg10/
2.將window.zip解壓縮到window資料夾,複製glut32.dll到window資料夾裡
3.打開Projection.exe來試試看運鏡
❤實作攝影機的運鏡❤
4.先開啟freeglut windows網站 https://www.transmissionzero.co.uk/software/freeglut-devel/
然後解壓縮然後打開lib資料夾,複製貼上libfreeglut.a,把複製的改名為libglut32.a
5.打開codeblack先建一個glut然後開啟執行,並把本來的程式刪光光
6.把source資料夾裡的glm.c,glm.h,projection.c複製到week15的資料夾
並把glm.c改成glm.cpp
7.新增glm.cpp進來
(用note++打開projection.c參考)
8.把window的data複製到freeglut的bin資料夾
9.打出程式碼
------------程式碼------------
#include <GL/glut.h>
#include "glm.h" ///for glmReadOBJ(), glmDraw(), glmUnitized()....
GLMmodel * pmodel=NULL;///NOW
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_DOUBLE | GLUT_DEPTH);
glutInitWindowSize(500,500);
glutCreateWindow("week15");
glutDisplayFunc(display);
glutMainLoop();
}
(會做出一個白色的人)
10.再增加色彩(打光)程式碼
------------程式碼------------
#include <GL/glut.h>
#include "glm.h" ///for glmReadOBJ(), glmDraw(), glmUnitized()....
GLMmodel * pmodel=NULL;///NOW
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_DOUBLE | GLUT_DEPTH);
glutInitWindowSize(500,500);
glutCreateWindow("week15");
glutDisplayFunc(display);
GLfloat light_pos[] = { 0.0, 0.0, -1.0, 0.0 };///NOW2 打光的位置
glEnable(GL_DEPTH_TEST);///NOW2 有立體的功能
glEnable(GL_LIGHT0); ///NOW2 打光後變立體的彩色的
glEnable(GL_LIGHTING); ///NOW2 打光後變立體的彩色的
glLightfv(GL_LIGHT0, GL_POSITION, light_pos);///NOW2 打光的位置
glutMainLoop();
}
11.再增加運鏡的程式碼
------------程式碼------------
#include <GL/glut.h>
#include "glm.h" ///for glmReadOBJ(), glmDraw(), glmUnitized()....
GLMmodel * pmodel=NULL;///NOW
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>
float eyeX=1, eyeY=0, eyeZ=0;
void timer(int t)///NOW3
{
glutTimerFunc(33, timer, t+1);///NOW3
float angle=t/180.0*3.1415926;///NOW3 算出一個角度
eyeX=cos(angle); eyeZ=sin(angle);///NOW3
glMatrixMode(GL_MODELVIEW);///NOW3
glLoadIdentity();///NOW3
gluLookAt(eyeX, eyeY, eyeZ, ///NOW3 LookAt的 eye
0.0, 0.8, 0.0, ///NOW3 LookAt的 center
0, 1, 0);///NOW3 LookAt的 up
glutPostRedisplay();///NOW3 Re-display
}
int main(int argc, char**argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutInitWindowSize(500,500);
glutCreateWindow("week15");
glutDisplayFunc(display);
glutTimerFunc(33, timer, 0);///NOW3
GLfloat light_pos[] = { 0.0, 0.0, -1.0, 0.0 };///NOW2 打光的位置
glEnable(GL_DEPTH_TEST);///NOW2 有立體的功能
glEnable(GL_LIGHT0); ///NOW2 打光後變立體的彩色的
glEnable(GL_LIGHTING); ///NOW2 打光後變立體的彩色的
glLightfv(GL_LIGHT0, GL_POSITION, light_pos);///NOW2 打光的位置
glutMainLoop();
}
12.再調整要讓人物呈現的更自然
------------程式碼------------
#include <GL/glut.h>
#include "glm.h" ///for glmReadOBJ(), glmDraw(), glmUnitized()....
GLMmodel * pmodel=NULL;///NOW
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>
float eyeX=1, eyeY=0, eyeZ=0;
void timer(int t)///NOW3
{
glutTimerFunc(33, timer, t+1);///NOW3
float angle=t/180.0*3.1415926;///NOW3 算出一個角度
eyeX=cos(angle); eyeZ=sin(angle);///NOW3
glMatrixMode(GL_PROJECTION);///NOW4
glLoadIdentity();///NOW4
glOrtho(-1,+1, -1,+1, -10,+10);///NOW4 可以看到範圍比較大的投影法
glMatrixMode(GL_MODELVIEW);///NOW3
glLoadIdentity();///NOW3
gluLookAt(eyeX, eyeY, eyeZ, ///NOW3 LookAt的 eye
0.0, 0.6, 0.0, ///NOW3 LookAt的 center
0, 1, 0);///NOW3 LookAt的 up
glutPostRedisplay();///NOW3 Re-display
}
int main(int argc, char**argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutInitWindowSize(500,500);
glutCreateWindow("week15");
glutDisplayFunc(display);
glutTimerFunc(33, timer, 0);///NOW3
GLfloat light_pos[] = { 0.0, 0.0, 1.0, 0.0 };///NOW2 打光的位置
glEnable(GL_DEPTH_TEST);///NOW2 有立體的功能
glEnable(GL_LIGHT0); ///NOW2 打光後變立體的彩色的
glEnable(GL_LIGHTING); ///NOW2 打光後變立體的彩色的
glLightfv(GL_LIGHT0, GL_POSITION, light_pos);///NOW2 打光的位置
glutMainLoop();
}
------------程式碼------------
#include <GL/glut.h>
#include "glm.h" ///for glmReadOBJ(), glmDraw(), glmUnitized()....
GLMmodel * pmodel=NULL;///NOW
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>
float eyeX=1, eyeY=0, eyeZ=0;
void timer(int t)///NOW3
{
glutTimerFunc(33, timer, t+1);///NOW3
float angle=t/180.0*3.1415926;///NOW3 算出一個角度
eyeX=cos(angle); eyeZ=sin(angle);///NOW3
glMatrixMode(GL_PROJECTION);///NOW4
glLoadIdentity();///NOW4
gluPerspective(60, 1, 0.001, 1000);///NOW5
///glOrtho(-1,+1, -1,+1, -10,+10);///NOW4 可以看到範圍比較大的投影法
glMatrixMode(GL_MODELVIEW);///NOW3
glLoadIdentity();///NOW3
gluLookAt(eyeX, eyeY, eyeZ, ///NOW3 LookAt的 eye
0.0, 0.6, 0.0, ///NOW3 LookAt的 center
0, 1, 0);///NOW3 LookAt的 up
glutPostRedisplay();///NOW3 Re-display
}
int main(int argc, char**argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutInitWindowSize(500,500);
glutCreateWindow("week15");
glutDisplayFunc(display);
glutTimerFunc(33, timer, 0);///NOW3
GLfloat light_pos[] = { 0.0, 0.0, 1.0, 0.0 };///NOW2 打光的位置
glEnable(GL_DEPTH_TEST);///NOW2 有立體的功能
glEnable(GL_LIGHT0); ///NOW2 打光後變立體的彩色的
glEnable(GL_LIGHTING); ///NOW2 打光後變立體的彩色的
glLightfv(GL_LIGHT0, GL_POSITION, light_pos);///NOW2 打光的位置
glutMainLoop();
}
沒有留言:
張貼留言