Update

The update() method is an essential part of BaseClass which is ancestor of all vrecko classes.

Update method is basically a simple callback function which is called by the Scheduler in a regular time interval defined by a programmer.

Implementation of a regular callback is crucial in a majority of cases, such as:

  • object animation (e.g. using motion capture techniques),
  • physics computation,
  • rendering to texture,
  • re-computation of various data structures,
  • and a lot more.

Setting up the update method

To set the update frequency of your ability, call the appropriate scheduler method, in your initialize() method

world->getSchedulerPtr()->addEntity(this, frequency);

where frequency is a positive floating point or the FRAME_FREQUENCY constant defined in a header file vrecko/Scheduler.h.

After calling the aforementioned method, the system will attempt to call your object’s update() method at specified intervals. However, it will do so only once per frame in the main thread altogether with processing the graphics and handling other abilities.

This may result in an unexpected behaviour – if the frequency of your ability is e.g. 100 Hz but the main thread runs only at 30 Hz, your ability’s update() method will be called approximately three times per frame, in a row. No other processing (such as handling of events and other abilities or rendering) takes place in-between.

Because of this, it is usually good to use the FRAME_FREQUENCY constant which assures that your object’s update() method is called exactly once per frame. In case you need to base your computations on the time difference since the last call of the update() method, use the osg::Timer class.

You are of course free to use low frequencies such as 1/60 Hz to call the update() method once per minute.