Step01撥聲音:
1.file-new-empty file再改檔名.cpp
2.寫入
#include <windows.h>
#include <stdio.h>
int main(){
printf("playsound()前\n");
PlaySound("bb.wav",NULL,SND_SYNC);
printf("playsound()後\n");
}
2.Settings-Compiler-Linker settings
加入winmm
3.去https://sound-effects.bbcrewind.co.uk/search尋找想要的wav檔
3.下載後移到執行資料夾
4.執行結果(wav先改成跟下載的檔案同名
Step02:
1.file-new-empty file再改檔名.cpp
2.寫入
#include <windows.h>
#include <stdio.h>
int main(){
PlaySound("do.wav",NULL,SND_SYNC);///ASYNC不等待
PlaySound("re.wav",NULL,SND_SYNC);
PlaySound("mi.wav",NULL,SND_SYNC);
}
3.wav檔移到執行資料夾
4.要記得寫成SYNC(寫ASYNC不等待會出錯
4.改寫成
#include <windows.h>
#include <stdio.h>
int main(){
PlaySound("NHU05082251.wav",NULL,SND_ASYNC);///不等待執行較快,適合互動
while(1){
printf("輸入數字: ");
int N;
scanf("%d",&N);
if(N==1)PlaySound("do.wav",NULL,SND_SYNC);///ASYNC不等待
if(N==2)PlaySound("re.wav",NULL,SND_SYNC);
if(N==3)PlaySound("mi.wav",NULL,SND_SYNC);
}
}
Step03 mp3:
1.下載CMP3_MCI.h再移到執行資料夾
2.file-new-empty file再改檔名.cpp
3.寫入
#include "CMP3_MCI.h"
#include <stdio.h>
CMP3_MCI mp3;
int main(){
mp3.Load("NHU05082251.wav");
mp3.Play();
printf("輸入數字(wav停止) :");
int N;
scanf("%d",&N);
}
Step04 :
1.複製上週程式
#include <GL/glut.h>
#include <stdio.h>
float angle[20],oldX=0;
int angleID=0;
FILE * fout=NULL,*fin=NULL;
void myWrite(){
if(fout==NULL) fout=fopen("file.txt","w");
for(int i=0;i<20;i++){
printf("%.1f ",angle[i]);
fprintf(fout,"%.1f ",angle[i]);
}
printf("\n");//跳行
fprintf(fout,"\n");
}
void myRead(){
if(fout!=NULL){fclose(fout);fout=NULL;}
if(fin==NULL) fin=fopen("file.txt","r");
for(int i=0;i<20;i++){
fscanf(fin, "%f", &angle[i]);
}
glutPostRedisplay();//重畫畫面
}
void keyboard(unsigned char key,int x,int y){
if(key=='r')myRead();
if(key=='0')angleID=0;
if(key=='1')angleID=1;
if(key=='2')angleID=2;
if(key=='3')angleID=3;
}
void mouse(int button,int state,int x,int y){
oldX=x;
}
void motion(int x,int y){
angle[angleID]+=(x-oldX);
myWrite();
oldX=x;
glutPostRedisplay();///重畫畫面
}
void display(){
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glColor3f(1,1,1);
glRectf(0.3,0.5,-0.3,-0.5);///身體
glPushMatrix();
glTranslatef(0.3,0.4,0);///手臂掛到身體
glRotatef(angle[0],0,0,1);///旋轉
glTranslatef(-0.3,-0.4,0);///把手臂旋轉中心放到中心
glColor3f(1,0,0);///紅
glRectf(0.3,0.5,0.7,0.3);///上手臂
glPushMatrix();
glTranslatef(0.7,.4,0);
glRotatef(angle[1],0,0,1);///旋轉
glTranslatef(-0.7,-0.4,0);///把手臂旋轉中心放到中心
glColor3f(0,1,0);///紅
glRectf(0.7,0.5,1.0,0.3);///下手臂
glPopMatrix();
glPopMatrix();
glPushMatrix();
glTranslatef(-0.3,0.4,0);///手臂掛到身體
glRotatef(angle[2],0,0,1);///旋轉
glTranslatef(0.3,-0.4,0);///把手臂旋轉中心放到中心
glColor3f(1,0,0);///紅
glRectf(-0.3,0.5,-0.7,0.3);///上手臂
glPushMatrix();
glTranslatef(-0.7,.4,0);
glRotatef(angle[3],0,0,1);///旋轉
glTranslatef(0.7,-0.4,0);///把手臂旋轉中心放到中心
glColor3f(0,1,0);///紅
glRectf(-0.7,0.5,-1.0,0.3);///下手臂
glPopMatrix();
glPopMatrix();
glutSwapBuffers();
}
int main(int argc,char** argv){
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
glutInitWindowSize(600,600);
glutCreateWindow("week15_ANGLE_TRT_Again");
glutKeyboardFunc(keyboard);
glutMouseFunc(mouse);
glutMotionFunc(motion);
glutDisplayFunc(display);
glutMainLoop();
}
2.在motion註解
///myWrite();
3.keyboard寫入
if(key=='s')myWrite();
s:寫好才存入一個動作
3.小技巧:可以複製紀錄後的動作重複執行,動作就會增加



沒有留言:
張貼留言