1.主題:計時器
#include <GL/glut.h>
#include <mmsystem.h>
#include <stdio.h>
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glutSolidTeapot( 0.3 );
glutSwapBuffers();
}
void timer(int t)
{
glutTimerFunc(1000,timer,t+1);
printf("t=%d",t);
PlaySoundA("bird.wav",NULL,SND_ASYNC);
}
int main(int argc, char**argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutInitWindowSize(500,500);
glutCreateWindow("week 14 timer");
glutDisplayFunc(display);
glutTimerFunc(1000,timer,0);
glutMainLoop();
}
2.主題:內插公式
3.主題:動畫
#include <GL/glut.h>
#include <mmsystem.h>
float angle=0;
float nowX=0;
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glTranslatef(nowX,0,0);
glutSolidTeapot( 0.3 );
glPopMatrix();
glutSwapBuffers();
}
void timer(int t)
{
///1000 ms =1 sec,30 ms =1/33 sec,33 fps
glutTimerFunc(30,timer,t+1);
float alpha=(t%33)/33.0;///alpha內插
nowX=alpha*1+(1-alpha)*-1;
alpha+=1;
glutPostRedisplay();///系統重繪畫面
PlaySoundA("bird.wav",NULL,SND_ASYNC);
}
int main(int argc, char**argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutInitWindowSize(500,500);
glutCreateWindow("week 14 timer");
glutDisplayFunc(display);
glutTimerFunc(1000,timer,0);
glutMainLoop();
}
4.上週hw問題回覆
5.期末作品
沒有留言:
張貼留言