第一堂
作業互評
第二堂
Keyboard
#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("soap3.wav",NULL,SND_ASYNC);
if (key == 'b') puts("bbbbb");
}
int main (int argc, char *argv[])
{
glutInit(&argc, argv);
glutCreateWindow("02160136");
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 == '1') {PlaySound("Do.wav",NULL,SND_ASYNC); puts("Do");}
if (key == '2') {PlaySound("Re.wav",NULL,SND_ASYNC); puts("Re");}
if (key == '3') {PlaySound("Mi.wav",NULL,SND_ASYNC); puts("Mi");}
if (key == '4') {PlaySound("Fa.wav",NULL,SND_ASYNC); puts("Fa");}
if (key == '5') {PlaySound("So.wav",NULL,SND_ASYNC); puts("So");}
if (key == '6') {PlaySound("La.wav",NULL,SND_ASYNC); puts("La");}
if (key == '7') {PlaySound("Si.wav",NULL,SND_ASYNC); puts("Si");}
}
int main (int argc, char *argv[])
{
glutInit(&argc, argv);
glutCreateWindow("02160136");
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 == '1') {PlaySound("Do.wav",NULL,SND_ASYNC); puts("Do");}
if (key == '2') {PlaySound("Re.wav",NULL,SND_ASYNC); puts("Re");}
if (key == '3') {PlaySound("Mi.wav",NULL,SND_ASYNC); puts("Mi");}
if (key == '4') {PlaySound("Fa.wav",NULL,SND_ASYNC); puts("Fa");}
if (key == '5') {PlaySound("So.wav",NULL,SND_ASYNC); puts("So");}
if (key == '6') {PlaySound("La.wav",NULL,SND_ASYNC); puts("La");}
if (key == '7') {PlaySound("Si.wav",NULL,SND_ASYNC); puts("Si");}
}
void mouse (int button, int state, int x, int y)
{
oldX = x; oldY = y;
if (GLUT_LEFT_BUTTON == button && GLUT_DOWN == state) puts("now left down");
if (GLUT_RIGHT_BUTTON == button && GLUT_DOWN == state) puts("now right down");
}
void motion (int x, int y)
{
rotX += y - oldY;
rotY += x - oldX;
oldX = x;
oldY = y;
glutPostRedisplay();
}
void special (int key, int x, int y)
{
if (key == GLUT_KEY_DOWN){teaY -= 0.1; puts("down");}
else if (key == GLUT_KEY_UP){teaY += 0.1; puts("up");}
glutPostRedisplay();
}
int main (int argc, char *argv[])
{
glutInit(&argc, argv);
glutCreateWindow("02160136");
glutDisplayFunc(display);
glutKeyboardFunc(keyboard);
glutSpecialFunc(special);
glutMouseFunc(mouse);
glutMotionFunc(motion);
glutMainLoop();
}
#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 == '1') {PlaySound("Do.wav",NULL,SND_ASYNC); puts("Do");}
if (key == '2') {PlaySound("Re.wav",NULL,SND_ASYNC); puts("Re");}
if (key == '3') {PlaySound("Mi.wav",NULL,SND_ASYNC); puts("Mi");}
if (key == '4') {PlaySound("Fa.wav",NULL,SND_ASYNC); puts("Fa");}
if (key == '5') {PlaySound("So.wav",NULL,SND_ASYNC); puts("So");}
if (key == '6') {PlaySound("La.wav",NULL,SND_ASYNC); puts("La");}
if (key == '7') {PlaySound("Si.wav",NULL,SND_ASYNC); puts("Si");}
}
void mouse (int button, int state, int x, int y)
{
oldX = x; oldY = y;
if (GLUT_LEFT_BUTTON == button && GLUT_DOWN == state) puts("now left down");
if (GLUT_RIGHT_BUTTON == button && GLUT_DOWN == state) puts("now right down");
}
void motion (int x, int y)
{
rotX += y - oldY;
rotY += x - oldX;
oldX = x;
oldY = y;
glutPostRedisplay();
}
void special (int key, int x, int y)
{
if (key == GLUT_KEY_DOWN){teaY -= 0.1; puts("down");}
else if (key == GLUT_KEY_UP){teaY += 0.1; puts("up");}
glutPostRedisplay();
}
int main (int argc, char *argv[])
{
glutInit(&argc, argv);
glutCreateWindow("02160136");
glutDisplayFunc(display);
glutKeyboardFunc(keyboard);
glutSpecialFunc(special);
glutMouseFunc(mouse);
glutMotionFunc(motion);
glutMainLoop();
}
沒有留言:
張貼留言