Home

hersto:  Follower Implementation in C++

 

Rant to the author:

    

Check for a response

The "Follower C++ Library" provides two template classes for generating animations as described on the Followers Page. This library can be used in applications that want to create always-smooth transitions in their user interface by just specifying a new destination value, as well as in X3D players that want to implement the component 39, "Followers" as of the X3D specification ISO/IEC FCD 19775-1r1:200x.

Classes provided by the Followes C++ Library

The Followers C++ library consists of four classes, where you usually use only two, the CTDamper and the CTChaser:

Values are animated with the CTDamper and CTChaser classes. They receive as a template parameter the type they animate, e.g. double, MyColorClass, or SFVec3f. They have a common abstract base class CTimeDependent that allows them to receive timing information in form of a periodically called Tick(.) method.

A CFollowerVarTrait class translates the operations that the CTDamper and CTChaser classes need to perform on the underlying data type to the operations that the data type supports. E.g. the Interpolate(.) operation is translated to A + (B - A) * t. You usually don't need to tweak with the CFollowerVarTrait class. Only for special data types that differ too much from normal numbers you must provide a template specialization of CFollowerVarTrait. This is explained later with 3D Rotations (yet to come).

Both, CTDamper and CTChaser share the same methods for performing the animation. set_destination(.) sets a new destination value that the internal value in the CTDamper or CTChaser has to move towards, and set_value(.) overrides the internal value, so that the generated animation starts from that value towards the destination value. Both functions trigger a sequence of output values that the CTDamper or CTChaser send over their callback mechanism. The currently set destination value and the current output value can be queried via the get_destination() and get_value() methods. With the method get_isActive() it can be queried whether the CTDamper or CTChaser currently performs an animation, i.e. whether it periodically fires events over its callback mechanism.

The CTDamper and CTChaser objects support automatic propagation of changes to their internal state, which is the current value of the animation performed, and a bool flag that tells whether an animation starts or ends. While other languages like C# have an elaborate event mechanism or support closures like JavaScript, C++ does not have a native such mechanism for event propagatin. Instead of deciding for one of the mechanisms in use, or developing its own, the Followers C++ library resorts to the most basic mechanism in C++, which is the C callback function with an opaque context parameter. Therefore the method SetReceivers(.) allows to specify callback methods for updates on the internal value and notification of animation start or end.

Viewing files online

The Followers C++ library consists of the following files:

Download

Please Note:
Chasers are not yet implemented. Only Dampers are available in the current version.

Please download the library here: FollowersCppLib-1.0.rar (7.64 K Byte)

For an example application that demonstrates usage of the Followes C++ Library, see the Followers Tester application.

 

__.-.__
end of document