Hi folks,
I'm trying to implement some kind of animation framework into OpenSG,
which is based on the following idea:
the user specifies a list of control points (with each point associated
to a time value) and the field container whose fields are to be animated
(every control point contains a field container of the same type of the
one we want to 'animate'). Such data is then handed down to an
'AnimationController' object, which calculates the current time and thus
interpolates the control points in the given list: this stuff is done
inside the method AnimationController::Animate(), which is called every
frame before the actual rendering occurs.
Here's an example (I'm using GLUT):
...
AnimationController ac ;
SimpleSceneManager* mgr ;
...
...
ComponentTransformPtr ct = ComponentTransform::create();
NodePtr someNode = Node::create();
{
CPEdit(someNode, Node::CoreFieldMask);
someNdoe->setCore(ct);
}
...
ComponentTransformPtr ct1 = ComponentTransform::create();
ComponentTransformPtr ct2 = ComponentTransform::create();
BitVector mask = ComponentTransform::RotationFieldMask |
ComponentTransform::TranslationFieldMask ;
{
CPEdit(ct1, mask);
CPEdit(ct2, mask);
...
...
// Set some new field values
}
// ControlPoint and ControlPointList have been created by me
ControlPointList cpl(mask);
// The mask is needed in order to know which fields have actually
// to be modified.
ControlPoint cp1(ct1);
ControlPoint cp2(ct2);
cpl.InsertControlPoint(0.0, cp1); //First parameter is 'time'
cpl.InsertControlPoint(10.0, cp2); //Second parameter is the control point
ac.InsertFieldContainer(someNode->getCore(), cpl);
...
glutMainLoop();
...
//End Main
// GLUT Display Function
void display(void)
{
ac.Animate();
mgr->redraw();
return ;
}
The Animate() method works as follows:
after calculating the current time, a new ControlPoint object with a
field container inside is created. Such field container is then assigned
the correct value which has just ben retrieved from the interpolation
between two control points, and then the update of the field container
returned by "someNode->getCore()" can take place: using the field mask
provided to the ControlPointList object to identify the fields to be
updated and checking the string returned by the
FieldContainer::getTypeName() in order to know what tipe of core we are
dealing with, the appropriate fields are updated via CPEdit(fcPtr,
field_mask).
This method has been tested and seems to work fine, but I also would
like to try a different approach such as, for example, passing a plain
Vec3f to the ControlPoint class constructor and making the appropriate
field do the update by itself (perhaps using some kind of Vec3f wrapper
class with an update() method inside).
Any help/suggestions would be greatly appreciated!
Cheers,
Carlo
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Opensg-core mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/opensg-core