更詳細解說PlaySound()
#include<mmsystem.h>上週教的
PlaySound("檔名.wav",NULL,SND_ASYNC);///上週
本周教#include<windows.h>
PlaySound("107042111.wav",NULL, SND_SYNC);
開一個empty file存成week15-1.cpp
#include <windows.h>
#include <stdio.h>
int main()
{
printf("PlaySound()之前\n");
///檔案不存在會有錯誤聲音
PlaySound("107042111.wav",NULL, SND_SYNC);
printf("PlaySound()之後\n");
}
Setting ->Compiler Setting->Linker加入winmm
注意工作執行目錄working_dir(in C:\........
#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]);///檔案印出來
///1f要空格
}
printf("\n");///每呼叫一次小黑會跳行
fprintf(fout,"\n");///每呼叫一次檔案會跳行
}///這邊沒有fclose
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=='s') myWrite();
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();///請GLUT重畫畫面
}
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);///(3)整體移位
glRotatef(angle[0],0,0,1);///(2)
glTranslatef(-0.3,-0.4,0);///(1)把軸心放在正中心
glColor3f(1,0,0);///紅
glRectf(0.3,0.5,0.7,0.3);///上手臂
glPushMatrix();
glTranslatef(0.7,0.4,0);///(3)整體移位
glRotatef(angle[1],0,0,1);///(2)
glTranslatef(-0.7,-0.4,0);///(1)把軸心放在正中心
glColor3f(0,1,0);///綠
glRectf(0.7,0.5,1.0,0.3);///下手臂
glPopMatrix();
glPopMatrix();
glPushMatrix();///左邊
glTranslatef(-0.3,0.4,0);///(3)整體移位
glRotatef(angle[2],0,0,1);///(2)
glTranslatef(0.3,-0.4,0);///(1)把軸心放在正中心
glColor3f(1,0,0);///紅
glRectf(-0.3,0.5,-0.7,0.3);///上手臂
glPushMatrix();
glTranslatef(-0.7,0.4,0);///(3)整體移位
glRotatef(angle[3],0,0,1);///(2)
glTranslatef(0.7,-0.4,0);///(1)把軸心放在正中心
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_TRT");
glutMouseFunc(mouse);
glutMotionFunc(motion);
glutKeyboardFunc(keyboard);
glutDisplayFunc(display);
glutMainLoop();
}
沒有留言:
張貼留言