Removed osg::Transform::ComputeTransformCallback from osg::Transform.

Updated various dependant files to reimplemt callbacks as Transform subclasses.
This commit is contained in:
Robert Osfield 2003-12-09 14:07:44 +00:00
parent d76cef6f8e
commit 9780a7cbd6
10 changed files with 23 additions and 112 deletions

View File

@ -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 struct DrawableUpdateCallback : public osg::Drawable::UpdateCallback
{ {
virtual void update(osg::NodeVisitor*, osg::Drawable* drawable) virtual void update(osg::NodeVisitor*, osg::Drawable* drawable)
@ -121,7 +100,6 @@ class InsertCallbacksVisitor : public osg::NodeVisitor
virtual void apply(osg::Transform& node) virtual void apply(osg::Transform& node)
{ {
node.setComputeTransformCallback(new TransformCallback());
apply((osg::Node&)node); apply((osg::Node&)node);
} }
}; };

View File

@ -26,10 +26,11 @@ extern osg::Node *makeSky( void );
extern osg::Node *makeBase( void ); extern osg::Node *makeBase( void );
extern osg::Node *makeClouds( 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.*/ /** 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); osgUtil::CullVisitor* cv = dynamic_cast<osgUtil::CullVisitor*>(nv);
if (cv) if (cv)
@ -41,8 +42,10 @@ struct MoveEarthySkyWithEyePointCallback : public osg::Transform::ComputeTransfo
} }
/** Get the transformation matrix which moves from world coords to local coords.*/ /** 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); osgUtil::CullVisitor* cv = dynamic_cast<osgUtil::CullVisitor*>(nv);
if (cv) if (cv)
{ {
@ -67,7 +70,7 @@ osg::Group* createModel()
clearNode->setRequiresClear(false); // we've got base and sky to do it. 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. // 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 // 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, // 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. // this node or any other branch above this transform.
transform->setCullingActive(false); 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. // add the sky and base layer.
transform->addChild(makeSky()); // bin number -2 so drawn first. transform->addChild(makeSky()); // bin number -2 so drawn first.
transform->addChild(makeBase()); // bin number -1 so draw second. transform->addChild(makeBase()); // bin number -1 so draw second.

View File

@ -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.*/ /** 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); osgUtil::CullVisitor* cv = dynamic_cast<osgUtil::CullVisitor*>(nv);
if (cv) if (cv)
@ -211,7 +212,7 @@ struct MoveEarthySkyWithEyePointCallback : public osg::Transform::ComputeTransfo
} }
/** Get the transformation matrix which moves from world coords to local coords.*/ /** 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); osgUtil::CullVisitor* cv = dynamic_cast<osgUtil::CullVisitor*>(nv);
if (cv) if (cv)
@ -262,9 +263,8 @@ osg::Node* createSkyBox()
geode->addDrawable(drawable); geode->addDrawable(drawable);
osg::Transform* transform = new osg::Transform; osg::Transform* transform = new MoveEarthySkyWithEyePointTransform;
transform->setCullingActive(false); transform->setCullingActive(false);
transform->setComputeTransformCallback(new MoveEarthySkyWithEyePointCallback);
transform->addChild(geode); transform->addChild(geode);
osg::ClearNode* clearNode = new osg::ClearNode; osg::ClearNode* clearNode = new osg::ClearNode;

View File

@ -93,14 +93,7 @@ class SG_EXPORT Billboard : public Geode
virtual bool removeDrawable( Drawable *gset ); virtual bool removeDrawable( Drawable *gset );
bool computeMatrix(Matrix& modelview, const Vec3& eye_local, const Vec3& pos_local) const;
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;
protected: protected:

View File

@ -105,55 +105,6 @@ class SG_EXPORT Transform : public Group
ReferenceFrame getReferenceFrame() const { return _referenceFrame; } 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 virtual bool computeLocalToWorldMatrix(Matrix& matrix,NodeVisitor*) const
{ {
if (_referenceFrame==RELATIVE_TO_PARENTS) if (_referenceFrame==RELATIVE_TO_PARENTS)
@ -190,9 +141,6 @@ class SG_EXPORT Transform : public Group
* computeMatrix if required.) */ * computeMatrix if required.) */
virtual bool computeBound() const; virtual bool computeBound() const;
ref_ptr<ComputeTransformCallback> _computeTransformCallback;
ReferenceFrame _referenceFrame; ReferenceFrame _referenceFrame;
}; };

View File

@ -80,7 +80,7 @@ void CollectOccludersVisitor::apply(osg::Transform& node)
pushCurrentMask(); pushCurrentMask();
ref_ptr<osg::RefMatrix> matrix = createOrReuseMatrix(getModelViewMatrix()); ref_ptr<osg::RefMatrix> matrix = createOrReuseMatrix(getModelViewMatrix());
node.getLocalToWorldMatrix(*matrix,this); node.computeLocalToWorldMatrix(*matrix,this);
pushModelViewMatrix(matrix.get()); pushModelViewMatrix(matrix.get());
handle_cull_callbacks_and_traverse(node); handle_cull_callbacks_and_traverse(node);

