2020年6月17日 星期三

(*^ω^*) 喵~Week17

➽ 複習+期末作品
  • 安裝OpenCV
    • 要裝 PATH
    • CodeBlacks 要重開!!!
    • 要設定:(Setting>Compiler)
      • Search directories>Compiler
      • C:\OpenCV2.1\include
      • Search directories>Linker
      • C:\OpenCV2.1\lib
      • Linker settings
      • cv210
      • cxcore210
      • highgui210
  • 新增 GLUT專案
    • 開啟Codeblocks>>開啟new project>>OpenGL
    • 設定好 freeglut
      • 下載freegult>>將lib裡的libfreeglut.a複製一份並改名libglut32.a
      • 更改執行目錄(改成".")
      •  
      • 要將 freeglut.dll 複製到自己的目錄裡
  • 刪減範例程式
    • 網址:http://www.cmlab.csie.ntu.edu.tw/~jsyeh/3dcg10/
    • 下載  [source]
    • [glm.c]更改為[glm.cpp]
    • [glm.cpp][glm.h]拉到與專案同一層
    • 在codeblocks裡加入[glm.cpp]
    •  Gundam 的 OBJ 和 MTL 檔 和圖檔拉入專案資料夾
      • #include <GL/glut.h>
      • #include "glm.h"  ///使用 glm的外掛
      • GLMmodel * model=NULL;///指標變數, 指到 3D model
      • static void resize(int width, int height)
      • {
      •     const float ar = (float) width / (float) height;
      •     glViewport(0, 0, width, height);
      •     glMatrixMode(GL_PROJECTION);
      •     glLoadIdentity();
      •     glFrustum(-ar, ar, -1.0, 1.0, 2.0, 100.0);
      •     ///這個程式會從0,0,0看出去...我們的模式也會放0,0,0,衝突
      •     glMatrixMode(GL_MODELVIEW);
      •     glLoadIdentity() ;
      •     gluLookAt( 0,0,2, 0,0,0, 0,1,0);///我們從0,0,2看中心

      • }
      • static void display(void)
      • {
      •     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
      •     glPushMatrix();
      •         ///glutSolidTeapot(1);/// 放Teapot,等下要放 Gundam
      •         glmDraw(model, GLM_SMOOTH|GLM_TEXTURE);
      •     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);
      •     glutInitWindowSize(640,480);
      •     glutInitWindowPosition(10,10);
      •     glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);

      •     glutCreateWindow("GLUT Shapes");

      •     glutReshapeFunc(resize);
      •     glutDisplayFunc(display);
      •     
      •     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);
      •     ///我們要把 OBJ檔讀進來 (glm.cpp幫忙)
      •     model = glmReadOBJ("Gundam.obj");///讀檔
      •     glmUnitize(model);/// 縮成 -1...+1範圍
      •     glutMainLoop();
      •     return EXIT_SUCCESS;
      • }
    • 加上貼圖
      • #include <opencv/highgui.h> ///貼圖要用
      • #include <opencv/cv.h> ///貼圖要用
      • #include <GL/glut.h>
      • #include "glm.h"  ///TODO: 使用 glm的外掛
      • GLMmodel * model=NULL;///TODO: 指標變數, 指到 3D model
      • int myTexture(char *filename)
      • {
      •     IplImage * img = cvLoadImage(filename); ///OpenCV讀圖
      •     cvCvtColor(img,img, CV_BGR2RGB); ///OpenCV轉色彩 (需要cv.h)
      •     glEnable(GL_TEXTURE_2D); ///1. 開啟貼圖功能
      •     GLuint id; ///準備一個 unsigned int 整數, 叫 貼圖ID
      •     glGenTextures(1, &id); /// 產生Generate 貼圖ID
      •     glBindTexture(GL_TEXTURE_2D, id); ///綁定bind 貼圖ID
      •     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
      •      /// 貼圖參數, 超過包裝的範圖T, 就重覆貼圖
      •     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
      •      /// 貼圖參數, 超過包裝的範圖S, 就重覆貼圖
      •     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); /// 貼圖參數, 放大時的內插, 用最近點
      •     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); /// 貼圖參數, 縮小時的內插, 用最近點
      •     glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, img->width, img->height, 0, GL_RGB, GL_UNSIGNED_BYTE, img->imageData);
      •     return id;
      • }
      • static void resize(int width, int height)
      • {
      •     const float ar = (float) width / (float) height;

      •     glViewport(0, 0, width, height);
      •     glMatrixMode(GL_PROJECTION);
      •     glLoadIdentity();
      •     glFrustum(-ar, ar, -1.0, 1.0, 2.0, 100.0);
      •     ///這個程式會從0,0,0看出去...我們的模式也會放0,0,0,衝突
      •     glMatrixMode(GL_MODELVIEW);
      •     glLoadIdentity() ;
      •     gluLookAt( 0,0,2, 0,0,0, 0,1,0);///TODO: 我們從0,0,2看中心

      • }
      • static void display(void)
      • {
      •     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
      •     glPushMatrix();///TODO:
      •         ///glutSolidTeapot(1);///TODO: 放Teapot,等下要放 Gundam
      •         glmDraw(model, GLM_SMOOTH|GLM_TEXTURE);///TODO:
      •     glPopMatrix();///TODO:
      •     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);
      •     glutInitWindowSize(640,480);
      •     glutInitWindowPosition(10,10);
      •     glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);

      •     glutCreateWindow("GLUT Shapes");

      •     glutReshapeFunc(resize);
      •     glutDisplayFunc(display);

      •     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);
      •     ///TODO:我們要把 OBJ檔讀進來 (glm.cpp幫忙)
      •     model = glmReadOBJ("Gundam.obj");///TODO:讀檔
      •     glmUnitize(model);///TODO: 縮成 -1...+1範圍
      •     myTexture("Diffuse.jpg");

      •     glutMainLoop();

      •     return EXIT_SUCCESS;
      • }
  • MAYA 如何存各個部位
    • 讀入一個模型檔
    • Separate 分解
    • 選擇需要拆解的部位
    • Ctrl + G 群組起來
    • File>Export Selection 將選取部位存檔

沒有留言:

張貼留言