1.模擬考,期中考
2.用範例學習
3.打光→法向量
4.貼圖→貼圖座標
5.NeHe Lesson32小遊戲 : http://nehe.gamedev.net/
測試 程式碼效果
#include<GL/glut.h>///宣告
#include<stdio.h>///宣告
#include<mmsystem.h>///宣告
void display()///函式
{
glClearColor(0.5,0.5,1,0);
glClear(GL_COLOR_BUFFER_BIT);
glFlush();
}
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("BULLET.wav",NULL,SND_ASYNC); //產生槍聲音效
printf("Shot!\n");
}
}
int main(int argc,char *argv[])
{
glutInit(&argc,argv);
glutCreateWindow("02160270_射擊測試");
glutFullScreen(); //全螢幕顯示
glutDisplayFunc(display);
glutKeyboardFunc(keyboard);
glutMouseFunc(mouse);
glutMainLoop();
}
新增會移動的茶壺
#include<GL/glut.h>///宣告
#include<stdio.h>///宣告
#include<mmsystem.h>///宣告
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();
glTranslatef(potX,potY,0);
glutSolidTeapot(0.05);
glPopMatrix();
glFlush();
}
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("BULLET.wav",NULL,SND_ASYNC);
printf("Shot!\n");
}
}
int main(int argc,char *argv[])
{
glutInit(&argc,argv);
glutCreateWindow("02160270_射擊測試");
glutFullScreen();
glutDisplayFunc(display);
glutIdleFunc(display);
glutKeyboardFunc(keyboard);
glutMouseFunc(mouse);
glutMainLoop();
}
之後加上 偵測到茶壺射擊後發出的叫聲
#include<GL/glut.h>///宣告
#include<stdio.h>///宣告
#include<mmsystem.h>///宣告
#include<math.h>
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();
glTranslatef(potX,potY,0);
glutSolidTeapot(0.05);
glPopMatrix();
glFlush();
}
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("BULLET.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("ahhh.wav",NULL,SND_ASYNC);
printf("You got it !\n");
}
}
}
int main(int argc,char *argv[])
{
glutInit(&argc,argv);
glutCreateWindow("02160270_射擊測試");
glutFullScreen();
glutDisplayFunc(display);
glutIdleFunc(display);
glutKeyboardFunc(keyboard);
glutMouseFunc(mouse);
glutMainLoop();
}
沒有留言:
張貼留言