2024年5月30日 星期四

電腦圖學week15

 # week15

##week15-1_PlaySound

0.安裝 freeglut

1.file-new-project,GLUT專案week15-1_PlaySound

2.新增#include <windows.h>

3.新增 


##week15-2_PlaySound_empty


1.file-new-project,GLUT專案week15-2_PlaySound_empty

2.修改程式碼 輸入一個整數


3.現在要把你的執行目錄Project-Properties的第二分頁Execution working dir改成小數點
4.再把freeglut.dll及音樂檔複製到專案目錄

##week15-3_CMP3_MCI
1.file-new-project,GLUT專案week15-3_CMP3_MCI

2.請把CMP3_MCI.h 和sone.mp3 和 freeglut.dll都放到你的專案目錄裡

3.把你的 工作執行目錄,設成.

4.修改程式碼

#include "CMP3_MCI.h"

CMP3_MCI myMP3;


int main(...)

{

myMP3.Load("song.mp3");

    myMP3.Play();

}


##week15-4_mouse_motion_translate_rotate

1..file-new-project,GLUT專案week15-4_mouse_motion_translate_rotate

2.貼上11行程式碼

3.修改程式碼

#include <GL/glut.h>
#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();
        ///glTranslatef(teapotX,teapotY,0);
        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_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("week09 Microsoft Visual Studio");
    glutDisplayFunc(display);
    glutMouseFunc(mouse);
    glutMotionFunc(motion);
    glutMainLoop();
}



4.中心點旋轉




























沒有留言:

張貼留言