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-23 23:42:36 +08:00
|
|
|
|
2002-01-19 03:00:55 +08:00
|
|
|
_matrix = new Matrix;
|
2001-12-16 00:56:39 +08:00
|
|
|
_matrix->makeIdentity();
|
2002-01-23 23:42:36 +08:00
|
|
|
_matrixDirty = false;
|
|
|
|
|
|
|
|
_inverse = new Matrix;
|
|
|
|
_inverse->makeIdentity();
|
|
|
|
_inverseDirty = false;
|
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-23 23:42:36 +08:00
|
|
|
|
2002-01-19 03:00:55 +08:00
|
|
|
_matrix = new Matrix(mat);
|
2002-01-23 23:42:36 +08:00
|
|
|
_matrixDirty = false;
|
|
|
|
|
|
|
|
_inverseDirty = true; // will neeed to recompute.
|
2001-09-20 05:19:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Transform::~Transform()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
const bool Transform::computeBound() const
|
|
|
|
{
|
|
|
|
if (!Group::computeBound()) return false;
|
|
|
|
|
2002-01-23 23:42:36 +08:00
|
|
|
if (_matrixDirty) computeMatrix();
|
|
|
|
|
2001-09-20 05:19:47 +08:00
|
|
|
Vec3 xdash = _bsphere._center;
|
|
|
|
xdash.x() += _bsphere._radius;
|
|
|
|
xdash = xdash*(*_matrix);
|
|
|
|
|
|
|
|
Vec3 ydash = _bsphere._center;
|
|
|
|
ydash.y() += _bsphere._radius;
|
|
|
|
ydash = ydash*(*_matrix);
|
|
|
|
|
|
|
|
Vec3 zdash = _bsphere._center;
|
|
|
|
zdash.y() += _bsphere._radius;
|
|
|
|
zdash = zdash*(*_matrix);
|
|
|
|
|
|
|
|
_bsphere._center = _bsphere._center*(*_matrix);
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|