2015年4月9日 星期四

week07洞陸扒伍

(1)作業互評(peer assessment):品味(HFS)
(2)keyboard,mouse,UI"考試都不會考"
(3)音效,音樂"考試都不會考"
(4)期中考題目,答案
(5)模擬考


1.建立用keyboard輸出文字
#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("aaaaaa\n");
    if(key=='b') printf("bbbbbb\n");
}
int main(int argc,char**argv)
{
    glutInit(&argc, argv);
    glutCreateWindow("02160685");

    glutDisplayFunc(display);
    glutKeyboardFunc(keyboard);
    glutMainLoop();
}
上面是程式碼
重要三行
void keyboard(unsigned char key,int x,int y)
{
    if(key=='a') printf("aaaaaa\n");
    if(key=='b') printf("bbbbbb\n");
}



















2修改程式碼,可輸出音效
#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("tarzan.wav",NULL,SND_ASYNC);
        printf("阿  ~~~哈哈哈ㄏ哈哈哈阿\n");
    }
    if(key=='b') printf("bbbbbb\n");
}
int main(int argc,char**argv)
{
    glutInit(&argc, argv);
    glutCreateWindow("02160685");

    glutDisplayFunc(display);
    glutKeyboardFunc(keyboard);
    glutMainLoop();
}
主要程式
#include <mmsystem.h>
 if(key=='a'){
  PlaySound("tarzan.wav",NULL,SND_ASYNC);
  printf("阿  ~~~哈哈哈ㄏ哈哈哈阿\n");



















3.輸出小小鋼琴
#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=='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("02160685");

    glutDisplayFunc(display);
    glutKeyboardFunc(keyboard);
    glutMainLoop();
}
重要程式
void keyboard(unsigned char key,int x,int y)
{
    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);
}



















4用keyboard,mouse,special,motion涵式讓茶壺轉動移動
#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);
    glEnd();
    glFlush();
}
void keyboard(unsigned char key,int x,int y)
{
    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("02160685");

    glutDisplayFunc(display);
    glutKeyboardFunc(keyboard);
    glutSpecialFunc(special);
    glutMouseFunc(mouse);
    glutMotionFunc(motion);
    glutMainLoop();
}
主要程式碼
Main
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);
    glEnd();
    glFlush();
}
Keyboard
void keyboard(unsigned char key,int x,int y)
{
    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);
}
Special
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();
}
Mouse
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");
}
Motion
void motion(int x,int y)
{
    rotX +=y-oldY;
    rotY +=x-oldX;
    oldX=x;oldY=y;
    glutPostRedisplay();
}
glutKeyboardFunc(keyboard);
glutSpecialFunc(special);
glutMouseFunc(mouse);
glutMotionFunc(motion);

沒有留言:

張貼留言