2016年5月3日 星期二

Week11

Class Work 1

Step 1. Download Do Re Mi .wav
           http://www.openprocessing.org/sketch/132652
Step 2.Create -New Project -Shell
Step 3. Build Option set Link"winmm"


Code:
#include <iostream>
#include<windows.h>
#include<mmsystem.h>
int main()
{
    PlaySoundA("Do.wav",NULL,SND_SYNC);
    PlaySoundA("Re.wav",NULL,SND_SYNC);
    PlaySoundA("Mi.wav",NULL,SND_SYNC);
    return 0;
}


Class Work 2

Step 1. Build Option
            freeglut, opengl32, glu32, gdi32, winmm 

Step 2. Build Option
            freeglut\include
            freeglut\lib

Code:
#include <GL/glut.h>
#include<windows.h>
#include<mmsystem.h>

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");
    glutDisplayFunc(display);
    glutKeyboardFunc(keyboard);

    glutMainLoop();

    return 0;
}

Class Work 3. 炫炮妖怪手錶

Code:
#include <GL/glut.h>
#include<windows.h>
#include<mmsystem.h>
#include"CMP3_MCI.h"
CMP3_MCI player;
float potx=-1,poty=0;
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 botton, 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");

    glutDisplayFunc(display);
    glutKeyboardFunc(keyboard);
    glutTimerFunc(30,timer,0);
    glutMouseFunc(mouse);

    player.Load("youkai.mp3");
    player.Play();
    glutMainLoop();

    return 0;
}

沒有留言:

張貼留言