1.
step1: 下載 freeglut-MinGW-3.0.0-1.mp.zip
step2: 進到資料夾,把檔案 freeglut 拉到桌面
step3: 點進 freeglut 👉 lib 資料夾
step4: 複製 libfreeglut.a 並且改名為libglut32.a
step5: 開啟code blocks
step6: 開新專案,專案名稱: week11-0_sample
2.
step1: 開新專案,專案名稱: week11-1_TRT_again
step2: 複製 week10-1_TRT_glutSolidCube_myBody_myArm 的程式碼
註: 小心中文問題
step3: 搭出 T-R-T 的程式碼
void myArm()
{
glPushMatrix();
glColor3f(0, 1, 0); ///綠色的手臂
glScalef(1.5, 0.5, 0.5); ///寬變1.5,高度變0.5倍
glutWireCube( 0.3 ); ///方塊
glPopMatrix();
}
float angle=0;
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
///glTranslatef(-0.6, +0.3, 0);
myBody();
glPopMatrix();
glPushMatrix();
glTranslatef(0.3, 0.3, 0); ///掛到肩上
glRotatef(angle++, 0, 0, 1); ///轉動
glTranslatef(0.45/2, 0, 0); ///把旋轉中心,放正中心
myArm();
glPopMatrix();
glutSwapBuffers();
}
int main(int argc, char *argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("GLUT Shapes");
glutIdleFunc(display);
glutDisplayFunc(display);
glutMainLoop();
}
3.
step1: 開新專案,專案名稱: week11-2_obj_gundam_opencv_texture_lighting
step2: 安裝 OpenCV 要勾 Add PATH (第二個),裝在預設目錄
👉 Setting-Compiler 裡,要把 OpenCV 的三個設定設好
👇
(1) 重開 CodeBlocks
👇 原本的檔案在 View 👉 Start Page
(2) 在 Search directories 加入2個目錄
1-1 Compiler 👉 C:\OpenCV2.1\include
1-2 Linker 👉 C:\OpenCV2.1\lib
(3) 在 Linker setting 裡,加入 👉 cv210
👉 cxcore210
👉 highgui210
step3: 專案的設定是否需要修改 (專案的右鍵,Properties)
step4: 到專案,在專案名稱上按右鍵,Add File 將glm.cpp 加入專案
step5: 因無法順利執行,需到檔案內容修改
👉 專案名稱上按右鍵,選最下面的 Properties ,跳出視窗,選第2個 Build targets
👉 把 Execution working dir 工作執行目錄,改成小數點"."
註: 參考 Week07 筆記
step6: 利用 git clone https://github.com/你的帳號/2024graphicsb
把雲端程式拿下來, week09-1 是我們要用的專案,複製過來用
step7: 複製資料夾到桌面後,把檔名
week09-1_obj_gundam_opencv_texture_lighting
改 👇
week11-2_obj_gundam_opencv_texture_lighting
step8: 再用 CodeBlocks 開起來。
step9: 用 Project-Properties 去改 Title
step10: 到 Maya 👉 File 👉 Import 👉 Gundam.obj
step11: 只留左手臂: hand1.obj 匯出(右手臂也要: hand2.obj)
👉 要選取才能匯出 Export Selection 👉 檔案類型選 OBJexport
👉 直接匯出 Export All 👉 檔案類型選 OBJexport
step12: 回到 CodeBlocks 改模型檔名
4.
step1: 複製整個專案 week11-2_obj_gundam_opencv_texture_lighting
改 👇
week11-3_obj_gundam_hand1_hand2
step2: 再把裡面的 .cbp 檔名也改成 week11-3_obj_gundam_hand1_hand2
step3: 複製 hand1、hand2 的 .obj、.mtl 模型檔到 week11-3 的目錄
step4: 到 CodeBlocks 的 File-Open,開啟 week11-3 的 .cbp 檔
step5: 修改程式碼
GLMmodel * pmodel = NULL; ///加的程式,有顆指標,指到模型檔
GLMmodel * hand1 = NULL;
GLMmodel * hand2 = NULL;
void drawmodel(void)
{
if(!pmodel){
pmodel = glmReadOBJ("Gundam.obj");
if(!pmodel) exit(0);
glmUnitize(pmodel);
glmFacetNormals(pmodel);
glmVertexNormals(pmodel, 90.0);
}
glmDraw(pmodel, GLM_SMOOTH | GLM_TEXTURE);
}
void drawhand1(void)
{
if(!hand1){
hand1 = glmReadOBJ("hand1.obj");
if(!hand1) exit(0);
glmUnitize(hand1);
glmFacetNormals(hand1);
glmVertexNormals(hand1, 90.0);
}
glmDraw(hand1, GLM_SMOOTH | GLM_TEXTURE);
}
void drawhand2(void)
{
if(!hand2){
hand2 = glmReadOBJ("hand2.obj");
if(!hand2) exit(0);
glmUnitize(hand2);
glmFacetNormals(hand2);
glmVertexNormals(hand2, 90.0);
}
glmDraw(hand2, GLM_SMOOTH | GLM_TEXTURE);
}
float angle=0;
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glutSolidSphere( 0.1, 30, 30);
glPushMatrix();
//glRotatef(angle++, 0, 1, 0);
///掛到肩上
///轉動
///把旋轉中心,放正中心
drawhand1(); ///glutSolidTeapot( 0.3 );
glPopMatrix();
glutSwapBuffers();
}
step6: 加上 T-R-T
👇
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glutSolidSphere( 0.1, 30, 30);
glPushMatrix();
//glRotatef(angle++, 0, 1, 0);
glTranslatef(-0.3, 0.3, 0); ///掛到肩上
//glRotatef(angle++, 0, 0, 1); ///轉動
glTranslatef(-0.45/2, 0, 0); ///把旋轉中心,放正中心
drawhand1(); ///glutSolidTeapot( 0.3 );
glPopMatrix();
glPushMatrix();
//glRotatef(angle++, 0, 1, 0);
glTranslatef(0.3, 0.3, 0); ///掛到肩上
//glRotatef(angle++, 0, 0, 1); ///轉動
glTranslatef(0.45/2, 0, 0); ///把旋轉中心,放正中心
drawhand2(); ///glutSolidTeapot( 0.3 );
glPopMatrix();
glutSwapBuffers();
}
沒有留言:
張貼留言