如何为曲线上的实心球体设置动画 [英] How to animate a solid sphere over a curve

查看:28
本文介绍了如何为曲线上的实心球体设置动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用 opengl 编写一个程序来为曲线上的实体球体制作动画
它就像
//显示函数

i am making a program in opengl to animate a solid-sphere over a curve
it goes like
//display function

void display()  
{  
    glClear(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT);  
    glLoadIdentity();  
    //set of condition   
    loop:j=1 to 5  
        loop:i=1 to 3  
            if(j==1)
            {  
                animate(x,y,z)  
                glutSwapBuffers();
            }
            elseif(j==5)
            {  
                animate(x,y,z)  
                glutSwapBuffers();
            }  
            else //for all value j between 1 and 5
            {  
                animate(x,y,z);  
                glutSwapBuffers();
            }  
}  

//animate function  
void animate(float x, float y, float z)  
{  
    glLoadIdentity();  
    glTranslatef(0,0,-20);  
    glPushMatrix();  
    glTranslatef (x, y, z);  
    glutSolidSphere (0.3, 10, 10);  

    int i, j;  

    for(i = 0; i < 10000; i++) //for introducing delay  
        for(j = 0; j < 5000; j++);


    glPopMatrix();  
    glutSwapBuffers();  
}  

问题:实心球体正在曲线上平移,但对于它的下一个位置我无法删除其先前的位置...例如如果球体从 P1,P2,P3,P4 AND THEN P5..after 等位置序列开始来到位置 P5 它在所有其他先前位置仍然可见(P1,P2,P3,P4)但我希望它在翻译时仅在当前位置显示球体我该怎么做?

Problem:the solid sphere is translating over the curve but for its each next position i am not able to remove its previous position...for instance if the sphere goes from sequence of position like P1,P2,P3,P4 AND THEN P5..after coming to position P5 its still visible at all others previous position(P1,P2,P3,P4) but i want it to display sphere only at current position while translation How can i do this?

推荐答案

您没有清除帧缓冲区,这意味着您正在前一帧的顶部绘制每一帧.尝试使用 glClearColor(0.0f, 0.0f, 0.0f, 1.0f ); 和您想要的颜色.

You are not clearing the frame buffer, which means that you are drawing each frame on top of the previous frame. Try using glClearColor(0.0f, 0.0f, 0.0f, 1.0f ); with the color you desire.

这篇关于如何为曲线上的实心球体设置动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