2018年5月18日 星期五

Week12_陳示珮

第十二週

(1) 小考 : T-R-T觀念
(2) 上週 : PlaySound 、MP3播放
(3) 主題 : 計時器 Timer
(4) 主題 : 線性內插、動畫
(5) 作業



實作一  播放MP3















(1) 依照正常程序開啟GLUT project,並下載freeglut檔案(moodle)

程式碼 :

#include <mmsystem.h>

PlaySound("Do.wav",NULL,SND_ASYNC|SND_LOOP);
















(2)freeglut依正常程序修改後,將wav檔放入freeglut / bin中後即可播放聲音














(3) 至moodle上課用的軟體中下載CMP3_MCI.h
















(3)將GLUT project 儲存,並將CMP3_MCI.h放入剛儲存的GLUT project中
















(4) 加入程式碼,並將下載好的mp3檔放入freeglut / bin中,即可播放mp3檔

程式碼 :

///#include <windows.h>
///#include <mmsystem.h>
#include "CMP3_MCI.h"
CMP3_MCI myMP3;
int a;

    myMP3.Load("123.mp3");
    myMP3.Play();
    ///PlaySound("Do.wav",NULL,SND_ASYNC|SND_LOOP);



實作二 計時器Timer















(1)將程式碼加入正確位置

程式碼 :

#include <windows.h>///因為mmsystem.h需要windows.h
#include <mmsystem.h>///多媒體系統,才會有PlaySound
void timer(int t)
{
    glutTimerFunc(1000,timer,t+1);///等多久,呼叫誰,參數    持續加秒播放
    PlaySound("Do.wav",NULL,SND_ASYNC);
}

 glutTimerFunc(5000,timer,0);///計時器函式 timer  等5秒後開始播放

*印出來
#include <stdio.h>
    printf("Now t is: %d\n",t);


















(2) 即可印出計時器及播放聲音



實作三 線性內插、動畫















(1)利用內插算法將圖形做成動畫

程式碼 :

#include <GL/glut.h>
#include <stdio.h>
float angle=0, oldAngle=0,newAngle=90;//角度 舊角度 新角度
void display()
{
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
    glPushMatrix();
       glRotatef(angle,0,0,1);//會照角度去旋轉
       glutSolidTeapot(0.3);
     glPopMatrix();
     glutSwapBuffers();
}
void timer(int t)
{

    glutTimerFunc(1000,timer,t+1);///等多久,呼叫誰,參數
    float alpha=(t)/30.0;//算出一個內插的alpha值
    angle=newAngle*alpha+oldAngle*(1-alpha);//角度去內插
    glutPostRedisplay();//照著上面的角度 重畫

}
int main(int argc, char *argv[])
{
    glutInit(&argc, argv);
    glutInitWindowSize(640,480);
    glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);

    glutCreateWindow("GLUT Shapes");

    glutTimerFunc(0,timer,0);///計時器函式 timer
    glutDisplayFunc(display);
    glutMainLoop();

}















沒有留言:

張貼留言