1.實作:計時器
2.實作:動畫
前置
讀取
附錄1:今天前半的程式
#include <GL/glut.h>
#include <mmsystem.h>
#include <stdio.h>
float angle=0;
float nowx=0;
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glRotatef(-angle, 0,0,1);
glTranslated(-nowx,0,0);
glColor3f(1,1,1);
glutSolidTeapot( 0.3 );
glPopMatrix();
glutSwapBuffers();
}
void timer(int t)
{
glutTimerFunc(30,timer,t+1);
printf("timer(t): %d\n",t);
angle=t;
float alpha=(t%30)/30;
nowx=alpha*1.0+(1-alpha)*(-1.0);
glutPostRedisplay();
//PlaySoundA("largedoor.wav",NULL,SND_ASYNC);
}
int main(int argc,char ** argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutInitWindowSize(600,600);
glutCreateWindow("week14");
glutDisplayFunc(display);
glutTimerFunc(1000,timer,0);
glutMainLoop();
}
附錄2:今天後半的程式(因為大多是別人的 節學到的)
void timer(int t)
{
glutTimerFunc(30,timer,t+1);
if(t%30==0){
if(forout==NULL){
forout=fopen("idontknow.txt","r");
for(int i=1;i<=8;i++){
oldangle[i]=newangle[i];
fscanf( forout," %f ",&newangle[i]);
}
}
}
float alpha=(t%30)/30;
for(int i=1;i<=8;i++){
angle[i]=alpha*newangle[i]+(1-alpha)*oldangle[i];
}
glutPostRedisplay();
}
if(key=='r'){
if(forout==NULL){
forout=fopen("idontknow.txt","r");
}
for(int i=1;i<=8;i++){
fscanf( forout," %f ",&angle[i]);
}
}
if(key=='t'){
glutTimerFunc(30,timer,0);
if(forout==NULL){
forout=fopen("idontknow.txt","r");
for(int i=1;i<=8;i++){
fscanf( forout," %f ",&angle[i]);
}
}
}
注:forout,要新增
沒有留言:
張貼留言