顯示具有 40447011S_余瑞得 標籤的文章。 顯示所有文章
顯示具有 40447011S_余瑞得 標籤的文章。 顯示所有文章

2017年12月14日 星期四

余瑞得 week 14

畫裡面有顏色的三角形

加入深度資訊後


可以看見vertex(X,Y,Deep) deep大的會放在上面

余瑞得 week 13

P語言 RGB HSB
1.如果是RGB
    
2.如果是HSB
    

茶壺軌跡
    

2017年11月30日 星期四

余瑞得 week 12

編譯老師的檔案
1. 建立GLUT專案
2. compiler設定 不要用C++ 11
3. 補code
   
    (argc argv glutinit)
4.把txt檔案放到freeglut資料夾內
   
5. compile
    

開P語言的範例程式
1. 下載P語言
2. 打開後進library 搜尋sketch-library
3. 下載Collada loader for ... & Picking
    
4. 開啟Viewer2D
    
5. 可以把上面model的部分選擇開啟或關閉
    
6. Viewer 2D完後看Picking 的Simple範例
    
    會發現 滑鼠移到橘色方塊時會選出的值為0 因此邊框也會印出橘色
    移到黃色方塊時選出1 邊框印出黃色 其他都選到-1  印出黑色

開啟老師寫的P語言
1. 打開看看
    
2. 可以看看資料夾內的bvh檔案

2017年11月23日 星期四

余瑞得 week 11

開啟wav音檔
1.需要include <mmsystem.h>
2.code PlaySoundA("filename.wav",NULL,SND_ASYNC); 
                         ///snd_sync 等同步 async 不等 下一行繼續
3.以GLUT專案為底寫出的code
   
4.跑出來(有聲音可是沒辦法表示)
   
5.播放Mp3的檔案
   
6.code解釋
    #include "CMP3_MCI.h"
    CMP3_MCI mp3; ///變數宣告   //全域
    main 內
    mp3.Load("file.mp3");
    mp3.Play(); //播放
    #####切記檔案要放在freeglut的bin中#####

Processing code for open Mp3 file
1.安裝P語言然後安裝Minim library
   
2.寫code 上面import就是類似call include
   
   ####記得要把檔案拉進P語言中 不然會找不到檔案####

2017年11月16日 星期四

余瑞得 week 10

利用processing code寫Android程式
1. 先下載processing 並安裝
2. 打開後於右上角新增模式->選擇android mode
3. 安裝完後會跳一個通知要裝SDK 選自動安裝
4. 變換mode就能開始安裝了

沒有連手機所以不能跑

2017年11月9日 星期四

余瑞得 week 9

Bump mapping (讓圖形有凹凸面)

