一、開啟模擬移動、旋轉、縮放程式
1. 連至jsyeh.org/3dcg10,並下載[data]、[win32]、 glut32.dll
2.下載完後新增一個資料夾,將[data]、[win32]解壓縮裡的檔案拉進去,以及 glut32.dll也拉進去
3.執行 Transformation.exe ,就可以模擬了
二、模擬透視投影
1.一樣在剛剛執行 Transformation.exe的資料夾,執行 Projection.exe
就可以模擬了
2.按右鍵,可以切換不同函式(參數)去模擬
(1)gluPerspective(fovy(視野),aspect(y/x比例),zNear,zFar)
(2)gluOrtho(左,右,下,上,近,遠)
gluFrustum(左,右,下,上,近,遠)
(3)gluLookAt(eyeX,eyeY,eyeZ,centerX,centerY,centerZ,upX,up Y,upZ)
eye為視角位置,center為物體位置,up為視角的轉動
三、建構簡單透視投影程式
1.連至jsyeh.org/3dcg10,並下載[source]
將裡頭的 glm.c glm.h projection.c拉出來
並將projection.c改成以下簡短程式
#include <GL/glut.h>
#include "glm.h"
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()
{
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);
glutCreateWindow("week05");
glutDisplayFunc(display);
glutMainLoop();
}
就可以執行了
#strdup() 為字串複製,glm.c裡的寫法同時為c/c++c混合,所以可能無法執行。





沒有留言:
張貼留言