2024年5月30日 星期四

week15

                                                                      week15-1 撥放音樂


                              第一行加入:#include <windows.h>

                            加入這行:PlaySound("C:/mykbeat.wav", NULL, SND_ASYNC);


                                 PlaySound("C:/Do.wav", NULL, SND_SYNC);
                                PlaySound("C:/Re.wav", NULL, SND_SYNC);
                                   PlaySound("C:/Mi.wav", NULL, SND_SYNC);
                                PlaySound("C:/Fa.wav", NULL, SND_SYNC);
                                PlaySound("C:/Sol.wav", NULL, SND_SYNC);

把檔案放進專案目錄裡
再把工作執行目錄,設成小數點



weeeeeeeeeeeeeeek15

 WEEK15-1 playsound

安裝一切
新增GLUT專案

#include <windows.h>
int main()
{
    PlaySound("檔案名稱",NULL, SND_ASYNC)
    
}


PlaySound("檔案名稱",NULL, SND_ASYNC)
有A 直接播放
無A 播完在執行下一條程式


WEEK15-2

新增GLUT專案


再輸入後結束

WEEK15-3

播放MP3檔



Week15-4 

貼上Line11
結果







(メ ゚皿゚)メ電腦圖學week15(╬゚д゚)▄︻┻┳═一

 

  1.下載上課所需的檔案:freeglut檔(做以下步驟:到lib裡面複製檔名最小的,然後改名成libglut32.a)💦

  2.創建一個新專案,名稱是week15-1_PlaySound💧

  3.將裡面的main.cpp檔新增兩航程是在執行即可新增撥放音樂的功能💨

第1行新增#include <windows.h>
新增PlaySound("檔案", NULL, SND_ASYNC);///有A 不同步(不等待)


  4.進行二次修改,新增前置作業💞

新增PlaySound("檔案", NULL, SND_SYNC);每有A 同步等待
 

  5.創建一個新檔案,名稱是week15-2_PlaySound_empty;將上一個檔案的內容精簡化。👋


  6.修改WEEK15-1的內容👍


 

 💪須注意事項:

1.需要有:freeglut.all在檔案內
2.指定檔案右鍵找到Properties

3.裡面的Execution working dir 改成小數點


  7.創建新檔案week15-3_CMP3_MCI,新增程式碼,讓其可以播放mp3👊


  8.創建新專案,week15-4_mouse_motion_translate_rotate,現階段是可以透過滑鼠按住茶壺來移動其位置👌👈


  9.進行新的修正,讓其能夠可以記錄移動到的地點的數值👀


  10.新增與註解,讓茶壺可以跟著中心點旋轉👺



05/30

 1.week15-1_PlaySound

    安裝freeglut,新增GLUT專案

    """cpp

        #include <windows.h>///第一行

    """ 

       PlaySound("檔名.wav",NULL,SND_ASYNC);///有A 不同步/不等待

    """

        PlaySound("C:/Do.wav",NULL,SND_SYNC);///沒有A 同步等待

        PlaySound("C:/Re.wav",NULL,SND_SYNC);

        PlaySound("C:/Mi.wav",NULL,SND_SYNC);

        PlaySound("C:/Fa.wav",NULL,SND_SYNC);

        PlaySound("C:/Sol.wav",NULL,SND_SYNC);

    """

    把前面註解PlaySound("C:/Do.wav",NULL,SND_SYNC);///沒有A 同步等待

        PlaySound("C:/Re.wav",NULL,SND_SYNC);

        PlaySound("C:/Mi.wav",NULL,SND_SYNC);

        PlaySound("C:/Fa.wav",NULL,SND_SYNC);

    改成

    """cpp

    static void key(unsigned char key, int x, int y)

{

    switch (key)

    {

        case '1':

            PlaySound("C:/Do.wav",NULL,SND_SYNC);

            break;

        case '2':

            PlaySound("C:/Re.wav",NULL,SND_SYNC);

            break;

        case '3':

            PlaySound("C:/Mi.wav",NULL,SND_SYNC);

            break;

}

    """

    現在要把工作執行目錄Project-Properties的第2分頁

    Execution working dir 改成小數點

    再把 桌面\freeglut\bin\freeglut.dll 及音樂,都copy到專案目錄

2.week15-2_PlaySound_empty

    新增GLUT專案

    把程式碼全刪

    """cpp

        #include <windows.h>

            int main()

            {

                PlaySound("C:/檔名.wav",NULL,SND_SYNC);

            }

    """