1. 範例看看(https://www.openprocessing.org/sketch/249457)
2. moodle 內下載 processing 3 安裝
3.把範例copy paste到processing

4. 自己畫出一個四邊形

5. 如何call圖 (記得要把圖拉進去processing 才能讀圖檔)

6. 如何利用滑鼠決定要在哪裡畫圖

7. 做個簡單mario


















/// processing code
int [][]map={{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
              {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
              {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
              {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
              {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
              {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
              {0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0},
              {0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0},
              {0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0},
              {0,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0},
              {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
              {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
              {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
              {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
              {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
              {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}};
PImage img;
PImage brick;
void setup(){
   size(800,800);
  img=loadImage("mario.png");
  brick=loadImage("Brick.png");
}
float marioX=200,marioY=50,marioVY=0,marioVX=0;
boolean marioOnFloor=false;
void draw(){
  background(255); //redraw background
  for(int i=0;i<16;i++){
    for(int j=0;j<16;j++)
  {
    if(map[j][i]==1)image(brick,i*50,j*50,50,50);}}
  image(img,marioX,marioY,100,100);
  marioY+=marioVY;
  marioX+=marioVX;
  marioVY+=0.98;
  if(marioY>=750-100) {marioY=750-100;marioVY=0;marioOnFloor=true;}
}
void keyPressed(){
  if(keyCode==UP && marioOnFloor){marioVY=-15;marioOnFloor=false;}
  if(keyCode==RIGHT) marioVX=5;
  if(keyCode==LEFT) marioVX=-5;
}
void keyReleased(){
  if(keyCode==RIGHT || keyCode==LEFT) marioVX=0;
}
 

2017年11月2日 星期四

余瑞得 week 8

Texture
1. 進入jsyeh/3dcg10/ 下載 source data win32 glut32.dll
2.

    glTexCoord2f(0.0,0.0); 左邊為X右邊為y
    glVertex3f(-1.0,-1.0,0.0); X,Y,Z軸

3.去moodle下載 OpenCV-2.1.0-win32-vs2008.exe 後安裝
4. CodeBlocks -> new project -> Console application
5. 設定以下三個path (對左欄位的專案檔點右鍵選build option)



6.把main的code改掉 下載一張照片改好名子丟到project所在資料夾 然後就可以build了


讓glut跟opencv共存
1.開一個glut專案
2.設定opencv的path
3.把圖片拉到freeglut的bin資料夾
4.在main的 main函式裡新增opencv的函式 (記得要include)

5.run 會先跑出圖片 然後按任意鍵會出現glut的視窗


讓opencv的圖可以在glut檔中轉
1.先照上面弄出可以共存的專案
2.複製code進去main
3.

2017年10月26日 星期四

2017年10月19日 星期四

余瑞得 week 6

1.先照上周的方法開啟專案
2.利用CPP檔案中的部分code弄出一隻沒有顏色的人
3.增加打光函式 讓角色有陰影深度
/* code 解釋
    GLfloat light_pos[] = { 0.0, 0.0, -1.0, 0.0 };///  position 表打燈的位置
    glEnable(GL_DEPTH_TEST);/// 啟用深度測試
    glEnable(GL_LIGHTING);///  啟用燈光功能
    glEnable(GL_LIGHT0);///  啟用第0盞燈
    glLightfv(GL_LIGHT0, GL_POSITION, light_pos);///  用第0盞燈 後面是打燈的位置  上面有設定從後面打燈
*/
4.增加滑鼠跟鍵盤指令
/*
    void keyboard(unsigned char key,int x,int y)
keyboard 會回傳 鍵值 跟滑鼠位置
    glutMouseFunc(mouse);/// glut的mouse fun
    glutKeyboardFunc(keyboard);/// glut 的 keyboard fun
*/
5.最後有新增根據滑鼠鍵盤做轉動但不太能實際表現出來所以下面只附code

#include <GL/glut.h>
#include "glm.h"
GLMmodel* pmodel = NULL;
float glx=0,gly=0,glz=0;
void keyboard(unsigned char key,int x,int y) ///
{
    printf("%c (%d %d)\n",key,x,y);
    if(key=='1') glx+=10;
    if(key=='2') gly+=10;
    if(key=='3') glz+=10;
    glutPostRedisplay();
}
float oldx=0,oldy=0,oldz=0;
void mouse(int button,int state,int x,int y,int z) ///
{
    printf("p %d %d\n",button,state);
    if(state==GLUT_DOWN && button==1)
    {
        oldx=x;
        oldy=y;
    }
    if(state==GLUT_DOWN)
    {
        oldx=x;
        oldy=y;
    }
}
void motion(int x,int y,int z) ///
{
   // glx+=(oldy-y);
  //  gly+=(oldx-x);
    glz+=((oldx-x)+(oldy-y))/2;
    oldx=x,oldy=y,oldz=((oldx-x)+(oldy-y))/2;
    glutPostRedisplay();
}
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);
}
GLfloat light_pos[] = { 0.0, 0.0, -1.0, 0.0 };///
void display()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glPushMatrix();    //把現在的原點push進stack
        glRotatef(glx,1,0,0);           // (角度,x軸,y軸,z軸)
        glRotatef(gly,0,1,0);
        glRotatef(glz,0,0,1);
        drawmodel();
    glPopMatrix();   //把點pop回來
    glutSwapBuffers();

}
int main(int argc, char**argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("week05");
    glutMouseFunc(mouse);///
    glutKeyboardFunc(keyboard);///
    glutMotionFunc(motion);
    glEnable(GL_DEPTH_TEST);///
    glEnable(GL_LIGHTING);///
    glEnable(GL_LIGHT0);///
    glLightfv(GL_LIGHT0, GL_POSITION, light_pos);///
    glutDisplayFunc(display);

    glutMainLoop();
}

2017年10月12日 星期四

余瑞得 week 5

Run 範例程式
1.下載範例程式 (http://www.cmlab.csie.ntu.edu.tw/~jsyeh/3dcg10/)
2.下載的檔案有 windows.zip   glut32.dll   data.zip  等三個
3.把windows.zip那個解壓縮出一個資料夾後把glut32.dll複製進去
4.把data.zip資料夾解壓縮進去

↑外觀
↓內容

5.按transformation.exe開始跑

6.perspective投影法

↑ fov:視野(視界大小)aspect:視野寬窄  zNear:前界 zFar:後界
       (影像在前後界中間才會顯示)
   eye 是以人眼睛去做旋轉,所以會環繞著物體轉
   center 是以中心去做旋轉,所以可能轉一邊就看不到物體了
   up 是以哪軸為上,像是範例中的y=1就是以正Y軸為上
7.orthogonal投影法

↑left 左界 right右界 bottom下界 top上界 near前界 far後界 形成一個框框 框框中的影像才會顯示
8.把別的人檔案打開

  i.先開個glut專案
  ii.把source檔裡面的東西拉進專案資料夾
  iii.把data拉進freeglut的bin裡面
  iv.把source拉進資料夾的東西取代原本的main
  v.執行

9.