2015年4月9日 星期四

week07_翁子喻_02160022

一、因為老師對我們的肯定,今天的進度是音效和音樂~~~~~~
重複之前的步驟到freeglut windows下載,也在codeblocks建立專案
打出程式碼,秀出成果圖~~~~

程式碼:
#include <GL/glut.h>
#include <stdio.h>

void display()
{
    glutSolidTeapot(0.3);
    glFlush();
}
void keyboard(unsigned char key, int x,int y)
{
    if(key=='a')printf("aaaaaa\n");
    if(key=='b')printf("bbbbbb\n");
}
int main(int argc, char**argv)
{
    glutInit(&argc,argv);
    glutCreateWindow("hello");

    glutDisplayFunc(display);
    glutKeyboardFunc(keyboard);

    glutMainLoop();
}

二、我們利用程式碼輕輕鬆鬆發出聲音哦,覺得很酷!
上網搜尋,下載wav檔案。
輸入程式碼後,只要輸入a就會發出BOTTLE的聲音。

#include <GL/glut.h>
#include <stdio.h>

#include <mmsystem.h>
void display()
{
    glutSolidTeapot(0.3);
    glFlush();
}
void keyboard(unsigned char key, int x,int y)
{
    if(key=='a'){
        PlaySound("BOTTLE.wav",NULL,SND_ASYNC);
        printf("BOTTLE BBB\n");
    }

    if(key=='b')printf("bbbbbb\n");
}
int main(int argc, char**argv)
{
    glutInit(&argc,argv);
    glutCreateWindow("hello");

    glutDisplayFunc(display);
    glutKeyboardFunc(keyboard);

    glutMainLoop();
}

三、在程式碼裡加入paino: do re mi fa sol la si~~~的語法,讓他輸入數字就能發出聲音~~~
我到網路上去下載do re mi~si的wav音樂檔,然後加入今天上課所學的程式碼,
順利執行出靠鍵盤數字發出聲音的成果~~~~~~~
打1~6就會出現從Do~Si的聲音。

#include <GL/glut.h>
#include <stdio.h>

#include <mmsystem.h>
void display()
{
    glutSolidTeapot(0.3);
    glFlush();
}
void keyboard(unsigned char key, int x,int y)
{
    if(key=='a'){
        PlaySound("BOTTLE.wav",NULL,SND_ASYNC);
        printf("BOTTLE BBB\n");
    }
 if(key=='1')  PlaySound("Do.wav",NULL,SND_ASYNC);
    if(key=='2') PlaySound("Re.wav",NULL,SND_ASYNC);
    if(key=='3')PlaySound("Mi.wav",NULL,SND_ASYNC);
    if(key=='4')PlaySound("Fa.wav",NULL,SND_ASYNC);
    if(key=='5')PlaySound("Sol.wav",NULL,SND_ASYNC);
    if(key=='6')PlaySound("La.wav",NULL,SND_ASYNC);
    if(key=='7')PlaySound("Si.wav",NULL,SND_ASYNC);
    {
    if(key=='b')printf("bbbbbb\n");
}
}
int main(int argc, char**argv)
{
    glutInit(&argc,argv);
    glutCreateWindow("hello");

    glutDisplayFunc(display);
    glutKeyboardFunc(keyboard);

    glutMainLoop();
}

四、最後小葉老師超前進度教我們更多
利用上下鍵讓茶壺移動~~~然後利用滑鼠左右鍵可以左右動和旋轉哦!!
以下是我的程式碼和圖片成果
#include <GL/glut.h>
#include <stdio.h>

#include <mmsystem.h>
float teaY=0,rotX=0,rotY=0,oldX=0,oldY=0;
void display()
{
    glutSolidTeapot(0.3);
    glPushMatrix();
    glTranslatef(0,teaY,0);
    glRotatef(rotX,1,0,0);
    glRotatef(rotY,0,1,0);
    glutSolidTeapot(0.3);
    glPopMatrix();
    glFlush();
}
void keyboard(unsigned char key, int x,int y)
{
    if(key=='a'){
        PlaySound("BOTTLE.wav",NULL,SND_ASYNC);
        printf("BOTTLE BBB\n");
    }
 if(key=='1')  PlaySound("Do.wav",NULL,SND_ASYNC);
    if(key=='2') PlaySound("Re.wav",NULL,SND_ASYNC);
    if(key=='3')PlaySound("Mi.wav",NULL,SND_ASYNC);
    if(key=='4')PlaySound("Fa.wav",NULL,SND_ASYNC);
    if(key=='5')PlaySound("Sol.wav",NULL,SND_ASYNC);
    if(key=='6')PlaySound("La.wav",NULL,SND_ASYNC);
    if(key=='7')PlaySound("Si.wav",NULL,SND_ASYNC);
    {
    if(key=='b')printf("bbbbbb\n");
}
}
void mouse(int button, int state,int x, int y)
{
    oldX=x; oldY=y;
    if(GLUT_LEFT_BUTTON==button &&GLUT_DOWN==state)printf("now left down\n");
    if(GLUT_RIGHT_BUTTON==button &&GLUT_DOWN==state)printf("now right down\n");
}
void motion(int x, int y)
{
    rotX += y-oldY;
    rotY += x-oldX;
    oldX=x; oldY=y;
    glutPostRedisplay();
}
void special(int key, int x, int y)
{
    if(key==GLUT_KEY_DOWN){
        teaY-=0.1;printf("down\n");
    }else if(key==GLUT_KEY_UP){
    teaY+=0.1;printf("up\n");}
    glutPostRedisplay();
}
int main(int argc, char**argv)
{
    glutInit(&argc,argv);
    glutCreateWindow("hello");

    glutDisplayFunc(display);
    glutKeyboardFunc(keyboard);
    glutSpecialFunc(special);

    glutMouseFunc(mouse);
    glutMotionFunc(motion);

    glutMainLoop();
}

沒有留言:

張貼留言