3.week15-3_CMP3_MCI

    新增專案

    請把CMP3_MCI.h和sone.mp3和freeglut.dll都放到你的專案目錄

    把你的工作執行目錄,設定成小數點

    """cpp

        #include "CMP._MCI.h",//雙引號,很像之前"glm.h"

        CMP3_MCI myMP3;//宣告一個物件變數

    """

    在main()

    """cpp

        int main(...)

        {

            myMP3.Load("song.mp3");

            myMP3.Play();

            ...

        }

    """

4.week15-4_mouse_motion_translate_rotate

    貼上11行GLUT程式

    用滑鼠移動



紀錄座標


轉動



week15

##week15

#week15-1_PlaySound

 1.先設定好環境


2. 安裝 freeglut 再把 lib\libfreeglut.a 複製成 libglut32.a.

3. 加入#include <windows.h>  PlaySound("C:Do.wav,NULL,SND_SYNC);







##week15-2_PlaySound_empty
1.把程式碼全刪
加入PlaySound("C:/Do.wav",NULL,SND_ASYNC);
        printf("請輸入一個整數: ");
    int n;
    scanf("%d",&n);

##week15-3_CMP3_MCI
1. 開新專案
2. 請把 CMP3_MIC.h和sone.mp3 和freeglut.dll 都放到你的專案目錄裡
3. 把工作執行目錄,設成小數點
4. 加入 
#include "CMP3_MCI.h"  ///雙引號,像之前的"glm.h"
CMP3_MCI myMP3; ///宣告一個物件變數 
5. 在main()裡加入
        int main()
    {    
    myMP3.Load("song.mp3");
    myMP3.Play();
    }

##week15-4_mouse_motion_translate_rotate
1. 開新專案
2. 貼上11行GLUT程式碼
3. 目標: 先能移動、旋轉、陣列
滑鼠能移動物件

印出移動的座標

轉動的茶壺



PC

播放音訊
精簡程式碼
按鍵控制音符
播放音樂
讓茶壺跟著鼠標移動

顯示茶壺座標
讓茶壺繞圓心旋轉







 

從0到0.01的電腦圖學 Week15

本週主題

(1) 主題:音樂、音效

(2) mouse 移動模型

(3) 期末作品

1. GLUT程式1:PlaySound()

在程式最上面先放上#include <windows.h>

接著在main中寫 PlaySound("音樂檔案路徑/音樂檔案", NULL,SND_ASYNC)

第三參數有兩個下法:
SND_ASYNC - 不同步(不等待)
SND_SYNC  -  同步

2. GLUT程式2:.mp3的使用

在程式最上面放上
#include "CMP3_MCI.h"
CMP3_MCI myMP3;

接著在main中寫
myMP3.Load("音樂檔案路徑/音樂檔案");
myMP3.Play();

3. GLUT程式3-1:利用滑鼠移動物件

#include <GL/glut.h>
float angleX[10]={},angleY[10]={};
float teapotX=0, teapotY=0;
void display(){
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
        glTranslatef(teapotX,teapotY,0);
        glutSolidTeapot(0.5);
glPopMatrix();
glutSwapBuffers();
}
int oldX = 0, oldY = 0;
void mouse(int button, int state, int x,int y){
    oldX = x;
    oldY = y;
}
void motion(int x,int y){
    teapotX += (x - oldX)/150.0;
    teapotY -= (y - oldY)/150.0;
    oldX = x;
    oldY = y;
    glutPostRedisplay();
}
int main(int argc, char*argv[]){
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("week15-4");
glutDisplayFunc(display);
glutMouseFunc(mouse);
glutMotionFunc(motion);
glutMainLoop();
}
4. GLUT程式3-2:利用程式找出座標點
#include <GL/glut.h>
#include <stdio.h>
float angleX[10]={},angleY[10]={};
float teapotX=0, teapotY=0;
void display(){
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
        glTranslatef(teapotX,teapotY,0);
        glutSolidTeapot(0.5);
glPopMatrix();
glutSwapBuffers();
}
int oldX = 0, oldY = 0;
void mouse(int button, int state, int x,int y){
    oldX = x;
    oldY = y;
}
void motion(int x,int y){
    teapotX += (x - oldX)/150.0;
    teapotY -= (y - oldY)/150.0;
    printf("glTranslatef(%.3f, %.3f, 0);\n",teapotX,teapotY);
    oldX = x;
    oldY = y;
    glutPostRedisplay();
}
int main(int argc, char*argv[]){
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("week15-4");
glutDisplayFunc(display);
glutMouseFunc(mouse);
glutMotionFunc(motion);
glutMainLoop();
}

