2016年5月3日 星期二

Week 11 劉正威

一.音效.音樂

先打開貝殼專案

打呼叫音樂檔的程式碼

(程式碼)

#include <iostream>
#include <windows.h>
#include <mmsystem.h>

using namespace std;

int main()
{
    cout << "Hello world!" << endl;
    PlaySoundA("Do.WAV",NULL,SND_SYNC);
    PlaySoundA("Re.WAV",NULL,SND_SYNC);
    PlaySoundA("Mi.WAV",NULL,SND_SYNC);
    return 0;
}
最後在打上咒語

二.用鍵盤彈奏音樂

先建立貝殼專案

撰寫程式碼

(程式碼)

#include <iostream>
#include <GL/glut.h>
#include <windows.h>
#include <mmsystem.h>
using namespace std;
void display()
{

}
void keyboard(unsigned char key,int x,int y)
{
    if(key=='1') PlaySoundA("Do.wav",NULL,SND_ASYNC);
    if(key=='2') PlaySoundA("Re.wav",NULL,SND_ASYNC);
    if(key=='3') PlaySoundA("Mi.wav",NULL,SND_ASYNC);
    if(key=='4') PlaySoundA("Fa.wav",NULL,SND_ASYNC);
    if(key=='5') PlaySoundA("Sol.wav",NULL,SND_ASYNC);
    if(key=='6') PlaySoundA("La.wav",NULL,SND_ASYNC);
    if(key=='7') PlaySoundA("Si.wav",NULL,SND_ASYNC);
}
int main(int argc,char**argv)
{
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("3D sound version");
    glutDisplayFunc(display);
    glutKeyboardFunc(keyboard);
    glutMainLoop();

}
打上咒語
設兩個路徑
1.
2.
最後成功執行

樂階分別

1 Do
2 Re
3 Mi
4 Fa
5 Sol
6 La
7 Si

三.業界接軌(妖怪手錶)

利用妖怪手錶.MP3檔加入程式碼執行,使背景有妖怪手錶的音樂

(程式碼)

#include <GL/glut.h>
#include <windows.h>
#include <mmsystem.h>
#include "CMP3_MCI.h"
CMP3_MCI myMP3;
using namespace std;
void display()
{
    glClearColor(0.5,0.5,1,1);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glPushMatrix();
        glTranslatef(potx,poty,0);
        glutSolidTeapot(0.1);
    glPopMatrix();
    glutSwapBuffers();  

}
void keyboard(unsigned char key,int x,int y)
{
    if(key=='1') PlaySoundA("Do.wav",NULL,SND_ASYNC);
    if(key=='2') PlaySoundA("Re.wav",NULL,SND_ASYNC);
    if(key=='3') PlaySoundA("Mi.wav",NULL,SND_ASYNC);
    if(key=='4') PlaySoundA("Fa.wav",NULL,SND_ASYNC);
    if(key=='5') PlaySoundA("Sol.wav",NULL,SND_ASYNC);
    if(key=='6') PlaySoundA("La.wav",NULL,SND_ASYNC);
    if(key=='7') PlaySoundA("Si.wav",NULL,SND_ASYNC);
}
void mouse(int button, int state,int x,int y)
{
    if(state==GLUT_DOWN)
    {
        PlaySoundA("Si.wav",NULL,SND_ASYNC);
    }
}
void timer(int t)
{
    glutTimerFunc(30,timer,t+1);
    potx+=0.03;
    if(potx>1)potx=-1;
    glutPostRedisplay();
}

int main(int argc,char**argv)
{
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("3D sound version");
    glutDisplayFunc(display);
    glutKeyboardFunc(keyboard);
    myMP3.Load("music.mp3");
    myMP3.Play();
    glutMainLoop();

}

沒有留言:

張貼留言