2015年4月16日 星期四

week08_簡上棋

電腦圖學
2015/04/16
          week08
1.模擬考,期中考試
2.用範例學習
3.打光 → 法向量
4.貼圖 → 貼圖座標
5.NeHe Lesson 32 小遊戲


#include<GL/freeglut.h>
#include<mmsystem.h>
#include<stdio.h>
void mouse (int button, int state , int x,int y)
{
    if(state == GLUT_DOWN) //滑鼠狀態按下左鍵
    {
        PlaySound("Shot.wav",NULL,SND_ASYNC); //播放freeglut\bin底下的Shot.wav的音檔
        printf("Shot!\n");
    }
}
void keyboard (unsigned char key, int x , int y)
{
    exit(0); //按下隨意鍵離開
}
void display ()
{
    glClearColor(0.5,0.5,1,0); //背景顏色
    glClear(GL_COLOR_BUFFER_BIT);
    glFlush();
}

int main(int argc,char** argv)
{
    glutInit(&argc,argv);
    glutCreateWindow("02160393_DownChess");

    glutFullScreen();//全螢幕

    glutDisplayFunc(display);//顯示
    glutKeyboardFunc(keyboard);//鍵盤
    glutMouseFunc(mouse);//聲音
    glutMainLoop();
}


#include<GL/freeglut.h>
#include<mmsystem.h>
#include<stdio.h>
void mouse (int button, int state , int x,int y)
{
    if(state == GLUT_DOWN) //滑鼠狀態按下左鍵
    {
        PlaySound("Shot.wav",NULL,SND_ASYNC); //播放freeglut\bin底下的Shot.wav的音檔
        printf("Shot!\n");
    }
}
void keyboard (unsigned char key, int x , int y)
{
    exit(0); //按下隨意鍵離開
}
float potx=-1,poty=0;
void display ()
{
    potx+=0.01;
    if(potx>1.1)potx=-1.1;
    glClearColor(0.5,0.5,1,0);
    glClear(GL_COLOR_BUFFER_BIT);
    glPushMatrix();
    glTranslated(potx,poty,0);
    glutSolidTeapot(0.08);
    glPopMatrix();
    glFlush();
}

int main(int argc,char** argv)
{
    glutInit(&argc,argv);
    glutCreateWindow("02160393_DownChess");

    glutFullScreen();//全螢幕

    glutDisplayFunc(display);//顯示
    glutIdleFunc(display); //重複執行程式
    glutKeyboardFunc(keyboard);//鍵盤
    glutMouseFunc(mouse);//聲音
    glutMainLoop();
}


#include<GL/freeglut.h>
#include<mmsystem.h>
#include<stdio.h>
#include<math.h>
float potx=-1,poty=0;
void mouse (int button, int state , int x,int y)
{
    if(state == GLUT_DOWN)
    {
        PlaySound("Shot.wav",NULL,SND_ASYNC);
        printf("Shot!\n");
        float mousex= 2*x/1280.0 -1 , mousey=2*y/1024.0 -1;
        if(fabs(mousex-potx)<0.1 &&fabs(mousey-poty)<0.1 )
        {
            PlaySound("Cow.wav",NULL,SND_ASYNC);
            printf("YOU GET IT!!!\n");
        }
    }
}
void keyboard (unsigned char key, int x , int y)
{
    exit(0);
}

void display ()
{
    potx+=0.01;
    if(potx>1.1)potx=-1.1;
    glClearColor(0.5,0.5,1,0);
    glClear(GL_COLOR_BUFFER_BIT);
    glPushMatrix();
    glTranslated(potx,poty,0);
    glutSolidTeapot(0.08);
    glPopMatrix();
    glFlush();
}

int main(int argc,char** argv)
{
    glutInit(&argc,argv);
    glutCreateWindow("02160393_DownChess");

    glutFullScreen();
    glutDisplayFunc(display);
    glutIdleFunc(display);
    glutKeyboardFunc(keyboard);
    glutMouseFunc(mouse);
    glutMainLoop();
}



沒有留言:

張貼留言