計時器聲音
#include <GL/glut.h>
#include <mmsystem.h>///NOW (0)發聲音
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glutSwapBuffers();
}
void timer(int t)///NOW (2)
{
glutTimerFunc(1000, timer, 0);///NOW2
PlaySoundA("fart.wav", NULL, SND_ASYNC);///NOW (2)
}
int main(int argc, char**argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutInitWindowSize(500,500);///大一點
glutCreateWindow("week14 timer");
glutDisplayFunc(display);
glutTimerFunc(1000, timer, 0);///NOW (1)
glutMainLoop();
}
內插:
alpha*新+(1-alpha)*舊 |
#include <GL/glut.h>
#include <mmsystem.h>///NOW (0)發聲音
#include <stdio.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)///NOW (2)
{
glutTimerFunc(33, timer, t+1);
printf("現在的 timer(t)的t是: %d\n", t);///NOW3
float alpha = (t%30) / 30.0;
nowX = alpha*1.0 + (1-alpha)* -1.0;
glutPostRedisplay();///NOW4 要更新畫面
}
int main(int argc, char**argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutInitWindowSize(500,500);///大一點
glutCreateWindow("week14 timer");
glutDisplayFunc(display);
glutTimerFunc(1000, timer, 0);///NOW (1)
glutMainLoop();
}
沒有留言:
張貼留言