[Qt-interest] Animation with QGraphicsView

Arnold Krille arnold at arnoldarts.de
Sat May 2 17:13:52 CEST 2009


Hi,

On Saturday 02 May 2009 13:39:04 Freddie Witherden wrote:
> My application uses QGraphicsView to model a physical system, in which
> the position of objects (x,y) is a function of time. Currently my
> application works by using a timer set to fire every m_timeStep
> milliseconds and calling scene()->advanced() in the timer event.
> This causes each simulated object to advance by m_timeStep and update
> its position. The problem is that if the system is unable to keep
> manage 60 advances a second the simulation lags. Obviously this is not
> the right way to go about it.

As you noticed, you can't be sure if the time passed is your given interval or 
more than your given interval. If the gui isn't fast enough, your timer gets 
scheduled as fast as possible after the current running event (which should be 
the paint-event).

So using a timer with an interval of 1000/60ms will give you at maximum 60 
frames per second (which is what you want). But using a counter times the 
interval you set will in worst case give you a timing slower than realtime. 
The only chance to "fix" this is to use the timer for scheduling our 
simulation-ticks but use QTime to get the real time elapsed since start of the 
simulation...
Which might make interpolation harder as you can't rely on the future and only 
interpolate from the past because there is no guarantee that the next interval 
will be 1/60s exactly.

If you want to export the simulation to video online or offline, you might start 
to think about a) using a parameter for the interval and b) make the usage of 
QTime configurable because with the fixed framerate and offline-simulation you 
will need an own clock. Sounds like an abstract TimeLine-class...

Have fun,

Arnold
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: This is a digitally signed message part.
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090502/94b3b537/attachment.bin 


More information about the Qt-interest-old mailing list