2016年6月16日 星期四

㍿ ✘✘✘✘DOPE✘✘✘✘ Week15


在OPENGL/GLUT做

動作內插





10個ROT 

去內插播放(TIMER)計時器

程式碼

可以存入每個位置的數值 利用TIMER函式將兩個數值內插多個數值,可以讓動作變得更平滑流暢

#include <stdio.h>
#include <GL/glut.h>
float pos=0, oldX=0.7, newX=0.1;
void display()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glPushMatrix();
        glTranslatef(pos, 0,0);
        glutSolidTeapot(0.2);
    glPopMatrix();
    glutSwapBuffers();
}
void timer (int t)
{
    float alpha=t/100.0;
    pos = newX*alpha+oldX*(1-alpha);
    printf("%d %f %f \n",t,alpha,pos);
    glutTimerFunc(100,timer,t+1);
    glutPostRedisplay();
}
int main (int argc, char**argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("123");
    glutDisplayFunc(display);
    glutTimerFunc(100,timer,0);
    glutMainLoop();
}

沒有留言:

張貼留言