2015年4月9日 星期四

02160925_葉乃慈 week07

#include <GL/glut.h>
#include <stdio.h>

void display()
{
    glutSolidTeapot(0.3);
    glFlush();
}
void keyboard(unsigned char key,int x,int y)
{
    if(key =='a') printf("aaaaa\n");
    if(key =='b') printf("bbbbb\n");
}
int main(int argc,char**argv)
{
    glutInit(&argc, argv);
    glutCreateWindow("02160925");

    glutDisplayFunc(display);
    glutKeyboardFunc(keyboard);
    glutMainLoop();
}
#include <GL/glut.h>
#include <stdio.h>
#include <mmsystem.h>
void display()
{
    glutSolidTeapot(0.3);
    glFlush();
}
void keyboard(unsigned char key,int x,int y)
{
    if(key =='a') {
            PlaySound("atchoum.wav",NULL,SND_ASYNC);
            printf("aaaaa\n");
    }
    if(key =='b') printf("bbbbb\n");
}
int main(int argc,char**argv)
{
    glutInit(&argc, argv);
    glutCreateWindow("02160925");

    glutDisplayFunc(display);
    glutKeyboardFunc(keyboard);
    glutMainLoop();
}
#include <GL/glut.h>
#include <stdio.h>
#include <mmsystem.h>
void display()
{
    glutSolidTeapot(0.3);
    glFlush();
}
void keyboard(unsigned char key,int x,int y)
{
    if(key =='a') {
            PlaySound("atchoum.wav",NULL,SND_ASYNC);
            printf("aaaaa\n");
    }
    if(key =='1') PlaySound("Do.wav",NULL,SND_ASYNC);
    if(key =='2') PlaySound("Re.wav",NULL,SND_ASYNC);
    if(key =='3') PlaySound("Mi.wav",NULL,SND_ASYNC);
    if(key =='4') PlaySound("Fa.wav",NULL,SND_ASYNC);
    if(key =='5') PlaySound("Sol.wav",NULL,SND_ASYNC);
    if(key =='6') PlaySound("La.wav",NULL,SND_ASYNC);
    if(key =='7') PlaySound("Si.wav",NULL,SND_ASYNC);
}
int main(int argc,char**argv)
{
    glutInit(&argc, argv);
    glutCreateWindow("02160925");

    glutDisplayFunc(display);
    glutKeyboardFunc(keyboard);
    glutMainLoop();
}
(四)
旋轉
#include <GL/glut.h>
#include <stdio.h>
#include <mmsystem.h>
float teaY=0,rotX=0,rotY=0,oldX=0,oldY=0;
void display()
{
    glClear(GL_COLOR_BUFFER_BIT);
    glPushMatrix();
    glTranslatef(0,teaY,0);
    glRotatef(rotX,1,0,0);
    glRotatef(rotY,0,1,0);
    glutSolidTeapot(0.3);
    glPopMatrix();
    glFlush();
}
void keyboard(unsigned char key,int x,int y)
{
        if(key =='a') {
            PlaySound("atchoum.wav",NULL,SND_ASYNC);
            printf("aaaaa\n");
    }
if(key =='1') PlaySound("Do.wav",NULL,SND_ASYNC);
    if(key =='2') PlaySound("Re.wav",NULL,SND_ASYNC);
    if(key =='3') PlaySound("Mi.wav",NULL,SND_ASYNC);
    if(key =='4') PlaySound("Fa.wav",NULL,SND_ASYNC);
    if(key =='5') PlaySound("Sol.wav",NULL,SND_ASYNC);
    if(key =='6') PlaySound("La.wav",NULL,SND_ASYNC);
    if(key =='7') PlaySound("Si.wav",NULL,SND_ASYNC);
}

void special(int key,int x,int y)
{
    if(key==GLUT_KEY_DOWN)
        {
        teaY-=0.1; printf("down\n");
    }
    else if(key==GLUT_KEY_UP){
    teaY+=0.1; printf("up\n");
    }
    glutPostRedisplay();
}
void mouse(int button,int state,int X,int Y)
{
    oldX=X;oldY=Y;
    if(GLUT_LEFT_BUTTON==button && GLUT_DOWN==state) printf("now left down\n");
    if(GLUT_RIGHT_BUTTON==button && GLUT_DOWN==state) printf("now right down\n");
}

void motion(int x,int y)
{
    rotX +=y-oldY;
    rotY +=x-oldX;
    oldX=x; oldY=y;
    glutPostRedisplay();
}

int main(int argc,char**argv)
{
    glutInit(&argc, argv);
    glutCreateWindow("02160925");
    glutDisplayFunc(display);
    glutKeyboardFunc(keyboard);
    glutSpecialFunc(special);
    glutMouseFunc(mouse);
    glutMotionFunc(motion);
    glutMainLoop();
}




沒有留言:

張貼留言