Removed osg::Transform::ComputeTransformCallback from osg::Transform.
Updated various dependant files to reimplemt callbacks as Transform subclasses.
This commit is contained in:
parent
d76cef6f8e
commit
9780a7cbd6
@ -46,27 +46,6 @@ class DrawableDrawCallback : public osg::Drawable::DrawCallback
|
||||
}
|
||||
};
|
||||
|
||||
struct TransformCallback : public osg::Transform::ComputeTransformCallback
|
||||
{
|
||||
/** Get the transformation matrix which moves from local coords to world coords.*/
|
||||
virtual bool computeLocalToWorldMatrix(osg::Matrix& matrix,const osg::Transform* transform, osg::NodeVisitor* nv) const
|
||||
{
|
||||
std::cout<<"computeLocalToWorldMatrix - pre transform->computeLocalToWorldMatrix"<<std::endl;
|
||||
bool result = transform->computeLocalToWorldMatrix(matrix,nv);
|
||||
std::cout<<"computeLocalToWorldMatrix - post transform->computeLocalToWorldMatrix"<<std::endl;
|
||||
return result;
|
||||
}
|
||||
|
||||
/** Get the transformation matrix which moves from world coords to local coords.*/
|
||||
virtual bool computeWorldToLocalMatrix(osg::Matrix& matrix,const osg::Transform* transform, osg::NodeVisitor* nv) const
|
||||
{
|
||||
std::cout<<"computeWorldToLocalMatrix - pre transform->computeWorldToLocalMatrix"<<std::endl;
|
||||
bool result = transform->computeWorldToLocalMatrix(matrix,nv);
|
||||
std::cout<<"computeWorldToLocalMatrix - post transform->computeWorldToLocalMatrix"<<std::endl;
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
struct DrawableUpdateCallback : public osg::Drawable::UpdateCallback
|
||||
{
|
||||
virtual void update(osg::NodeVisitor*, osg::Drawable* drawable)
|
||||
@ -121,7 +100,6 @@ class InsertCallbacksVisitor : public osg::NodeVisitor
|
||||
|
||||
virtual void apply(osg::Transform& node)
|
||||
{
|
||||
node.setComputeTransformCallback(new TransformCallback());
|
||||
apply((osg::Node&)node);
|
||||
}
|
||||
};
|
||||
|
@ -26,10 +26,11 @@ extern osg::Node *makeSky( void );
|
||||
extern osg::Node *makeBase( void );
|
||||
extern osg::Node *makeClouds( void );
|
||||
|
||||
struct MoveEarthySkyWithEyePointCallback : public osg::Transform::ComputeTransformCallback
|
||||
class MoveEarthySkyWithEyePointTransform : public osg::Transform
|
||||
{
|
||||
public:
|
||||
/** Get the transformation matrix which moves from local coords to world coords.*/
|
||||
virtual bool computeLocalToWorldMatrix(osg::Matrix& matrix,const osg::Transform*, osg::NodeVisitor* nv) const
|
||||
virtual bool computeLocalToWorldMatrix(osg::Matrix& matrix,osg::NodeVisitor* nv) const
|
||||
{
|
||||
osgUtil::CullVisitor* cv = dynamic_cast<osgUtil::CullVisitor*>(nv);
|
||||
if (cv)
|
||||
@ -41,8 +42,10 @@ struct MoveEarthySkyWithEyePointCallback : public osg::Transform::ComputeTransfo
|
||||
}
|
||||
|
||||
/** Get the transformation matrix which moves from world coords to local coords.*/
|
||||
virtual bool computeWorldToLocalMatrix(osg::Matrix& matrix,const osg::Transform*, osg::NodeVisitor* nv) const
|
||||
virtual bool computeWorldToLocalMatrix(osg::Matrix& matrix,osg::NodeVisitor* nv) const
|
||||
{
|
||||
std::cout<<"computing transform"<<std::endl;
|
||||
|
||||
osgUtil::CullVisitor* cv = dynamic_cast<osgUtil::CullVisitor*>(nv);
|
||||
if (cv)
|
||||
{
|
||||
@ -67,7 +70,7 @@ osg::Group* createModel()
|
||||
clearNode->setRequiresClear(false); // we've got base and sky to do it.
|
||||
|
||||
// use a transform to make the sky and base around with the eye point.
|
||||
osg::Transform* transform = new osg::Transform;
|
||||
osg::Transform* transform = new MoveEarthySkyWithEyePointTransform;
|
||||
|
||||
// transform's value isn't knowm until in the cull traversal so its bounding
|
||||
// volume is can't be determined, therefore culling will be invalid,
|
||||
@ -76,10 +79,6 @@ osg::Group* createModel()
|
||||
// this node or any other branch above this transform.
|
||||
transform->setCullingActive(false);
|
||||
|
||||
// set the compute transform callback to do all the work of
|
||||
// determining the transform according to the current eye point.
|
||||
transform->setComputeTransformCallback(new MoveEarthySkyWithEyePointCallback);
|
||||
|
||||
// add the sky and base layer.
|
||||
transform->addChild(makeSky()); // bin number -2 so drawn first.
|
||||
transform->addChild(makeBase()); // bin number -1 so draw second.
|
||||
|
@ -196,10 +196,11 @@ public:
|
||||
};
|
||||
|
||||
|
||||
struct MoveEarthySkyWithEyePointCallback : public osg::Transform::ComputeTransformCallback
|
||||
class MoveEarthySkyWithEyePointTransform : public osg::Transform
|
||||
{
|
||||
public:
|
||||
/** Get the transformation matrix which moves from local coords to world coords.*/
|
||||
virtual bool computeLocalToWorldMatrix(osg::Matrix& matrix,const osg::Transform*, osg::NodeVisitor* nv) const
|
||||
virtual bool computeLocalToWorldMatrix(osg::Matrix& matrix,osg::NodeVisitor* nv) const
|
||||
{
|
||||
osgUtil::CullVisitor* cv = dynamic_cast<osgUtil::CullVisitor*>(nv);
|
||||
if (cv)
|
||||
@ -211,7 +212,7 @@ struct MoveEarthySkyWithEyePointCallback : public osg::Transform::ComputeTransfo
|
||||
}
|
||||
|
||||
/** Get the transformation matrix which moves from world coords to local coords.*/
|
||||
virtual bool computeWorldToLocalMatrix(osg::Matrix& matrix,const osg::Transform*, osg::NodeVisitor* nv) const
|
||||
virtual bool computeWorldToLocalMatrix(osg::Matrix& matrix,osg::NodeVisitor* nv) const
|
||||
{
|
||||
osgUtil::CullVisitor* cv = dynamic_cast<osgUtil::CullVisitor*>(nv);
|
||||
if (cv)
|
||||
@ -262,9 +263,8 @@ osg::Node* createSkyBox()
|
||||
geode->addDrawable(drawable);
|
||||
|
||||
|
||||
osg::Transform* transform = new osg::Transform;
|
||||
osg::Transform* transform = new MoveEarthySkyWithEyePointTransform;
|
||||
transform->setCullingActive(false);
|
||||
transform->setComputeTransformCallback(new MoveEarthySkyWithEyePointCallback);
|
||||
transform->addChild(geode);
|
||||
|
||||
osg::ClearNode* clearNode = new osg::ClearNode;
|
||||
|
@ -93,14 +93,7 @@ class SG_EXPORT Billboard : public Geode
|
||||
virtual bool removeDrawable( Drawable *gset );
|
||||
|
||||
|
||||
|
||||
|
||||
inline bool getMatrix(Matrix& modelview, const Vec3& eye_local, const Vec3& pos_local) const
|
||||
{
|
||||
return computeMatrix(modelview,eye_local,pos_local);
|
||||
}
|
||||
|
||||
virtual bool computeMatrix(Matrix& modelview, const Vec3& eye_local, const Vec3& pos_local) const;
|
||||
bool computeMatrix(Matrix& modelview, const Vec3& eye_local, const Vec3& pos_local) const;
|
||||
|
||||
protected:
|
||||
|
||||
|
@ -105,55 +105,6 @@ class SG_EXPORT Transform : public Group
|
||||
|
||||
ReferenceFrame getReferenceFrame() const { return _referenceFrame; }
|
||||
|
||||
|
||||
/** Callback attached to an Transform to specify how to compute the
|
||||
* modelview transformation for the transform below the Transform
|
||||
* node. */
|
||||
struct ComputeTransformCallback : public virtual osg::Referenced
|
||||
{
|
||||
/** Get the transformation matrix which moves from local coords
|
||||
* to world coords.*/
|
||||
virtual bool computeLocalToWorldMatrix(Matrix& matrix,const Transform* transform, NodeVisitor* nv) const = 0;
|
||||
|
||||
/** Get the transformation matrix which moves from world coords
|
||||
* to local coords.*/
|
||||
virtual bool computeWorldToLocalMatrix(Matrix& matrix,const Transform* transform, NodeVisitor* nv) const = 0;
|
||||
};
|
||||
|
||||
/** Set the ComputerTransfromCallback which allows users to attach
|
||||
* custom computation of the local transformation as seen by cull
|
||||
* traversers and the like. */
|
||||
void setComputeTransformCallback(ComputeTransformCallback* ctc) { _computeTransformCallback=ctc; dirtyBound(); }
|
||||
|
||||
/** Get the non const ComputerTransfromCallback.*/
|
||||
ComputeTransformCallback* getComputeTransformCallback() { return _computeTransformCallback.get(); }
|
||||
|
||||
/** Get the const ComputerTransfromCallback.*/
|
||||
const ComputeTransformCallback* getComputeTransformCallback() const { return _computeTransformCallback.get(); }
|
||||
|
||||
|
||||
/** Get the transformation matrix which moves from local coords to
|
||||
* world coords.
|
||||
* Returns true if the Matrix passed in has been updated. */
|
||||
inline bool getLocalToWorldMatrix(Matrix& matrix,NodeVisitor* nv) const
|
||||
{
|
||||
if (_computeTransformCallback.valid())
|
||||
return _computeTransformCallback->computeLocalToWorldMatrix(matrix,this,nv);
|
||||
else
|
||||
return computeLocalToWorldMatrix(matrix,nv);
|
||||
}
|
||||
|
||||
/** Get the transformation matrix which moves from world coords to
|
||||
* local coords.
|
||||
* Return true if the Matrix passed in has been updated. */
|
||||
inline bool getWorldToLocalMatrix(Matrix& matrix,NodeVisitor* nv) const
|
||||
{
|
||||
if (_computeTransformCallback.valid())
|
||||
return _computeTransformCallback->computeWorldToLocalMatrix(matrix,this,nv);
|
||||
else
|
||||
return computeWorldToLocalMatrix(matrix,nv);
|
||||
}
|
||||
|
||||
virtual bool computeLocalToWorldMatrix(Matrix& matrix,NodeVisitor*) const
|
||||
{
|
||||
if (_referenceFrame==RELATIVE_TO_PARENTS)
|
||||
@ -190,9 +141,6 @@ class SG_EXPORT Transform : public Group
|
||||
* computeMatrix if required.) */
|
||||
virtual bool computeBound() const;
|
||||
|
||||
|
||||
ref_ptr<ComputeTransformCallback> _computeTransformCallback;
|
||||
|
||||
ReferenceFrame _referenceFrame;
|
||||
|
||||
};
|
||||
|
@ -80,7 +80,7 @@ void CollectOccludersVisitor::apply(osg::Transform& node)
|
||||
pushCurrentMask();
|
||||
|
||||
ref_ptr<osg::RefMatrix> matrix = createOrReuseMatrix(getModelViewMatrix());
|
||||
node.getLocalToWorldMatrix(*matrix,this);
|
||||
node.computeLocalToWorldMatrix(*matrix,this);
|
||||
pushModelViewMatrix(matrix.get());
|
||||
|
||||
handle_cull_callbacks_and_traverse(node);
|
||||
|
@ -38,11 +38,11 @@ class TransformVisitor : public NodeVisitor
|
||||
{
|
||||
if (_coordMode==LOCAL_TO_WORLD)
|
||||
{
|
||||
transform.getLocalToWorldMatrix(_matrix,this);
|
||||
transform.computeLocalToWorldMatrix(_matrix,this);
|
||||
}
|
||||
else // worldToLocal
|
||||
{
|
||||
transform.getWorldToLocalMatrix(_matrix,this);
|
||||
transform.computeWorldToLocalMatrix(_matrix,this);
|
||||
}
|
||||
}
|
||||
|
||||
@ -95,12 +95,6 @@ Matrix osg::computeEyeToLocal(const Matrix& modelview,NodePath& nodePath)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Transform::Transform()
|
||||
{
|
||||
_referenceFrame = RELATIVE_TO_PARENTS;
|
||||
@ -108,7 +102,6 @@ Transform::Transform()
|
||||
|
||||
Transform::Transform(const Transform& transform,const CopyOp& copyop):
|
||||
Group(transform,copyop),
|
||||
_computeTransformCallback(transform._computeTransformCallback),
|
||||
_referenceFrame(transform._referenceFrame)
|
||||
{
|
||||
}
|
||||
@ -136,7 +129,7 @@ bool Transform::computeBound() const
|
||||
// to handle this case gracefully, normally this should not be a problem.
|
||||
Matrix l2w;
|
||||
|
||||
getLocalToWorldMatrix(l2w,NULL);
|
||||
computeLocalToWorldMatrix(l2w,NULL);
|
||||
|
||||
Vec3 xdash = _bsphere._center;
|
||||
xdash.x() += _bsphere._radius;
|
||||
|
@ -393,7 +393,7 @@ void CullVisitor::apply(Billboard& node)
|
||||
|
||||
RefMatrix* billboard_matrix = createOrReuseMatrix(modelview);
|
||||
|
||||
node.getMatrix(*billboard_matrix,eye_local,pos);
|
||||
node.computeMatrix(*billboard_matrix,eye_local,pos);
|
||||
|
||||
|
||||
float d = distance(pos,modelview);
|
||||
@ -499,7 +499,7 @@ void CullVisitor::apply(Transform& node)
|
||||
if (node_state) pushStateSet(node_state);
|
||||
|
||||
ref_ptr<RefMatrix> matrix = createOrReuseMatrix(getModelViewMatrix());
|
||||
node.getLocalToWorldMatrix(*matrix,this);
|
||||
node.computeLocalToWorldMatrix(*matrix,this);
|
||||
pushModelViewMatrix(matrix.get());
|
||||
|
||||
handle_cull_callbacks_and_traverse(node);
|
||||
|
@ -593,7 +593,7 @@ void IntersectVisitor::apply(Transform& node)
|
||||
if (!enterNode(node)) return;
|
||||
|
||||
osg::ref_ptr<RefMatrix> matrix = new RefMatrix;
|
||||
node.getLocalToWorldMatrix(*matrix,this);
|
||||
node.computeLocalToWorldMatrix(*matrix,this);
|
||||
|
||||
pushMatrix(*matrix);
|
||||
|
||||
|
@ -525,11 +525,11 @@ class CollectLowestTransformsVisitor : public osg::NodeVisitor
|
||||
else if (transform->getReferenceFrame()==osg::Transform::RELATIVE_TO_ABSOLUTE) _moreThanOneMatrixRequired=true;
|
||||
else
|
||||
{
|
||||
if (_transformSet.empty()) transform->getLocalToWorldMatrix(_firstMatrix,0);
|
||||
if (_transformSet.empty()) transform->computeLocalToWorldMatrix(_firstMatrix,0);
|
||||
else
|
||||
{
|
||||
osg::Matrix matrix;
|
||||
transform->getLocalToWorldMatrix(_firstMatrix,0);
|
||||
transform->computeLocalToWorldMatrix(_firstMatrix,0);
|
||||
if (_firstMatrix!=matrix) _moreThanOneMatrixRequired=true;
|
||||
}
|
||||
}
|
||||
@ -1029,7 +1029,7 @@ void Optimizer::RemoveRedundantNodesVisitor::apply(osg::Transform& transform)
|
||||
{
|
||||
static osg::Matrix identity;
|
||||
osg::Matrix matrix;
|
||||
transform.getWorldToLocalMatrix(matrix,NULL);
|
||||
transform.computeWorldToLocalMatrix(matrix,NULL);
|
||||
if (matrix==identity)
|
||||
{
|
||||
_redundantNodeList.insert(&transform);
|
||||
|
Loading…
Reference in New Issue
Block a user