2001-10-22 05:27:40 +08:00
|
|
|
#include <osg/Transform>
|
2001-09-20 05:19:47 +08:00
|
|
|
|
|
|
|
using namespace osg;
|
|
|
|
|
|
|
|
Transform::Transform()
|
|
|
|
{
|
2001-10-11 04:20:14 +08:00
|
|
|
_type = DYNAMIC;
|
2002-01-24 06:15:39 +08:00
|
|
|
_mode = MODEL;
|
2002-01-23 23:42:36 +08:00
|
|
|
|
2002-01-24 06:15:39 +08:00
|
|
|
_localToWorld = new Matrix;
|
|
|
|
_localToWorld->makeIdentity();
|
|
|
|
_localToWorldDirty = false;
|
|
|
|
|
|
|
|
_worldToLocal = new Matrix;
|
|
|
|
_worldToLocal->makeIdentity();
|
|
|
|
_worldToLocalDirty = false;
|
2001-09-20 05:19:47 +08:00
|
|
|
}
|
|
|
|
|
Added support for shallow and deep copy of nodes, drawables and state, via a
copy constructor which takes an optional Cloner object, and the old
osg::Object::clone() has changed so that it now requires a Cloner as paramter.
This is passed on to the copy constructor to help control the shallow vs
deep copying. The old functionality of clone() which was clone of type has
been renamed to cloneType().
Updated all of the OSG to work with these new conventions, implemention all
the required copy constructors etc. A couple of areas will do shallow
copies by design, a couple of other still need to be updated to do either
shallow or deep.
Neither of the shallow or deep copy operations have been tested yet, only
the old functionality of the OSG has been checked so far, such running the
viewer on various demo datasets.
Also fixed a problem in osg::Optimize::RemoveRendundentNodesVisitor which
was not checking that Group didn't have have any attached StateSet's, Callbacks
or UserData. These checks have now been added, which fixes a bug which was
revealled by the new osgscribe demo, this related to removal of group acting
as state decorator.
method
2002-01-29 05:17:01 +08:00
|
|
|
Transform::Transform(const Transform& transform,const Cloner& cloner):
|
|
|
|
Group(transform,cloner),
|
|
|
|
_type(transform._type),
|
|
|
|
_mode(transform._mode),
|
|
|
|
_localToWorldDirty(transform._localToWorldDirty),
|
|
|
|
_localToWorld(transform._localToWorld),
|
|
|
|
_worldToLocalDirty(transform._worldToLocalDirty),
|
|
|
|
_worldToLocal(transform._localToWorld)
|
|
|
|
{
|
|
|
|
}
|
2001-09-20 05:19:47 +08:00
|
|
|
|
|
|
|
Transform::Transform(const Matrix& mat )
|
|
|
|
{
|
2001-10-11 04:20:14 +08:00
|
|
|
_type = DYNAMIC;
|
2002-01-24 06:15:39 +08:00
|
|
|
_mode = MODEL;
|
2002-01-23 23:42:36 +08:00
|
|
|
|
2002-01-24 06:15:39 +08:00
|
|
|
_localToWorld = new Matrix(mat);
|
|
|
|
_localToWorldDirty = false;
|
2002-01-23 23:42:36 +08:00
|
|
|
|
2002-01-24 06:15:39 +08:00
|
|
|
_worldToLocal = new Matrix;
|
|
|
|
_worldToLocalDirty = true;
|
2001-09-20 05:19:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Transform::~Transform()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2002-01-24 06:15:39 +08:00
|
|
|
void Transform::setMatrix(const Matrix& mat )
|
|
|
|
{
|
|
|
|
if (_mode==MODEL)
|
|
|
|
{
|
|
|
|
(*_localToWorld) = mat;
|
|
|
|
_localToWorldDirty = false;
|
|
|
|
_worldToLocalDirty = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
(*_worldToLocal) = mat;
|
|
|
|
_worldToLocalDirty = false;
|
|
|
|
_localToWorldDirty = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
dirtyBound();
|
|
|
|
}
|
|
|
|
|
|
|
|
/** preMult transform.*/
|
|
|
|
void Transform::preMult( const Matrix& mat )
|
|
|
|
{
|
|
|
|
if (_mode==MODEL)
|
|
|
|
{
|
|
|
|
_localToWorld->preMult(mat);
|
|
|
|
_localToWorldDirty = false;
|
|
|
|
_worldToLocalDirty = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_worldToLocal->preMult(mat);
|
|
|
|
_worldToLocalDirty = false;
|
|
|
|
_localToWorldDirty = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
dirtyBound();
|
|
|
|
}
|
|
|
|
|
|
|
|
/** postMult transform.*/
|
|
|
|
void Transform::postMult( const Matrix& mat )
|
|
|
|
{
|
|
|
|
if (_mode==MODEL)
|
|
|
|
{
|
|
|
|
_localToWorld->postMult(mat);
|
|
|
|
_localToWorldDirty = false;
|
|
|
|
_worldToLocalDirty = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_worldToLocal->postMult(mat);
|
|
|
|
_worldToLocalDirty = false;
|
|
|
|
_localToWorldDirty = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
dirtyBound();
|
|
|
|
}
|
|
|
|
|
2001-09-20 05:19:47 +08:00
|
|
|
const bool Transform::computeBound() const
|
|
|
|
{
|
|
|
|
if (!Group::computeBound()) return false;
|
|
|
|
|
2002-01-24 06:15:39 +08:00
|
|
|
if (_localToWorldDirty) computeLocalToWorld();
|
2002-01-23 23:42:36 +08:00
|
|
|
|
2001-09-20 05:19:47 +08:00
|
|
|
Vec3 xdash = _bsphere._center;
|
|
|
|
xdash.x() += _bsphere._radius;
|
2002-01-24 06:15:39 +08:00
|
|
|
xdash = xdash*(*_localToWorld);
|
2001-09-20 05:19:47 +08:00
|
|
|
|
|
|
|
Vec3 ydash = _bsphere._center;
|
|
|
|
ydash.y() += _bsphere._radius;
|
2002-01-24 06:15:39 +08:00
|
|
|
ydash = ydash*(*_localToWorld);
|
2001-09-20 05:19:47 +08:00
|
|
|
|
|
|
|
Vec3 zdash = _bsphere._center;
|
|
|
|
zdash.y() += _bsphere._radius;
|
2002-01-24 06:15:39 +08:00
|
|
|
zdash = zdash*(*_localToWorld);
|
2001-09-20 05:19:47 +08:00
|
|
|
|
2002-01-24 06:15:39 +08:00
|
|
|
_bsphere._center = _bsphere._center*(*_localToWorld);
|
2001-09-20 05:19:47 +08:00
|
|
|
|
|
|
|
xdash -= _bsphere._center;
|
|
|
|
float len_xdash = xdash.length();
|
|
|
|
|
|
|
|
ydash -= _bsphere._center;
|
|
|
|
float len_ydash = ydash.length();
|
|
|
|
|
|
|
|
zdash -= _bsphere._center;
|
|
|
|
float len_zdash = zdash.length();
|
|
|
|
|
|
|
|
_bsphere._radius = len_xdash;
|
|
|
|
if (_bsphere._radius<len_ydash) _bsphere._radius = len_ydash;
|
|
|
|
if (_bsphere._radius<len_zdash) _bsphere._radius = len_zdash;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2002-01-24 06:15:39 +08:00
|
|
|
|
|
|
|
void Transform::computeLocalToWorld() const
|
|
|
|
{
|
|
|
|
if (_localToWorldDirty)
|
|
|
|
{
|
|
|
|
if (_mode==VIEW)
|
|
|
|
{
|
|
|
|
_localToWorld->invert(*_worldToLocal);
|
|
|
|
}
|
|
|
|
_localToWorldDirty = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Transform::computeWorldToLocal() const
|
|
|
|
{
|
|
|
|
if (_worldToLocalDirty)
|
|
|
|
{
|
|
|
|
if (_mode==MODEL)
|
|
|
|
{
|
|
|
|
_worldToLocal->invert(*_localToWorld);
|
|
|
|
}
|
|
|
|
_worldToLocalDirty = false;
|
|
|
|
}
|
|
|
|
}
|