2024年5月30日 星期四

week15

week15-1_PlaySound

1.建立專案

```cpp

int main(....)

{

    PlaySound("檔名.wav",NULL,SND_ASYNC)

    ///PlaySound("C:/Do.wav",NULL,SND_SYNC);///沒有A 同步等待

}

```

補充

```cpp

static void key(unsigned char key, int x, int y)

{

    switch (key)

    {

        case '1':

            PlaySound("Do.wav",NULL,SND_ASYNC);///沒有A 同步等待

            break;

        case '2':

            PlaySound("Re.wav",NULL,SND_ASYNC);///沒有A 同步等待

            break;

        case '3':

            PlaySound("Mi.wav",NULL,SND_ASYNC);///沒有A 同步等待

            break;

```

week15-2_PlaySound_empty

1.建立專案
2.程式碼全刪除

```cpp
#include <windows.h>
#include <stdio.h>

int main()
{
    PlaySound("C:/Do.wav",NULL,SND_SYNC);
    printf("請輸入一個整數: ");
    int n;
    scanf("%d", &n);
}
```

week15-3_CMP3_MCI

1.建立專案

2.音樂檔和dll放到專案目錄,目錄改成'.'


week15-4_mouse_motion_translate_rotate

1.建立專案,貼上11行

2.目標: 能移動旋轉陣列

```cpp

#include <GL/glut.h>//¶}GLUT¥~±¾
float angleX[10]={},angleY[10]={};///陣列
float teapotX=0,teapotY=0;
void display()
{
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
    glPushMatrix();
        glTranslatef(teapotX,teapotY,0);
        glutSolidTeapot(0.3);
    glPopMatrix();
    glutSwapBuffers();
}

int oldX = 0,oldY = 0;
void mouse(int button,int state,int x,int y) {
    oldX = x;
    oldY = y;
}
void motion(int x,int y) {
    teapotX+=(x-oldX)/150.0;
    teapotY+=(y-oldY)/150.0;
    oldX=x;
    oldY=y;
    glutPostRedisplay();
}
int main(int argc, char *argv[])
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("2024week15");
    glutDisplayFunc(display);
    glutMouseFunc(mouse);
    glutMotionFunc(motion);

    glutMainLoop();
}
```
可以旋轉
```cpp
#include <GL/glut.h>//¶}GLUT¥~±¾
#include <stdio.h>
float angleX[10]={},angleY[10]={};///陣列
float teapotX=0,teapotY=0;
void display()
{
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
    glutSolidSphere(0.02,30,30);

    glPushMatrix();
        glRotatef(angleX[0],0,0,1);
        glTranslatef(-0.520,-0.133,0);
        glutSolidTeapot(0.3);
    glPopMatrix();
    glutSwapBuffers();
}

int oldX = 0,oldY = 0;
void mouse(int button,int state,int x,int y) {
    oldX = x;
    oldY = y;
}
void motion(int x,int y) {
    ///teapotX+=(x-oldX)/150.0;
    ///teapotY+=(y-oldY)/150.0;
    ///printf("glTranslatef(%.3f,%.3f,0);\n",teapotX,teapotY);
    angleX[0] += (x - oldX);
    oldX=x;
    oldY=y;
    glutPostRedisplay();
}
int main(int argc, char *argv[])
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("2024week15");
    glutDisplayFunc(display);
    glutMouseFunc(mouse);
    glutMotionFunc(motion);

    glutMainLoop();
}

```




沒有留言:

張貼留言