這週上課內容
(1)組出機器人(2)做出可轉動的關節
(3)錄製動作
(4)回家作業
先google:3D explorationo1.18版本 並下載其檔案
再至jsyeh.org/3dcg10下載data.zip(有3D模型可用)
開啟3D exploration後在開啟data內的模型(soccerball)
再另存新檔save as 出現框框後更改Sample APP
接著開啟CodeBlock->File->New project->OpenGL project
將原本的main.c刪掉
加入exploration內的soccerball.cpp
接著在專案那點選add File
將錯誤地方的程式碼註解掉執行後如下圖。
收到檔案
(1)myGLMsample.zip
(2)data.zip
(3)source.zip{glm.c
glm.h
transformation
(4)freeglut.zip
利用exporation內的Dolphins模組
將其分開存檔

將這三個Dolphins放入data內資料夾
#include <string.h>
#include <stdlib.h>
#include <GL/glut.h>
#include "glm.h"
GLMmodel* pmodel = NULL;
float angle=0;
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
angle++;
glRotated(angle,0,1,0);
if(!pmodel){
pmodel=glmReadOBJ("data/dolphins2.obj");
if(!pmodel)exit(0);
glmUnitize(pmodel);
glmFacetNormals(pmodel);
glmVertexNormals(pmodel,90.0);
}
glmDraw(pmodel,GLM_SMOOTH|GLM_MATERIAL);
glPopMatrix();
glutSwapBuffers();
}
const GLfloat light_ambient[] = { 0.0f, 0.0f, 0.0f, 1.0f };
const GLfloat light_diffuse[] = { 1.0f, 1.0f, 1.0f, 1.0f };
const GLfloat light_specular[] = { 1.0f, 1.0f, 1.0f, 1.0f };
const GLfloat light_position[] = { 2.0f, 5.0f, -5.0f, 0.0f };
const GLfloat mat_ambient[] = { 0.7f, 0.7f, 0.7f, 1.0f };
const GLfloat mat_diffuse[] = { 0.8f, 0.8f, 0.8f, 1.0f };
const GLfloat mat_specular[] = { 1.0f, 1.0f, 1.0f, 1.0f };
const GLfloat high_shininess[] = { 100.0f };
int main(int argc, char**argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH | GLUT_RGB);
glutCreateWindow("Yes, 3D Model Here");
glutDisplayFunc(display);
glutIdleFunc(display);
glClearColor(1,1,1,1);
//glEnable(GL_CULL_FACE);
//glCullFace(GL_BACK);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LESS);
glEnable(GL_LIGHT0);
glEnable(GL_NORMALIZE);
glEnable(GL_COLOR_MATERIAL);
glEnable(GL_LIGHTING);
glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);
glLightfv(GL_LIGHT0, GL_POSITION, light_position);
glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
glMaterialfv(GL_FRONT, GL_SHININESS, high_shininess);
glutMainLoop();
}




沒有留言:
張貼留言