From 57fb5a0182c3f29b89db318ab15c9b784c295fd9 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Sun, 3 Feb 2002 20:57:31 +0000 Subject: [PATCH] Added beginings of new AutoTransform class. --- include/osg/AutoTransform | 83 +++++++++++++++++++++++++++++++++++++++ src/osg/AutoTransform.cpp | 25 ++++++++++++ 2 files changed, 108 insertions(+) create mode 100644 include/osg/AutoTransform create mode 100644 src/osg/AutoTransform.cpp diff --git a/include/osg/AutoTransform b/include/osg/AutoTransform new file mode 100644 index 000000000..c1de6f29a --- /dev/null +++ b/include/osg/AutoTransform @@ -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 +#include + +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; +}; + +} + +#endif diff --git a/src/osg/AutoTransform.cpp b/src/osg/AutoTransform.cpp new file mode 100644 index 000000000..838828092 --- /dev/null +++ b/src/osg/AutoTransform.cpp @@ -0,0 +1,25 @@ +#include + +using namespace osg; + +AutoTransform::AutoTransform() +{ +} + +AutoTransform::AutoTransform(const AutoTransform& transform,const CopyOp& copyop): + Group(transform,copyop), + _calcTransformCallback(dynamic_cast(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; +}