上週:PlaySound MP3播放
PlaySound
開啟 glut專案,加入程式碼
#include <mmysystem.h> //(1)多媒體系統
int main()
{
PlaySound("Do.wav", NULL, SND_ASYNC | SND_LOOP); //暫放 freeglut\bin
}
聲音檔要放在 freeglut\bin裡面
MP3
#include <CMP3_MCI.h> //(1)在 moodle下載 MP3的外掛
CMP3_MCI MP3; //(2)宣告(物件)變數
int main()
{
myMP3.Load("123.mp3"); //(3)讀mp3(在 working_dir執行目錄)
myMP3.Play(); //(4)播放
}
主題:計時器 Timer
用 Timer計時器
#include<windows.h>
#include<mmsystem.h>
void timer(int t)
{
glutTimerFunc(1000, timer,t+1);
PlaySound("Do.wav", NULL, SND_ASYNC | SND_LOOP);
}
int main(...)
{
//glutCreateWindow()之後
glutTimerFunc(5000, timer, 0);
}
主題:線性內插
公式: alpha*新 + (1-alpha)*舊
(alpha: 0.0...1.0)
#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;
angle=newAngle*alpha+oldAngle*(1-alpha);
glutPostRedisplay();
}
int main(int argc, char *argv[])
{
glutInit(&argc, argv);
glutInitWindowSize(640,480);
glutInitWindowPosition(10,10);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("GLUT Shapes");
glutTimerFunc(0, timer, 0);
glutDisplayFunc(display);
glutMainLoop();
return EXIT_SUCCESS;
}

沒有留言:
張貼留言