2019年5月23日 星期四

瞎78打-11

( 1 ) 主題 : 計時器 Timer
( 2 ) 主題 : 內差公式
( 3 ) 主題 : 動畫
( 4 ) 期末作品
--------------------------------------------------------------------------

每秒發一次聲音

#include <GL/glut.h>
#include <mmsystem.h>///Now (1)
#include <stdio.h>///printf()
void display()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glutSolidTeapot( 0.3 );
    glutSwapBuffers();
}
void timer(int t)///NOW timer!!!!
{
    glutTimerFunc(1000, timer, t+1 );///NOW timer!!!! 起床要播下一個鬧鐘
    printf("timer(t) 的 t是 %d\n", t);///順便印一下現在的t是多少
    PlaySoundA("fart.wav", NULL, SND_ASYNC);///Now (2) ///NOW timer!!!!
}
int main(int argc, char**argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutInitWindowSize(500,500);///變大了
    glutCreateWindow("week 14 timer");

    glutDisplayFunc(display);
    glutTimerFunc(3000, timer, 0);///NOW timer!!!!

    glutMainLoop();
}

每秒轉一次角度


void timer(int t)///NOW timer!!!!
{
    /// 1000 ms = 1 sec,  30 ms = 1/33 sec , 33 fps
    glutTimerFunc(30, timer, t+1 );///NOW timer!!!! 起床要播下一個鬧鐘
    angle += 1;
    glutPostRedisplay();///系統重繪畫面
}

內插法:

  excel  =  B2*96+(1-B2)*73

 程式套用內插法移動

float angle=0;
float nowX=0;///NOW2
void display()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glPushMatrix();
        glTranslatef(nowX, 0, 0);///NOW2
        glutSolidTeapot( 0.3 );
    glPopMatrix();
    glutSwapBuffers();
}
void timer(int t)///NOW timer!!!!
{
    /// 1000 ms = 1 sec,  30 ms = 1/33 sec , 33 fps
    glutTimerFunc(30, timer, t+1 );///NOW timer!!!! 起床要播下一個鬧鐘
    float alpha = (t%33) / 33.0;///NOW2 alpha 內插
    nowX = alpha* 1 + (1-alpha)* -1 ;///NOW2

    angle += 1;
    glutPostRedisplay();///系統重繪畫面
}

沒有留言:

張貼留言