开发者

suspend a function for sometime in opengl

I have a function Drwa() this is rendering a triangle on screen.and also i have another Draw_poly() which is rendering a Rectangle on screen. And i also i m rotating rectangle and triangle both simultaneously.I want to keep speed of rotation different for both how will i do ?

Let suppose i am moving an object on screen and another i m rotating then how will i do ? That's why i m looking for function moving of object will keep time limited and rotating object will not keep time.So rotation 开发者_如何学Gowill be fast and moving of object will be slow


First, define your rotation as angle per second. Then in your main draw function, compute the elapsed time in second, multiply by the angular speed, and you're done.


I would like to partecipate with a an answer of mine.

The answer of genpfault could be good as much as you need, but if you would like to produce a good animation you need to design a better software.

Here, look at my answer. However, reading another your question, I think you are missing some fundamental point: learn OpenGL architecture, practice on each OpenGL entry point, read books.

At last, but not least, I would you suggest to search for answer already told on stackoverflow. This is supposed to be a question & answer site...


Rotate one less/slower than the other:

static float rot_a = 0.0;
static float rot_b = 0.0;

rot_a += 1.0;
rot_b += 0.5;

glPushMatrix();
glRotatef( rot_a, 0, 0, 1 );
Draw_A();
glPopMatrix();

glPushMatrix();
glRotatef( rot_b, 0, 0, 1 );
Draw_B();
glPopMatrix();

Alternatively you can spin up some threads that modify your object positions and sleep() without blocking the render thread.

Position obj_a;
Position obj_b;

void thread_1()
{
    while( !done )
    {
        sleep(1);
        modify_pos( obj_a );
    }
}


void thread_2()
{
    while( !done )
    {
        sleep(2);
        modify_pos( obj_b );
    }
}


void draw()
{
    glPushMatrix();
    position_object( obj_a );
    Draw_A();
    glPopMatrix();

    glPushMatrix();
    position_object( obj_b );
    Draw_B();
    glPopMatrix();
}


int main()
{
...
launch_thread( thread_1 );
launch_thread( thread_2 );

...
return 0;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