Allow adding a contition to locked-track animation

This commit is contained in:
Thomas Geymayer
2013-05-02 00:47:24 +02:00
parent 7c7109edf4
commit 2af78a3874
6 changed files with 89 additions and 25 deletions

View File

@@ -425,7 +425,7 @@ bool SGPath::isAbsolute() const
bool SGPath::isNull() const
{
return path.empty() || (path == "");
return path.empty();
}
std::string SGPath::str_native() const

View File

@@ -31,7 +31,7 @@ namespace nasal
naRef to_nasal_helper(naContext c, const std::string& str)
{
naRef ret = naNewString(c);
naStr_fromdata(ret, str.c_str(), str.size());
naStr_fromdata(ret, str.c_str(), static_cast<int>(str.size()));
return ret;
}

View File

@@ -85,7 +85,12 @@ class FindGroupVisitor:
if( !_group )
_group = &group;
else
SG_LOG(SG_IO, SG_WARN, "FindGroupVisitor: name not unique");
SG_LOG
(
SG_IO,
SG_WARN,
"FindGroupVisitor: name not unique '" << _name << "'"
);
}
protected:
@@ -122,7 +127,14 @@ class SGTrackToAnimation::UpdateCallback:
_slave_tf(slave_tf),
_root_length(0),
_slave_length(0),
_root_initial_angle(0)
_root_initial_angle(0),
_condition(anim->getCondition()),
_root_disabled_value(
anim->readOffsetValue("disabled-rotation-deg")
),
_slave_disabled_value(
anim->readOffsetValue("slave-disabled-rotation-deg")
)
{
setName("SGTrackToAnimation::UpdateCallback");
@@ -228,32 +240,49 @@ class SGTrackToAnimation::UpdateCallback:
).preMult(_target_center),
dir = target_pos - _node_center;
double offset = -_root_initial_angle;
if( _root_length > 0 )
{
double dist = dir.length(),
slave_angle = -_slave_initial_angle;
if( dist < _root_length + _slave_length )
{
offset += angleFromSSS(_root_length, dist, _slave_length);
double root_angle,
slave_angle;
if( _slave_tf )
slave_angle += angleFromSSS(_root_length, _slave_length, dist)
- SGMiscd::pi();
if( !_condition || _condition->test() )
{
root_angle = -_root_initial_angle;
slave_angle = -_slave_initial_angle;
if( _root_length > 0 )
{
double dist = dir.length();
if( dist < _root_length + _slave_length )
{
root_angle += angleFromSSS(_root_length, dist, _slave_length);
if( _slave_tf )
slave_angle += angleFromSSS(_root_length, _slave_length, dist)
- SGMiscd::pi();
}
}
if( _slave_tf )
_slave_tf->setAngleRad(slave_angle);
// Ensure direction is perpendicular to lock axis
float proj = _lock_axis * dir;
if( proj != 0.0 )
dir -= _lock_axis * proj;
float x = dir * _track_axis,
y = dir * _up_axis;
root_angle += std::atan2(y, x);
}
else
{
root_angle = _root_disabled_value
? SGMiscd::deg2rad(_root_disabled_value->getValue())
: 0;
slave_angle = _slave_disabled_value
? SGMiscd::deg2rad(_slave_disabled_value->getValue())
: 0;
}
// Ensure direction is perpendicular to lock axis
float proj = _lock_axis * dir;
if( proj != 0.0 )
dir -= _lock_axis * proj;
float x = dir * _track_axis,
y = dir * _up_axis;
tf->setAngleRad( std::atan2(y, x) + offset );
tf->setAngleRad( root_angle );
if( _slave_tf )
_slave_tf->setAngleRad(slave_angle);
traverse(node, nv);
}
@@ -273,6 +302,10 @@ class SGTrackToAnimation::UpdateCallback:
_slave_length,
_root_initial_angle,
_slave_initial_angle;
SGSharedPtr<SGCondition const> _condition;
SGExpressiond_ref _root_disabled_value,
_slave_disabled_value;
};
//------------------------------------------------------------------------------

View File

@@ -567,6 +567,30 @@ void SGAnimation::readRotationCenterAndAxis( SGVec3d& center,
center = readVec3("center", "-m", center);
}
//------------------------------------------------------------------------------
SGExpressiond* SGAnimation::readOffsetValue(const char* tag_name) const
{
const SGPropertyNode* node = _configNode->getChild(tag_name);
if( !node )
return 0;
SGExpressiond_ref expression;
if( !node->nChildren() )
expression = new SGConstExpression<double>(node->getDoubleValue());
else
expression = SGReadDoubleExpression(_modelRoot, node->getChild(0));
if( !expression )
return 0;
expression = expression->simplify();
if( expression->isConst() && expression->getValue() == 0 )
return 0;
return expression.release();
}
void
SGAnimation::removeMode(osg::Node& node, osg::StateAttribute::GLMode mode)
{

View File

@@ -73,6 +73,8 @@ protected:
const SGVec3d& def = SGVec3d::zeros() ) const;
void readRotationCenterAndAxis(SGVec3d& center, SGVec3d& axis) const;
SGExpressiond* readOffsetValue(const char* tag_name) const;
void removeMode(osg::Node& node, osg::StateAttribute::GLMode mode);
void removeAttribute(osg::Node& node, osg::StateAttribute::Type type);
void removeTextureMode(osg::Node& node, unsigned unit,

View File

@@ -900,6 +900,11 @@ typedef SGExpression<float> SGExpressionf;
typedef SGExpression<double> SGExpressiond;
typedef SGExpression<bool> SGExpressionb;
typedef SGSharedPtr<SGExpressioni> SGExpressioni_ref;
typedef SGSharedPtr<SGExpressionf> SGExpressionf_ref;
typedef SGSharedPtr<SGExpressiond> SGExpressiond_ref;
typedef SGSharedPtr<SGExpressionb> SGExpressionb_ref;
/**
* Global function to make an expression out of properties.