5. GLUT程式3-3:利用程式找出座標點,然後沿茶壺嘴轉動
#include <GL/glut.h>
#include <stdio.h>
float angleX[10]={},angleY[10]={};
float teapotX=0, teapotY=0;
void display(){
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glutSolidSphere(0.02,30,30); ///show the center
        ///move the teapot to center find the coordinate glTranslatef(-0.860, -0.220, 0);
glPushMatrix();
        glRotatef(angleX[0],0,0,1);
        ///glTranslatef(teapotX,teapotY,0);
        glTranslatef(-0.860, -0.220, 0);
        glutSolidTeapot(0.5);
glPopMatrix();
glutSwapBuffers();
}
int oldX = 0, oldY = 0;
void mouse(int button, int state, int x,int y){
    oldX = x;
    oldY = y;
}
void motion(int x,int y){
    ///teapotX += (x - oldX)/150.0;
    ///teapotY -= (y - oldY)/150.0;
    ///printf("glTranslatef(%.3f, %.3f, 0);\n",teapotX,teapotY);
    angleX[0] += (x-oldX);
    oldX = x;
    oldY = y;
    glutPostRedisplay();
}
int main(int argc, char*argv[]){
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("week15-4");
glutDisplayFunc(display);
glutMouseFunc(mouse);
glutMotionFunc(motion);
glutMainLoop();
}


我愛彩虹屋

 1.新增一個專案,命名為"week15-1_PlaySound"

2.新增一個專案,命名為"week15-2_PlaySound_empty"

3.把程式碼全刪

3.新增一個專案,命名為"week15-3_CMP3_MCI"

4.請把CMP3_MCI.h和sone.mp3和freeglut.dll都放到你的專案目錄裡

5.把你的工作執行目錄,設定成小數點.

6.新增一個專案,命名為"week15-4_mouse_motion_translate_rotate"

7.貼上11行的GLUT程式

8.目標:先能移動跟旋轉跟陣列

BK Week15

 # week15


# week15-1_PlaySound

0. 下載 freeglut 至桌面, 並解壓縮, 更改 lib 中的檔名

1. File-New-Project, GLUT專案 week15-1_PlaySound

2. 加入下方橘色部分程式碼

```cpp

    #include <windows.h> ///第1行

    int ,main(......)

    {

        PlaySound("檔名.wav", NULL, SND_ASYNC);

    }

```

3. 執行後可以撥出音樂


# week15-2_PlaySound_empty

1. File-New-Project, GLUT專案 week15-2_PlaySound_empty

2. 把程式碼全刪

```cppˇ

    #include <windows.h>

int main()

{

    PlaySound("C:/Do.wav",NULL,SND_SYNC);

}

```

3. 一樣可以放音樂

4. 先在把工作執行目錄 Project-Properties 的第2分頁 Execution working dir 改成小數點

5. 再把 桌面/freeglut/bin/freeglut.dll 和音樂 全部丟到檔案目錄


# week15-3_CMP3_MCI

1. File-New-Project, GLUT專案 week15-3_CMP3_MCI

2. 請把 CMP3 MCI.h 和 song.mp3 和 freeglut.dll 都放到專案目錄裡

3. 把工作執行目錄設成小數點

```cpp

    #include "CMP3_MCI.h" ///雙引號, 很像之前 glm.h

    CMP3_MCI myMP3; ///宣告一個物件變數

```


```cpp

    int main(...)
    {

        myMP3.Load("song.mp3");

        myMP3.Play();

    }

```cpp


# week15-4_mouse_motion_translate_rotate

1. File-New-Project, GLUT專案 week15-4_mouse_motion_translate_rotate

2. 貼上 11行的 GLUT 程式碼

3. 目標先能 移動、旋轉、陣列

Week15

 Week15-1_PlaySound

0. 安裝 freeglut

1. File-New-Project

、、、cpp

#include<windows.h>

、、、cpp

int main()

把 mybeat.wav 放在 C:\裡,就可以用 C:/mykbeat.wav PlaySound ("檔名.wav",NULL,SND_ASYNC) ;









 PlaySound ("檔名.wav",NULL,SND_ASYNC)    PlaySound ("檔名.wav",NULL,SND_SYNC) ;

沒有 A 是同步,A 是不同步









Week15-2_PlaySound_empty


1. File-New-Project

2. 把程式碼全刪掉









現在要把工作目錄 Project-Properties 的第2分頁 Execution working dir 改成小數點
再把桌面 \ freeglut \ bin \ freeglut.dll 及音樂都複製到專案目錄













Week15-3_CMP3_MCI

1. File-New-Project

2. 請把 CMP3_MCI.h 和 song.mp3 和 freeglut.dll 都放進專案目錄裡

3. 把工作執行目錄設成小數點



Week15-4_mouse_motion_translate_rotate

1. File-New-Project   week15-4_mouse_motion_translate_rotate

左邊照片:按滑鼠左鍵茶壺會移動

右邊照片:印出茶壺座標 ( x , y )

下面那張照片:茶壺以中心點轉動