1.主題:攝影機 運鏡
2.主題:投影 矩陣
3.複習:位置移動VS轉動
4.複習:背景貼圖
5.期末作品
下載WINDOWS GLUT32DLL DATA
透過main cpp把檔案弄到codeblocks打開 很酷
這個用到的都是之前交過的 但是還沒打光 所以看不到人長怎樣
glEnable(GL_DEPTH_TEST);<<深度偵測 很重要****
glEnable(GL_LIGHT0);
glEnable(GL_LIGHTING);開燈光
GLfloat light_pos[] = { 0.0, 0.0, -1.0, 0.0 };
glLightfv(GL_LIGHT0, GL_POSITION, light_pos);燈光亮度
#include <math.h> 因為用cos sin所以math函式
float eyeX=0.5, eyeY=0, eyeZ=0; 設定初始角度
void timer(int t) 時間軸
{
float angle = (t/180.0)*3.1415926; 角度公式
eyeX=0.5*cos(angle); 這我也不太懂
eyeZ=0.5*sin(angle);
glutTimerFunc(33, timer, t+1); 之前交的時間軸函式
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt( eyeX, eyeY, eyeZ,///eye ///NOW3
0, 0, 0,///center ///NOW3
0, 1, 0);///up ///NOW3
lookat>>觀看
glMatrixMode(GL_PROJECTION); 開啟ortho才不會破圖
glLoadIdentity(); ///NOW4
glOrtho(-1, +1, -1,+1, -10,+10);
--------------------------------------------------------------------
#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=4, eyeY=0, eyeZ=0; ///NOW3
float upX=0,upY=1,upZ=0;
void timer(int t)///NOW3
{
glutTimerFunc(33, timer, t+1);///NOW3
float angle = (t/180.0)*3.1415926; ///NOW3
eyeX=4*cos(angle); ///NOW3
eyeZ=4*sin(angle); ///NOW3
glMatrixMode(GL_PROJECTION); ///NOW4
glLoadIdentity(); ///NOW4
gluPerspective(60.0, 1, 1.0, 256.0);///glOrtho(-1, +1, -1,+1, -10,+10);
glMatrixMode(GL_MODELVIEW);///NOW3
glLoadIdentity();///NOW3
gluLookAt( eyeX, eyeY, eyeZ,///eye ///NOW3
0, 0, 0,///center ///NOW3
upX, upY, upZ);///up ///NOW3
glutPostRedisplay();///NOW3
}
void world_reshape(int width, int height){
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(60.0, 1, 1.0, 256.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt( eyeX, eyeY, eyeZ,///eye ///NOW3
0, 0, 0,///center ///NOW3
upX, upY, upZ);///up ///NOW3
glutPostRedisplay();
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE);
glutInitWindowSize(512,512);
glutInitWindowPosition(50, 50);
glutCreateWindow("week15-06160565");
glutReshapeFunc(world_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;
}
--------------------------------------------
world_reshape函式 當移動視窗大小 人物會維持比例 不會忽胖忽瘦
void world_reshape(int width, int height){
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(60.0, 1, 1.0, 256.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt( eyeX, eyeY, eyeZ,///eye ///NOW3
0, 0, 0,///center ///NOW3
upX, upY, upZ);///up ///NOW3
glutPostRedisplay();
}
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(60.0, 1, 1.0, 256.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt( eyeX, eyeY, eyeZ,///eye ///NOW3
0, 0, 0,///center ///NOW3
upX, upY, upZ);///up ///NOW3
glutPostRedisplay();
}
-----------------------------------------------
gluPerspective(60.0, 1, 1.0, 256.0);透視
glOrtho(-1, +1, -1,+1, -10,+10);直視
沒有留言:
張貼留言