Added DataVariance enum and set/get fields to osg::Object to help identify

which objects have values that vary over the lifetime of the object (DYNAMIC)
and ones that do not vary (STATIC).  Removed the equivalent code in
osg::Transform, StateSet and StateAttribute, as these are now encompassed
by the new DataVariance field.

Removed MatrixMode enum from Matrix, and associated fields/parameters from
osg::Transfrom and osg::NodeVisitor, since MatrixMode was not providing
any useful functionality, but made the interface more complex (MatrixMode
was an experimental API)

Added ReferenceFrame field to osg::Transform which allows users to specify
transforms that are relative to their parents (the default, and previous behavior)
or absolute reference frame, which can be used for HUD's, camera relative
light sources etc etc.  Note, the view frustum culling for absolute Transform
are disabled, and all their parents up to the root are also automatically
have view frustum culling disabled.  However, once passed an absolute Transform
node culling will return to its default state of on, so you can still cull
underneath an absolute transform, its only the culling above which is disabled.
This commit is contained in:
Robert Osfield
2002-04-11 23:20:23 +00:00
parent e85e5a6ce6
commit 6ed233d0d2
18 changed files with 202 additions and 175 deletions

View File

@@ -4,8 +4,7 @@ using namespace osg;
Transform::Transform()
{
_type = DYNAMIC;
_mode = MODEL;
_referenceFrame = RELATIVE_TO_PARENTS;
_matrix = osgNew Matrix;
_inverse = osgNew Matrix;
@@ -14,9 +13,8 @@ Transform::Transform()
Transform::Transform(const Transform& transform,const CopyOp& copyop):
Group(transform,copyop),
_type(transform._type),
_mode(transform._mode),
_computeTransformCallback(_computeTransformCallback),
_referenceFrame(transform._referenceFrame),
_matrix(osgNew Matrix(*transform._matrix)),
_inverse(osgNew Matrix(*transform._inverse)),
_inverseDirty(transform._inverseDirty)
@@ -25,8 +23,7 @@ Transform::Transform(const Transform& transform,const CopyOp& copyop):
Transform::Transform(const Matrix& mat )
{
_type = DYNAMIC;
_mode = MODEL;
_referenceFrame = RELATIVE_TO_PARENTS;
_matrix = osgNew Matrix(mat);
_inverse = osgNew Matrix();
@@ -38,6 +35,17 @@ Transform::~Transform()
{
}
void Transform::setReferenceFrame(ReferenceFrame rf)
{
if (_referenceFrame == rf) return;
_referenceFrame = rf;
// switch off culling if transform is absolute.
if (_referenceFrame==ABSOLUTE) setCullingActive(false);
else setCullingActive(true);
}
const bool Transform::computeBound() const
{
if (!Group::computeBound()) return false;
@@ -45,41 +53,36 @@ const bool Transform::computeBound() const
// note, NULL pointer for NodeVisitor, so compute's need
// to handle this case gracefully, normally this should not be a problem.
Matrix l2w;
if (_mode!=PROJECTION && getLocalToWorldMatrix(l2w,NULL))
{
Vec3 xdash = _bsphere._center;
xdash.x() += _bsphere._radius;
xdash = xdash*l2w;
getLocalToWorldMatrix(l2w,NULL);
Vec3 ydash = _bsphere._center;
ydash.y() += _bsphere._radius;
ydash = ydash*l2w;
Vec3 xdash = _bsphere._center;
xdash.x() += _bsphere._radius;
xdash = xdash*l2w;
Vec3 zdash = _bsphere._center;
zdash.y() += _bsphere._radius;
zdash = zdash*l2w;
Vec3 ydash = _bsphere._center;
ydash.y() += _bsphere._radius;
ydash = ydash*l2w;
_bsphere._center = _bsphere._center*l2w;
Vec3 zdash = _bsphere._center;
zdash.y() += _bsphere._radius;
zdash = zdash*l2w;
xdash -= _bsphere._center;
float len_xdash = xdash.length();
_bsphere._center = _bsphere._center*l2w;
ydash -= _bsphere._center;
float len_ydash = ydash.length();
xdash -= _bsphere._center;
float len_xdash = xdash.length();
zdash -= _bsphere._center;
float len_zdash = zdash.length();
ydash -= _bsphere._center;
float len_ydash = ydash.length();
_bsphere._radius = len_xdash;
if (_bsphere._radius<len_ydash) _bsphere._radius = len_ydash;
if (_bsphere._radius<len_zdash) _bsphere._radius = len_zdash;
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;
return true;
}
else
{
_bsphere.init();
return false;
}
}