Removed the dual inheritance from the AnimationPathCallback, moving the

NodeVisitor implemention into the .cpp.

Small tweak to the lighpoint drawable implmenentation to improve the additive
blending and state resotoration.
This commit is contained in:
Robert Osfield
2003-01-03 21:42:02 +00:00
parent fe64942c54
commit 141f065b17
3 changed files with 57 additions and 69 deletions

View File

@@ -7,7 +7,7 @@
#include <osg/Matrix>
#include <osg/Quat>
#include <osg/NodeVisitor>
#include <osg/NodeCallback>
#include <map>
@@ -133,7 +133,7 @@ class SG_EXPORT AnimationPath : public virtual osg::Object
};
class SG_EXPORT AnimationPathCallback : public NodeCallback, public NodeVisitor
class SG_EXPORT AnimationPathCallback : public NodeCallback
{
public:
@@ -174,9 +174,6 @@ class SG_EXPORT AnimationPathCallback : public NodeCallback, public NodeVisitor
/** implements the callback*/
virtual void operator()(Node* node, NodeVisitor* nv);
virtual void apply(MatrixTransform& mt);
virtual void apply(PositionAttitudeTransform& pat);
public:

View File

@@ -70,6 +70,30 @@ bool AnimationPath::getInterpolatedControlPoint(double time,ControlPoint& contro
}
class AnimationPathCallbackVisitor : public NodeVisitor
{
public:
AnimationPathCallbackVisitor(const AnimationPath::ControlPoint& cp):
_cp(cp) {}
virtual void apply(MatrixTransform& mt)
{
Matrix matrix;
_cp.getMatrix(matrix);
mt.setMatrix(matrix);
}
virtual void apply(PositionAttitudeTransform& pat)
{
pat.setPosition(_cp._position);
pat.setAttitude(_cp._rotation);
}
AnimationPath::ControlPoint _cp;
};
void AnimationPathCallback::operator()(Node* node, NodeVisitor* nv)
{
if (_animationPath.valid() &&
@@ -81,30 +105,15 @@ void AnimationPathCallback::operator()(Node* node, NodeVisitor* nv)
_animationTime = ((time-_firstTime)-_timeOffset)*_timeMultiplier;
node->accept(*this);
AnimationPath::ControlPoint cp;
if (_animationPath->getInterpolatedControlPoint(_animationTime,cp))
{
AnimationPathCallbackVisitor apcv(cp);
node->accept(apcv);
}
}
// must call any nested node callbacks and continue subgraph traversal.
NodeCallback::traverse(node,nv);
}
void AnimationPathCallback::apply(MatrixTransform& mt)
{
Matrix matrix;
if (_animationPath->getMatrix(_animationTime,matrix))
{
mt.setMatrix(matrix);
}
}
void AnimationPathCallback::apply(PositionAttitudeTransform& pat)
{
AnimationPath::ControlPoint cp;
if (_animationPath->getInterpolatedControlPoint(_animationTime,cp))
{
pat.setPosition(cp._position);
pat.setAttitude(cp._rotation);
}
}

View File

@@ -102,7 +102,6 @@ void LightPointDrawable::drawImplementation(osg::State& state) const
const LightPointList& lpl = *sitr;
if (!lpl.empty())
{
//state.applyMode(GL_POINT_SMOOTH,pointsize!=1);
glPointSize(pointsize);
glInterleavedArrays(GL_C4UB_V3F,0,&lpl.front());
//state.setInterleavedArrays(GL_C4UB_V3F,0,&lpl.front());
@@ -111,9 +110,29 @@ void LightPointDrawable::drawImplementation(osg::State& state) const
}
state.applyMode(GL_BLEND,true);
state.applyAttribute(_blendOne.get());
state.applyAttribute(_depthOff.get());
state.applyAttribute(_blendOneMinusSrcAlpha.get());
for(pointsize=1,sitr=_sizedBlendedLightPointList.begin();
sitr!=_sizedBlendedLightPointList.end();
++sitr,++pointsize)
{
const LightPointList& lpl = *sitr;
if (!lpl.empty())
{
glPointSize(pointsize);
glInterleavedArrays(GL_C4UB_V3F,0,&lpl.front());
//state.setInterleavedArrays(GL_C4UB_V3F,0,&lpl.front());
glDrawArrays(GL_POINTS,0,lpl.size());
}
}
state.applyAttribute(_blendOne.get());
for(pointsize=1,sitr=_sizedAdditiveLightPointList.begin();
sitr!=_sizedAdditiveLightPointList.end();
++sitr,++pointsize)
@@ -130,51 +149,14 @@ void LightPointDrawable::drawImplementation(osg::State& state) const
}
}
state.applyAttribute(_blendOneMinusSrcAlpha.get());
for(pointsize=1,sitr=_sizedBlendedLightPointList.begin();
sitr!=_sizedBlendedLightPointList.end();
++sitr,++pointsize)
{
const LightPointList& lpl = *sitr;
if (!lpl.empty())
{
//state.applyMode(GL_POINT_SMOOTH,pointsize!=1);
glPointSize(pointsize);
glInterleavedArrays(GL_C4UB_V3F,0,&lpl.front());
//state.setInterleavedArrays(GL_C4UB_V3F,0,&lpl.front());
glDrawArrays(GL_POINTS,0,lpl.size());
}
}
// // switch on depth mask to do set up depth mask.
// state.applyAttribute(_depthOn.get());
//
// state.applyMode(GL_BLEND,false);
//
// state.applyAttribute(_colorMaskOff.get());
//
// for(pointsize=1,sitr=_sizedLightPointList.begin();
// sitr!=_sizedLightPointList.end();
// ++sitr,++pointsize)
// {
//
// const LightPointList& lpl = *sitr;
// if (!lpl.empty())
// {
// glPointSize(pointsize);
// glInterleavedArrays(GL_C4UB_V3F,0,&lpl.front());
// //state.setInterleavedArrays(GL_C4UB_V3F,0,&lpl.front());
// glDrawArrays(GL_POINTS,0,lpl.size());
// }
// }
glPointSize(1);
glHint(GL_POINT_SMOOTH_HINT,GL_FASTEST);
state.haveAppliedAttribute(osg::StateAttribute::POINT);
// restore the state afterwards.
state.apply();
}