Added beginings of new AutoTransform class.

This commit is contained in:
Robert Osfield
2002-02-03 20:57:31 +00:00
parent 6630cfb455
commit 57fb5a0182
2 changed files with 108 additions and 0 deletions

83
include/osg/AutoTransform Normal file
View File

@@ -0,0 +1,83 @@
//C++ header - Open Scene Graph - Copyright (C) 1998-2001 Robert Osfield
//Distributed under the terms of the GNU Library General Public License (LGPL)
//as published by the Free Software Foundation.
#ifndef OSG_AUTOTRANSFORM
#define OSG_AUTOTRANSFORM 1
#include <osg/Group>
#include <osg/Matrix>
namespace osg {
/** AutoTransform - is group which all children
* are transformed by a matrix which is automatically
* calculated during the cull traversal. The routine to
* do the matrix transform is specified by the user allow
* them customize its behavior to their own requirements.
*/
class SG_EXPORT AutoTransform : public Group
{
public :
class CalcTransformCallback : public osg::Referenced
{
public:
/** Get the transformation matrix which moves from local coords to world coords.*/
virtual const Matrix getLocalToWorldMatrix(const osg::Matrix& modelview) const = 0;
/** Get the transformation matrix which moves from world coords to local coords.*/
virtual const Matrix getWorldToLocalMatrix(const osg::Matrix& modelview) const = 0;
protected:
virtual ~CalcTransformCallback() {}
};
AutoTransform();
/** Copy constructor using CopyOp to manage deep vs shallow copy.*/
AutoTransform(const AutoTransform&,const CopyOp& copyop=CopyOp::SHALLOW_COPY);
AutoTransform(const Matrix& matix);
META_Node(AutoTransform);
/** Get the transformation matrix which moves from local coords to world coords.*/
inline const Matrix getLocalToWorldMatrix(const osg::Matrix& modelview) const
{
if (_calcTransformCallback.valid())
return _calcTransformCallback->getLocalToWorldMatrix(modelview);
else return osg::Matrix::identity();
}
/** Get the transformation matrix which moves from world coords to local coords.*/
inline const Matrix getWorldToLocalMatrix(const osg::Matrix& modelview) const
{
if (_calcTransformCallback.valid())
return _calcTransformCallback->getLocalToWorldMatrix(modelview);
else return osg::Matrix::identity();
}
protected :
virtual ~AutoTransform();
/** Override's Group's computeBound.
* There is no need to override in subclasses from osg::AutoTransform since this computeBound() uses
* the underlying matrix (calling computeMatrix if required.) */
virtual const bool computeBound() const;
ref_ptr<CalcTransformCallback> _calcTransformCallback;
};
}
#endif

25
src/osg/AutoTransform.cpp Normal file
View File

@@ -0,0 +1,25 @@
#include <osg/AutoTransform>
using namespace osg;
AutoTransform::AutoTransform()
{
}
AutoTransform::AutoTransform(const AutoTransform& transform,const CopyOp& copyop):
Group(transform,copyop),
_calcTransformCallback(dynamic_cast<CalcTransformCallback*>(copyop(transform._calcTransformCallback.get())))
{
}
AutoTransform::~AutoTransform()
{
}
const bool AutoTransform::computeBound() const
{
// can't calc the bound of a automatically transform object,
// it position isn't know until cull time.
return false;
}