View File

@ -38,11 +38,11 @@ class TransformVisitor : public NodeVisitor
{ {
if (_coordMode==LOCAL_TO_WORLD) if (_coordMode==LOCAL_TO_WORLD)
{ {
transform.getLocalToWorldMatrix(_matrix,this); transform.computeLocalToWorldMatrix(_matrix,this);
} }
else // worldToLocal else // worldToLocal
{ {
transform.getWorldToLocalMatrix(_matrix,this); transform.computeWorldToLocalMatrix(_matrix,this);
} }
} }
@ -95,12 +95,6 @@ Matrix osg::computeEyeToLocal(const Matrix& modelview,NodePath& nodePath)
Transform::Transform() Transform::Transform()
{ {
_referenceFrame = RELATIVE_TO_PARENTS; _referenceFrame = RELATIVE_TO_PARENTS;
@ -108,7 +102,6 @@ Transform::Transform()
Transform::Transform(const Transform& transform,const CopyOp& copyop): Transform::Transform(const Transform& transform,const CopyOp& copyop):
Group(transform,copyop), Group(transform,copyop),
_computeTransformCallback(transform._computeTransformCallback),
_referenceFrame(transform._referenceFrame) _referenceFrame(transform._referenceFrame)
{ {
} }
@ -136,7 +129,7 @@ bool Transform::computeBound() const
// to handle this case gracefully, normally this should not be a problem. // to handle this case gracefully, normally this should not be a problem.
Matrix l2w; Matrix l2w;
getLocalToWorldMatrix(l2w,NULL); computeLocalToWorldMatrix(l2w,NULL);
Vec3 xdash = _bsphere._center; Vec3 xdash = _bsphere._center;
xdash.x() += _bsphere._radius; xdash.x() += _bsphere._radius;

View File

@ -393,7 +393,7 @@ void CullVisitor::apply(Billboard& node)
RefMatrix* billboard_matrix = createOrReuseMatrix(modelview); RefMatrix* billboard_matrix = createOrReuseMatrix(modelview);
node.getMatrix(*billboard_matrix,eye_local,pos); node.computeMatrix(*billboard_matrix,eye_local,pos);
float d = distance(pos,modelview); float d = distance(pos,modelview);
@ -499,7 +499,7 @@ void CullVisitor::apply(Transform& node)
if (node_state) pushStateSet(node_state); if (node_state) pushStateSet(node_state);
ref_ptr<RefMatrix> matrix = createOrReuseMatrix(getModelViewMatrix()); ref_ptr<RefMatrix> matrix = createOrReuseMatrix(getModelViewMatrix());
node.getLocalToWorldMatrix(*matrix,this); node.computeLocalToWorldMatrix(*matrix,this);
pushModelViewMatrix(matrix.get()); pushModelViewMatrix(matrix.get());
handle_cull_callbacks_and_traverse(node); handle_cull_callbacks_and_traverse(node);

View File

@ -593,7 +593,7 @@ void IntersectVisitor::apply(Transform& node)
if (!enterNode(node)) return; if (!enterNode(node)) return;
osg::ref_ptr<RefMatrix> matrix = new RefMatrix; osg::ref_ptr<RefMatrix> matrix = new RefMatrix;
node.getLocalToWorldMatrix(*matrix,this); node.computeLocalToWorldMatrix(*matrix,this);
pushMatrix(*matrix); pushMatrix(*matrix);

View File

@ -525,11 +525,11 @@ class CollectLowestTransformsVisitor : public osg::NodeVisitor
else if (transform->getReferenceFrame()==osg::Transform::RELATIVE_TO_ABSOLUTE) _moreThanOneMatrixRequired=true; else if (transform->getReferenceFrame()==osg::Transform::RELATIVE_TO_ABSOLUTE) _moreThanOneMatrixRequired=true;
else else
{ {
if (_transformSet.empty()) transform->getLocalToWorldMatrix(_firstMatrix,0); if (_transformSet.empty()) transform->computeLocalToWorldMatrix(_firstMatrix,0);
else else
{ {
osg::Matrix matrix; osg::Matrix matrix;
transform->getLocalToWorldMatrix(_firstMatrix,0); transform->computeLocalToWorldMatrix(_firstMatrix,0);
if (_firstMatrix!=matrix) _moreThanOneMatrixRequired=true; if (_firstMatrix!=matrix) _moreThanOneMatrixRequired=true;
} }
} }
@ -1029,7 +1029,7 @@ void Optimizer::RemoveRedundantNodesVisitor::apply(osg::Transform& transform)
{ {
static osg::Matrix identity; static osg::Matrix identity;
osg::Matrix matrix; osg::Matrix matrix;
transform.getWorldToLocalMatrix(matrix,NULL); transform.computeWorldToLocalMatrix(matrix,NULL);
if (matrix==identity) if (matrix==identity)
{ {
_redundantNodeList.insert(&transform); _redundantNodeList.insert(&transform);