顯示具有 04163031_溫淳安 標籤的文章。 顯示所有文章
顯示具有 04163031_溫淳安 標籤的文章。 顯示所有文章

2017年6月6日 星期二

Week12

(1)3D TRT轉動
(2)矩陣,投影矩陣
(3)攝影機運鏡
(4)會動的機器人
(5)(補)MP3播放


一.播放MP3檔

先去FB下載CMP3_MCI.h檔



再開啟codeblocks專案

把MP3檔放到專案資料夾中


輸入程式碼

#include <iostream>
#include "CMP3_MCI.h" 
///(1) 放在同一個程式碼專案的目錄中哦
CMP3_MCI myMP3; ///(2) 宣告一個變數,叫 myMP3
using namespace std;
int main()
{
    myMP3.Load("yukai.mp3");  /// Load檔案   
    myMP3.Play(); /// (4) Play the file 播放   
    int n;
    cin>>n;
    cout << "Hello world!" << endl;
    return 0;
}












2017年5月23日 星期二

Week14

(1)上週作業

(2)讓機器人動
(3)Timer計時器
(4)鍵盤滑鼠控制
(5)機器人2.0

TODO:
1..cbp專案檔 用Notepad++開include目錄.lib目錄設對working目錄.設 "."(句點)
2.Build&Run
3.Week14_01timer.cpp
4.Week14_02pushTRTpop_Left.cpp
   4-1 把函式拉出去:drawBody()
                                  drawArm0()
                                  drawArm1()
   4-2經常把函式暫時註解
        讓畫面乾淨,好判斷T-R-T
   4-3先把上手臂搞定
        再把下手臂搞定
5.Week14_03pushTRTpop.Right.cpp
6.Week14_04mouseRotateAngle.cpp
   可用mouse轉角度
   

2017年5月16日 星期二

Week13

(1)小考:T-R-T觀念
(2)上週範例
(3)讀圖檔
(4)貼圖設定
(5)轉動的地球
(6)回家作業:機器人





ans:

glPushMatrix();
   glTranslatef(0.6, 0.4, 0);///(3)最後把"會照著手肘中心轉動的手"移動,掛到真的世界畫面裡
   glRotatef(-80, 0,0,1);///(2)旋轉(小心,移動的正負號,要想一下右手定則)
   glTranslatef(0.3, 0.3, 0);///(1)把手肘(轉動中心)移到畫面的中心(負向,倒過來移哦)
   drawHand();///(0)畫手,位置不能錯,從下往上看
glPopMatrix();





讀圖檔:

(1)Google: opencv 2.1 download
(2)下載第二個
(3)opencv 2.1設定第三個PATH


(3)開啟CodeBlocks新專案
(4)因程式無法執行 要設定專案


設定專案Build Option設定



Add compiler include:  C:\opencv2.1\include
Linker lib:


Linker Setting:cv210,cxcore210,highgui210





2017年5月9日 星期二

Week11

本周重點:
(1)組合出機器人
(2)可轉動的關節
(3)錄製動作

一.先下載3D Exploration v1.81
二.下載


三.打開3D Exploration
四.再到http://www.cmlab.csie.ntu.edu.tw/~jsyeh/3dcg10/下載data

五.















Week10

(1)Maya匯出OBJ模型
(2)glm讀模型 畫模型
(3)WAV音效 MP3音樂
(4)小遊戲(回家作業)






(1)


(4)Google:Nehe Lesson32
    射擊遊戲 lesson32.zip解壓縮
    執行lesson32.exe






(5)在Lesson32.cpp找sound
Playsound("檔名.wav",NULL,SND_ASYNC);

(6)

2017年3月28日 星期二

Week06

一.期中考題練習:

glPushMatrix();//備份矩陣
   glRotatef(angle, x,y,z);//旋轉
   glTranslatef(x, y, z);//移動
   glScalef(x, y, z);//縮放
   glBegin(GL_POLYGON);//開始畫
      glNormal3f(nx, ny, nz);//打光的法向量
      glTexCoord2f(tx,ty);// 貼圖座標
      glColor3f(r,g,b);//顏色
      glVertex3f(x,y,z);//頂點
  glEnd();//結束畫
glPopMatrix();//還原矩陣

二.

三.實做:T-R-T




 程式碼:
#include <GL/glut.h>
float mouseX=0;
void display()
{
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
    glPushMatrix();
        glRotatef(mouseX, 0,0,1);
        glColor3f(1,0,0); glutSolidTeapot(0.3);
        glPushMatrix();
          glTranslatef(0.5,0.14,0);///3.把整個樓下的東西,移到紅色茶壺(掛上去)
          glRotatef(mouseX, 0,0,1);///2.會轉動
          glTranslatef(0.41,-0.05,0);///1.把手把移到轉盤的中心
          glColor3f(1,1,1); glutSolidTeapot(0.3);
          glutSolidTeapot(0.3);
       glPopMatrix();
    glPopMatrix();
    glutSwapBuffers();
}
void motion(int x,int y)
{
    mouseX = x;
    glutPostRedisplay();

}
int main(int argc, char **argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("TRT robot");
    glutDisplayFunc(display);
    glutMotionFunc(motion);
    glutMainLoop();


   


2017年3月21日 星期二

Week05

滑鼠拖曳可移動小茶壺:

 程式碼:

 #include <GL/glut.h>
float mouseX=0, mouseY=0;
void display()
{
    glClear(GL_COLOR_BUFFER_BIT| GL_DEPTH_BUFFER_BIT);
    glPushMatrix();///備份起來
        glTranslatef(mouseX, mouseY, 0);
        glutSolidTeapot(0.3);
    glPopMatrix();///還原回去

    glutSwapBuffers();
}
void motion(int x, int y)
{
    mouseX = (x-150)/150.0;
    mouseY = -(y-150)/150.0;
    glutPostRedisplay();
}
int main( int argc, char **argv )
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_RGB|GLUT_DOUBLE|GLUT_DEPTH);
    glutCreateWindow("04163031");

    glutDisplayFunc(display);
    glutMotionFunc(motion);
    glutMainLoop();
}

如圖:


滑鼠拖曳可縮放茶壺

程式碼:

#include <GL/glut.h>
float mouseX=0, mouseY=0;
void display()
{
    glClear(GL_COLOR_BUFFER_BIT| GL_DEPTH_BUFFER_BIT);///清掉舊的畫面
    glPushMatrix();///備份起來
        glScalef(mouseX, mouseY, 0);///改size縮放
        glutSolidTeapot(0.3);
    glPopMatrix();///還原回去

    glutSwapBuffers();///交換繪圖的memory buffer,才能畫出來
}
void motion(int x, int y)
{
    mouseX = (x-150)/150.0;
    mouseY = -(y-150)/150.0;
    glutPostRedisplay();///貼一張3M Post便利貼,告訴電腦的GLUT要畫畫面Re display
}
int main( int argc, char **argv )
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_RGB|GLUT_DOUBLE|GLUT_DEPTH);
    glutCreateWindow("04163031");

    glutDisplayFunc(display);
    glutMotionFunc(motion);
    glutMainLoop();
}

如圖:



滑鼠拖曳可旋轉茶壺

程式碼:

#include <GL/glut.h>
float mouseX=0, mouseY=0, rotX=0;
void display()
{
    glClear(GL_COLOR_BUFFER_BIT| GL_DEPTH_BUFFER_BIT);///清掉舊的畫面
    glPushMatrix();///備份起來
        //glScalef(mouseX, mouseY, 0);///改size縮放
        glRotatef(rotX, 0,0,1);
        glutSolidTeapot(0.3);
    glPopMatrix();///還原回去

    glutSwapBuffers();///交換繪圖的memory buffer,才能畫出來
}
void motion(int x, int y)
{
    mouseX = (x-150)/150.0;
    mouseY = -(y-150)/150.0;
    rotX = x;
    glutPostRedisplay();///貼一張3M Post便利貼,告訴電腦的GLUT要畫畫面Re display
}
int main( int argc, char **argv )
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_RGB|GLUT_DOUBLE|GLUT_DEPTH);
    glutCreateWindow("04163031");

    glutDisplayFunc(display);
    glutMotionFunc(motion);
    glutMainLoop();
}

如圖:



2017年3月14日 星期二

Week04

Week04

(ㄧ)畫出正圓形


程式碼:

#include <GL/glut.h>
#include <math.h>
void display()
{
    glBegin(GL_POLYGON);
    for(float angle=0; angle <= 3.1415926 *2; angle += 0.01){
        glVertex2f( cos(angle), sin(angle) );
    }
    glEnd();
    glutSwapBuffers();
}
int main(int argc, char*argv[] )
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_RGB |GLUT_DOUBLE |GLUT_DEPTH);
    glutCreateWindow("GLUT shape");//視窗名稱
    glutDisplayFunc(display);
    glutMainLoop();

}

(二)圓形變色

程式碼:

#include <GL/glut.h>
#include <math.h>
#include <stdio.h>//NOW for printf()
void display()
{
    glBegin(GL_POLYGON);
    for(float angle=0; angle <= 3.1415926 *2; angle += 0.01){
        glVertex2f( cos(angle), sin(angle) );
    }
    glEnd();
    glutSwapBuffers();
}
void mouse(int button, int state, int x, int y)
{///NOW mouse function
    printf("%d %d %d %d\n",button, state, x, y);//NOW printf the values
    glColor3f( 1, x/300.0 , y/300.0 );//NOW change color to any color
}
int main(int argc, char*argv[] )
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_RGB |GLUT_DOUBLE |GLUT_DEPTH);
    glutCreateWindow("GLUT shape");//視窗名稱
    glutDisplayFunc(display);//NOW we are using mouse function
    glutMouseFunc(mouse);
    glutMainLoop();

}




