2015年4月15日 星期三

02160403_林禹全_week08

今天主要是做出一個可以移動的茶壺,和點擊會有音效

#include<GL/glut.h>
#include<stdio.h>
#include<mmsystem.h> //認識Playsound
#include<opencv/highgui.h>
float potX=-1 ,potY=0;
void display ()
{
    glClearColor(0,0,1,0);
    glClear(GL_COLOR_BUFFER_BIT);
     glPushMatrix();
    glTranslatef(potX,potY, 0);
    glutSolidTeapot(0.1);
    glPopMatrix();

    glFlush();
    potX+=0.001;
    if(potX>1.1)potX=-1.1;
}
void keyboard(unsigned char key,int x,int y)
{
    exit(0);
}
void mouse(int button,int state,int x,int y)
{
    if(state==GLUT_DOWN) //如果滑鼠按下
    {
        PlaySound("Data/Shot.wav",NULL,SND_ASYNC);
        printf("SHOT!");
        float mouseX= 2*x/1280.0 -1,mouseY = -(2*y/1024.0 -1);
        if(abs(mouseX-potX)<0.01 && abs(mouseY-potY)<0.01)
        {
            printf("YA! got it!\n");
            PlaySound("ahhh.wav",NULL,SND_ASYNC);
        }
    }
}
int main(int argc,char**argv)
{
    glutInit(&argc, argv);
    glutCreateWindow("hello");
    glutFullScreen();
    glutDisplayFunc(display);
    glutIdleFunc(display);
    glutKeyboardFunc(keyboard);
    glutMouseFunc(mouse);
    IplImage * img=cvLoadImage("C:/Users/Public/Pictures/Sample Pictures/tulips.jpg");
    cvShowImage("a", img);
    cvWaitKey(10);
    glutMainLoop();
   
}

沒有留言:

張貼留言