week15
(1)
1-1.開 CodeBlocks/empty file-->week15_PlaySound.cpp
#include <windows.h>
#include <stdio.h>
int main()
{
printf("PlaySound()\n");
PlaySound("07042111.wav",NULL,SND_SYNC);
printf("PlaySound()之後\n");
}
⃟ 如果錯誤會有錯誤音效
1-2.開 CodeBlocks/empty file-->week15_SND_SNTC_ASNYC.cpp
⃤ 直接播
#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);
}
⃤ 等待
#include <windows.h>
#include <stdio.h>
int main()
{
PlaySound("07042111.wav",NULL,SND_ASYNC);///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);
}
}
(2)
2-1.開 CodeBlocks/empty file-->week15_MP3.cpp
2-2.moodle 下載CMP3_MCI.h
2-3.
#include <stdio.h>
#include "CMP3_MCI.h"
CMP3_MCI mp3;
int main()
{
mp3.Load("07042111.mp3");
mp3.Play();
printf("隨便等你輸入數字,程式就卡住了 : ");
int N;///為了程式不要結束
scanf("%d",&N);
}
2-4.開新專案-->week15_angle_TRT_again
可以讀動作,長按r可播錄的動作
2-5.改上週程式
#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=='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();
}
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,0.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,0.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);
glutCreateWindow("week15 angle TRT again");
glutKeyboardFunc(keyboard);
glutMouseFunc(mouse);
glutMotionFunc(motion);
glutDisplayFunc(display);
glutMainLoop();
}
⃤ 按s可以存動作
⃤ 找txt複製動作可以做很多次r
(3)HW
3-1.開新專案week15_HW
3-2.用notepad++改目錄-->"."
3-3.把freeglut/bin/freeglut.dll複製到cbp資料夾
3-4.把 glm.h & glm.cpp & gundam的data目錄


沒有留言:
張貼留言