(三) 滑鼠拖曳 讓圓形變色



程式碼:

#include <GL/glut.h>
#include <math.h>
#include <stdio.h>//NOW for printf()
void display()
{
    glBegin(GL_POLYGON);
    for(float angle=0; angle <= 3.1415926 *2; angle += 0.01){
        glVertex2f( cos(angle), sin(angle) );
    }
    glEnd();
    glutSwapBuffers();
}
void mouse(int button, int state, int x, int y)
{///NOW mouse function
    //printf("%d %d %d %d\n",button, state, x, y);//NOW printf the values
}
void motion(int x, int y)
{///NOW mouse Dragging!
      glColor3f( 1, x/300.0 , y/300.0 );//NOW change color to any color
      glutPostRedisplay();///post 貼個便利貼,告訴電腦有空的時候 Re-display
}

int main(int argc, char*argv[] )
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_RGB |GLUT_DOUBLE |GLUT_DEPTH);
    glutCreateWindow("GLUT shape");//視窗名稱
    glutDisplayFunc(display);//NOW we are using mouse function
    glutMouseFunc(mouse);
    glutMotionFunc(motion);
    glutMainLoop();

}

(四)小精靈


程式碼:

#include <GL/glut.h>
#include <math.h>
#include <stdio.h>//NOW for printf()
float mouth=0;
void display()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glBegin(GL_TRIANGLE_FAN);
    glVertex2f(0, 0);
    for(float angle=0 + mouth; angle <= 3.1415926 *2 -mouth; angle += 3.1415926 / 100){
        glVertex2f( cos(angle), sin(angle) );
    }
    glEnd();
    glutSwapBuffers();
}
void mouse(int button, int state, int x, int y)
{///NOW mouse function
    //printf("%d %d %d %d\n",button, state, x, y);//NOW printf the values
}
void motion(int x, int y)
{///NOW mouse Dragging!
      mouth = x / 300.0;
      glColor3f( 1, x/300.0 , y/300.0 );//NOW change color to any color
      glutPostRedisplay();///post 貼個便利貼,告訴電腦有空的時候 Re-display
}

int main(int argc, char*argv[] )
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_RGB |GLUT_DOUBLE |GLUT_DEPTH);
    glutCreateWindow("GLUT shape");//視窗名稱
    glutDisplayFunc(display);//NOW we are using mouse function
    glutMouseFunc(mouse);
    glutMotionFunc(motion);
    glutMainLoop();

}









2017年3月7日 星期二

Week03


然後下載data,zip  window.zip  glut32.dll 這三個檔案。如圖:




將data和win32都解壓縮,把解壓縮的data和glut.dll丟入win32的資料夾中,如圖:






(二)變色茶壺

          根據Week01教的打開opengl GLUT。


          然後將上次的茶壺加入顏色。如圖:

          P.S   RGB數值,要介於0~1之間,0~255/255.0



   (三)茶壺變三角形


               把剛剛那程式碼刪除  glutSolidTeapot(0.3);
               後加入 
                           glBegin(GL_POLYGON);//必要程式開頭,此為POLYGON多邊形

                           glColor3f(1,0,0);//3代表3個參數,(R,G,B)  3f的f=float
                           glVertex3f(0,0,0);//VERTEX=頂點 3個點(x,y,z)

                           glColor3f(0,1,0);
                           glVertex3f(1,1,0);

                           glColor3f(0,0,1);
                           glVertex3f(-1,1,0);
  

                           glEnd();//結束的必要程式碼

如圖:












                     


2017年2月21日 星期二

Week01_溫淳安

(1)展示: WebGraphics demo

      藉由WebGL來測試電腦是否可以使用相關功能

        網址:http://madebyevan.com/webgl-water/




(2)實作: 第一個 OpenGL程式


>打開codeblocks 新增openGL專案




>設專案名稱及設定儲存的地方


>程式碼的所在位置
>程式碼編譯結果


p.s:在蘋果電腦裡,早期會用到glx.h這個檔案,但後來就沒有它了,所以下方訊息裡,會出現找不到的問題。(如下圖)






(3)第一個 GLUT程式


>打開codeblocks 新增GLUT專案 



>設專案名稱及設定儲存的地方


>程式碼的所在位置

>程式碼編譯結果


(4)第一個 新手打造的圖學程式

      使用上述的GLUT專案,把main.cpp程式碼減少



>因為蘋果電腦與Windows不同。所以要把#include<GL/glut.h>改成#include<GLUT/glut.h>,然後把return EXIT_SUCCESS;刪掉,下圖為程式編譯結果。