1
0
Fork 0

Added select animation type (using a condition), and allow all

animations to be named.
This commit is contained in:
david 2002-04-01 14:00:08 +00:00
parent 394627b525
commit 7135382a28
2 changed files with 70 additions and 5 deletions

View file

@ -32,6 +32,9 @@ FGAircraftModel current_model; // FIXME: add to globals
// Static utility functions. // Static utility functions.
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
/**
* Locate a named SSG node in a branch.
*/
static ssgEntity * static ssgEntity *
find_named_node (ssgEntity * node, const char * name) find_named_node (ssgEntity * node, const char * name)
{ {
@ -296,6 +299,8 @@ FGAircraftModel::make_animation (const char * object_name,
const char * type = node->getStringValue("type"); const char * type = node->getStringValue("type");
if (!strcmp("none", type)) { if (!strcmp("none", type)) {
animation = new NullAnimation(); animation = new NullAnimation();
} else if (!strcmp("select", type)) {
animation = new SelectAnimation();
} else if (!strcmp("spin", type)) { } else if (!strcmp("spin", type)) {
animation = new SpinAnimation(); animation = new SpinAnimation();
} else if (!strcmp("rotate", type)) { } else if (!strcmp("rotate", type)) {
@ -340,17 +345,21 @@ FGAircraftModel::Animation::~Animation ()
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
FGAircraftModel::NullAnimation::NullAnimation () FGAircraftModel::NullAnimation::NullAnimation ()
: _branch(new ssgBranch)
{ {
} }
FGAircraftModel::NullAnimation::~NullAnimation () FGAircraftModel::NullAnimation::~NullAnimation ()
{ {
_branch = 0;
} }
void void
FGAircraftModel::NullAnimation::init (ssgEntity * object, FGAircraftModel::NullAnimation::init (ssgEntity * object,
SGPropertyNode * node) SGPropertyNode * props)
{ {
splice_branch(_branch, object);
_branch->setName(props->getStringValue("name", 0));
} }
void void
@ -359,6 +368,45 @@ FGAircraftModel::NullAnimation::update (int dt)
} }
////////////////////////////////////////////////////////////////////////
// Implementation of FGAircraftModel::SelectAnimation
////////////////////////////////////////////////////////////////////////
FGAircraftModel::SelectAnimation::SelectAnimation ()
: _condition(0),
_selector(new ssgSelector)
{
}
FGAircraftModel::SelectAnimation::~SelectAnimation ()
{
delete _condition;
_selector = 0;
}
void
FGAircraftModel::SelectAnimation::init (ssgEntity * object,
SGPropertyNode * props)
{
splice_branch(_selector, object);
_selector->setName(props->getStringValue("name", 0));
SGPropertyNode * node = props->getChild("condition");
if (node != 0) {
_condition = fgReadCondition(node);
}
}
void
FGAircraftModel::SelectAnimation::update (int dt)
{
if (_condition != 0 && _condition->test())
_selector->select(0xffff);
else
_selector->select(0x0000);
}
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
// Implementation of FGAircraftModel::SpinAnimation // Implementation of FGAircraftModel::SpinAnimation
@ -383,6 +431,7 @@ FGAircraftModel::SpinAnimation::init (ssgEntity * object,
{ {
// Splice in the new transform node // Splice in the new transform node
splice_branch(_transform, object); splice_branch(_transform, object);
_transform->setName(props->getStringValue("name", 0));
_prop = fgGetNode(props->getStringValue("property", "/null"), true); _prop = fgGetNode(props->getStringValue("property", "/null"), true);
_factor = props->getDoubleValue("factor", 1.0); _factor = props->getDoubleValue("factor", 1.0);
_position_deg = props->getDoubleValue("starting-position-deg", 0); _position_deg = props->getDoubleValue("starting-position-deg", 0);
@ -438,6 +487,7 @@ FGAircraftModel::RotateAnimation::init (ssgEntity * object,
{ {
// Splice in the new transform node // Splice in the new transform node
splice_branch(_transform, object); splice_branch(_transform, object);
_transform->setName(props->getStringValue("name", 0));
_prop = fgGetNode(props->getStringValue("property", "/null"), true); _prop = fgGetNode(props->getStringValue("property", "/null"), true);
_offset_deg = props->getDoubleValue("offset-deg", 0.0); _offset_deg = props->getDoubleValue("offset-deg", 0.0);
_factor = props->getDoubleValue("factor", 1.0); _factor = props->getDoubleValue("factor", 1.0);
@ -501,6 +551,7 @@ FGAircraftModel::TranslateAnimation::init (ssgEntity * object,
{ {
// Splice in the new transform node // Splice in the new transform node
splice_branch(_transform, object); splice_branch(_transform, object);
_transform->setName(props->getStringValue("name", 0));
_prop = fgGetNode(props->getStringValue("property", "/null"), true); _prop = fgGetNode(props->getStringValue("property", "/null"), true);
_offset_m = props->getDoubleValue("offset-m", 0.0); _offset_m = props->getDoubleValue("offset-m", 0.0);
_factor = props->getDoubleValue("factor", 1.0); _factor = props->getDoubleValue("factor", 1.0);
@ -533,7 +584,3 @@ FGAircraftModel::TranslateAnimation::update (int dt)
// end of model.cxx // end of model.cxx

View file

@ -98,6 +98,24 @@ private:
virtual ~NullAnimation (); virtual ~NullAnimation ();
virtual void init (ssgEntity * object, SGPropertyNode * props); virtual void init (ssgEntity * object, SGPropertyNode * props);
virtual void update (int dt); virtual void update (int dt);
private:
ssgBranch * _branch;
};
/**
* Animation to select alternative versions of the same object.
*/
class SelectAnimation : public Animation
{
public:
SelectAnimation ();
virtual ~SelectAnimation ();
virtual void init (ssgEntity * object, SGPropertyNode * props);
virtual void update (int dt);
private:
FGCondition * _condition;
ssgSelector * _selector;
}; };