1.播放音檔(有問題找上週)
#include <stdio.h>
#include <windows.h>
int main()
{
printf("playsound()之前\n"); (等待)
PlaySound("07071104.wav",NULL,SND_SYNC);
printf("playsound()之後\n");
}
# ASYNC 不等待,不會播放
除非下一行非"Sound"
winmm 可以播放聲音?
2. SYNC(等待)、ASYNC(不等待)
#include <stdio.h>
#include <windows.h>
int main()
{
PlaySound("07071104.wav",NULL,SND_ASYNC);
while(1)
{
printf("請輸入數字: ");
int n;
scanf("%d",&n);
if(n==1) PlaySound("do.wav",NULL,SND_ASYNC);
if(n==2) PlaySound("re.wav",NULL,SND_ASYNC);
if(n==3) PlaySound("mi.wav",NULL,SND_ASYNC);
}
}
ASYNC => 邊執行while邊撥放、播放中可讀數字
SYNC => 先撥放再執行while、撥放完才能讀,但會記得你按過什麼數字
1-3 mp3
# wav能直接讀,mp3有壓縮過,要再多加程式
#include "CMP3_MCI.h" moodle下載
#include <stdio.h>
CMP3_MCI mp3;///宣告變數
int main()
{
mp3.Load("Hurry_Up.mp3");
mp3.Play();
printf("請輸入數字: ");
int n; 讀數使音樂停止播放
scanf("%d",&n);
}
1-4 4個動作
S鍵儲存座標,存4個複製到file.txt,最後Build按r重現儲存位置
(It work this time)
上週copy
#include <GL/glut.h>
#include <stdio.h>
float angle[20],oldX=0;
int angleid=0;///0右手 1右手關節 2左手 3左手關節
FILE * fout = NULL , *fin =NULL;
void write()
{
if(fout = NULL) fout = fopen("file.txt","w+");
for(int i=0;i<20;i++)
{
printf("%.1f",angle[i]);///印出黑視窗
fprintf(fout,"%.1f",angle[i]);///印出檔案
}///印出20個數字
printf("\n");///每呼叫一次,黑視窗跳行
fprintf(fout,"\n");///每呼叫一次,檔案跳行
}
void read()
{
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 key(unsigned char key,int x,int y)
{
if(key=='s') write();///調好動作後存檔
if(key=='r') read();
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);
///write(); 不再複讀
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);///對z軸旋轉
glTranslatef(-0.3,-0.4,0);///手臂旋轉軸放中心
glColor3f(1,0,0);
glRectf(0.3,0.5,0.7,0.3);
glPushMatrix();
glTranslatef(0.7,0.4,0);///手臂掛回身體
glRotatef(angle[1],0,0,1);///對z軸旋轉
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);///對z軸旋轉
glTranslatef(0.3,-0.4,0);///手臂旋轉軸放中心
glColor3f(1,0,0);
glRectf(-0.3,0.5,-0.7,0.3);
glPushMatrix();
glTranslatef(-0.7,0.4,0);///手臂掛回身體
glRotatef(angle[3],0,0,1);///對z軸旋轉
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);
glutCreateWindow("week15 trt 2");
glutMouseFunc(mouse);
glutKeyboardFunc(key);
glutMotionFunc(motion);
glutDisplayFunc(display);
glutMainLoop();
}
#(部分無記錄)



沒有留言:
張貼留言