Sign in to follow this  
openX

Speed -- how to delay ?

Recommended Posts

Hello everybody, My problem is I need draw One light Point ( in OpenGL ) that moves between two points A and B with t parameter like this equation: A(x1,y1,z1) & B(x2,y2,z2) the equation: x = t*(x1-x2) + x2; y = t*(y1-y2) + y2; z = t*(z1-z2) + z2; t is increased by the value: (example )0.xxxxxx until t = 1 then stop. The program that run on my computer looks nice but look too fast(low) when it is run on other computer that are more powerful( powerless ). I don't know how to do to it have the same speed ? Thank for all.

Share this post


Link to post
Share on other sites
What your problem is, is how to implement animation. There's probably tons of tutorials and articles, many on this site. But to give a quick introduction:

There are basically two ways of doing this. In both cases you set a loop for rendering, much as you've done.

In the first method, at the start of the loop you call whatever system function you need to get the current time in fractions of a second. Subtract from this what you got on the previous cycle of the loop to get the amount of real time it took to go through the loop the last time. Then you simply advance your animation time in steps of Δt, which is the duration of time we compute at the beginning of the loop. In your case this means that your add Δt to t.

The second method is to keep the time step Δt constant. You add Δt to t as before, but this time t corresponds to animation time, which we wish to keep in sync with real time. You do this at the beginning of the loop by computing the amount of real time that has passed since the animation started and if that is less that your current value of t you make the program sleep for a duration equal to the difference.

Share this post


Link to post
Share on other sites
thank SnotBob,

but i mean this: with same parameter t when on my computer it look nice but when other computer it look fast. I do not know to fix it ?

Share this post


Link to post
Share on other sites
The reason why it's going faster on a faster computer is precisely because you do not take into account the time it actually takes to display your animation. I explained in my previous post two ways to fix your problem. Why don't you try out the first one.

Share this post


Link to post
Share on other sites
OpenX,

Whats the difference between the two machines? Different CPUs?

You might be seeing a difference between the cycle speed, if your counting the number of clock cycles before moving the item then you would get different speeds on different hardware platforms.

Share this post


Link to post
Share on other sites
Another computer might have a higher framerate than yours, which means it updates faster. Updating faster means the animation will go much quicker. What you want is Time Based Movement or Frame Independent Movement. Google it.

Share this post


Link to post
Share on other sites
Thank Tenac . Can you explain that more detail. I cannot limit my frame rate or speed when my program run on another computer. It will too fast if that one is more powerful.

Share this post


Link to post
Share on other sites
unlikely nobody will provide you with a complete implementation, which is what you would like to receive.

It's very easy to implement so google it, or make some effort as same question has been answered on this forum recently with code provided.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this