Converted AutoTransform to use doubles.

This commit is contained in:
Robert Osfield 2008-08-28 09:43:00 +00:00
parent 95a359bdab
commit c8ef144532
4 changed files with 204 additions and 93 deletions

View File

@ -42,26 +42,26 @@ class OSG_EXPORT AutoTransform : public Transform
virtual AutoTransform* asAutoTransform() { return this; } virtual AutoTransform* asAutoTransform() { return this; }
virtual const AutoTransform* asAutoTransform() const { return this; } virtual const AutoTransform* asAutoTransform() const { return this; }
inline void setPosition(const Vec3& pos) { _position = pos; _matrixDirty=true; dirtyBound(); } inline void setPosition(const Vec3d& pos) { _position = pos; _matrixDirty=true; dirtyBound(); }
inline const Vec3& getPosition() const { return _position; } inline const Vec3d& getPosition() const { return _position; }
inline void setRotation(const Quat& quat) { _rotation = quat; _matrixDirty=true; dirtyBound(); } inline void setRotation(const Quat& quat) { _rotation = quat; _matrixDirty=true; dirtyBound(); }
inline const Quat& getRotation() const { return _rotation; } inline const Quat& getRotation() const { return _rotation; }
inline void setScale(float scale) { setScale(osg::Vec3(scale,scale,scale)); } inline void setScale(double scale) { setScale(osg::Vec3(scale,scale,scale)); }
void setScale(const Vec3& scale); void setScale(const Vec3d& scale);
inline const Vec3& getScale() const { return _scale; } inline const Vec3d& getScale() const { return _scale; }
void setMinimumScale(float minimumScale) { _minimumScale = minimumScale; } void setMinimumScale(double minimumScale) { _minimumScale = minimumScale; }
float getMinimumScale() const { return _minimumScale; } double getMinimumScale() const { return _minimumScale; }
void setMaximumScale(float maximumScale) { _maximumScale = maximumScale; } void setMaximumScale(double maximumScale) { _maximumScale = maximumScale; }
float getMaximumScale() const { return _maximumScale; } double getMaximumScale() const { return _maximumScale; }
inline void setPivotPoint(const Vec3& pivot) { _pivotPoint = pivot; _matrixDirty=true; dirtyBound(); } inline void setPivotPoint(const Vec3d& pivot) { _pivotPoint = pivot; _matrixDirty=true; dirtyBound(); }
inline const Vec3& getPivotPoint() const { return _pivotPoint; } inline const Vec3d& getPivotPoint() const { return _pivotPoint; }
void setAutoUpdateEyeMovementTolerance(float tolerance) { _autoUpdateEyeMovementTolerance = tolerance; } void setAutoUpdateEyeMovementTolerance(float tolerance) { _autoUpdateEyeMovementTolerance = tolerance; }
@ -98,32 +98,32 @@ class OSG_EXPORT AutoTransform : public Transform
virtual ~AutoTransform() {} virtual ~AutoTransform() {}
Vec3 _position; Vec3d _position;
Vec3 _pivotPoint; Vec3d _pivotPoint;
float _autoUpdateEyeMovementTolerance; double _autoUpdateEyeMovementTolerance;
AutoRotateMode _autoRotateMode; AutoRotateMode _autoRotateMode;
bool _autoScaleToScreen; bool _autoScaleToScreen;
mutable Quat _rotation; mutable Quat _rotation;
mutable Vec3 _scale; mutable Vec3d _scale;
mutable bool _firstTimeToInitEyePoint; mutable bool _firstTimeToInitEyePoint;
mutable osg::Vec3 _previousEyePoint; mutable osg::Vec3 _previousEyePoint;
mutable osg::Vec3 _previousLocalUp; mutable osg::Vec3 _previousLocalUp;
mutable Viewport::value_type _previousWidth; mutable Viewport::value_type _previousWidth;
mutable Viewport::value_type _previousHeight; mutable Viewport::value_type _previousHeight;
mutable osg::Matrix _previousProjection; mutable osg::Matrixd _previousProjection;
mutable osg::Vec3 _previousPosition; mutable osg::Vec3d _previousPosition;
float _minimumScale; double _minimumScale;
float _maximumScale; double _maximumScale;
float _autoScaleTransitionWidthRatio; double _autoScaleTransitionWidthRatio;
void computeMatrix() const; void computeMatrix() const;
mutable bool _matrixDirty; mutable bool _matrixDirty;
mutable osg::Matrix _cachedMatrix; mutable osg::Matrixd _cachedMatrix;
}; };
} }

View File

@ -18,14 +18,14 @@
using namespace osg; using namespace osg;
AutoTransform::AutoTransform(): AutoTransform::AutoTransform():
_autoUpdateEyeMovementTolerance(0.0f), _autoUpdateEyeMovementTolerance(0.0),
_autoRotateMode(NO_ROTATION), _autoRotateMode(NO_ROTATION),
_autoScaleToScreen(false), _autoScaleToScreen(false),
_scale(1.0f,1.0f,1.0f), _scale(1.0,1.0,1.0),
_firstTimeToInitEyePoint(true), _firstTimeToInitEyePoint(true),
_minimumScale(0.0f), _minimumScale(0.0),
_maximumScale(FLT_MAX), _maximumScale(DBL_MAX),
_autoScaleTransitionWidthRatio(0.25f), _autoScaleTransitionWidthRatio(0.25),
_matrixDirty(true) _matrixDirty(true)
{ {
// setNumChildrenRequiringUpdateTraversal(1); // setNumChildrenRequiringUpdateTraversal(1);
@ -49,7 +49,7 @@ AutoTransform::AutoTransform(const AutoTransform& pat,const CopyOp& copyop):
// setNumChildrenRequiringUpdateTraversal(getNumChildrenRequiringUpdateTraversal()+1); // setNumChildrenRequiringUpdateTraversal(getNumChildrenRequiringUpdateTraversal()+1);
} }
void AutoTransform::setScale(const Vec3& scale) void AutoTransform::setScale(const Vec3d& scale)
{ {
_scale = scale; _scale = scale;
if (_scale.x()<_minimumScale) _scale.x() = _minimumScale; if (_scale.x()<_minimumScale) _scale.x() = _minimumScale;
@ -87,14 +87,14 @@ bool AutoTransform::computeWorldToLocalMatrix(Matrix& matrix,NodeVisitor*) const
{ {
matrix.postMult(osg::Matrix::translate(-_position)* matrix.postMult(osg::Matrix::translate(-_position)*
osg::Matrix::rotate(_rotation.inverse())* osg::Matrix::rotate(_rotation.inverse())*
osg::Matrix::scale(1.0f/_scale.x(),1.0f/_scale.y(),1.0f/_scale.z())* osg::Matrix::scale(1.0/_scale.x(),1.0/_scale.y(),1.0/_scale.z())*
osg::Matrix::translate(_pivotPoint)); osg::Matrix::translate(_pivotPoint));
} }
else // absolute else // absolute
{ {
matrix = osg::Matrix::translate(-_position)* matrix = osg::Matrix::translate(-_position)*
osg::Matrix::rotate(_rotation.inverse())* osg::Matrix::rotate(_rotation.inverse())*
osg::Matrix::scale(1.0f/_scale.x(),1.0f/_scale.y(),1.0f/_scale.z())* osg::Matrix::scale(1.0/_scale.x(),1.0/_scale.y(),1.0/_scale.z())*
osg::Matrix::translate(_pivotPoint); osg::Matrix::translate(_pivotPoint);
} }
return true; return true;
@ -138,21 +138,21 @@ void AutoTransform::accept(NodeVisitor& nv)
height = viewport->height(); height = viewport->height();
} }
osg::Vec3 eyePoint = cs->getEyeLocal(); osg::Vec3d eyePoint = cs->getEyeLocal();
osg::Vec3 localUp = cs->getUpLocal(); osg::Vec3d localUp = cs->getUpLocal();
osg::Vec3 position = getPosition(); osg::Vec3d position = getPosition();
const osg::Matrix& projection = *(cs->getProjectionMatrix()); const osg::Matrix& projection = *(cs->getProjectionMatrix());
bool doUpdate = _firstTimeToInitEyePoint; bool doUpdate = _firstTimeToInitEyePoint;
if (!_firstTimeToInitEyePoint) if (!_firstTimeToInitEyePoint)
{ {
osg::Vec3 dv = _previousEyePoint-eyePoint; osg::Vec3d dv = _previousEyePoint-eyePoint;
if (dv.length2()>getAutoUpdateEyeMovementTolerance()*(eyePoint-getPosition()).length2()) if (dv.length2()>getAutoUpdateEyeMovementTolerance()*(eyePoint-getPosition()).length2())
{ {
doUpdate = true; doUpdate = true;
} }
osg::Vec3 dupv = _previousLocalUp-localUp; osg::Vec3d dupv = _previousLocalUp-localUp;
// rotating the camera only affects ROTATE_TO_* // rotating the camera only affects ROTATE_TO_*
if (_autoRotateMode && if (_autoRotateMode &&
dupv.length2()>getAutoUpdateEyeMovementTolerance()) dupv.length2()>getAutoUpdateEyeMovementTolerance())
@ -179,35 +179,35 @@ void AutoTransform::accept(NodeVisitor& nv)
if (getAutoScaleToScreen()) if (getAutoScaleToScreen())
{ {
float size = 1.0f/cs->pixelSize(getPosition(),0.48f); double size = 1.0/cs->pixelSize(getPosition(),0.48);
if (_autoScaleTransitionWidthRatio>0.0f) if (_autoScaleTransitionWidthRatio>0.0)
{ {
if (_minimumScale>0.0f) if (_minimumScale>0.0)
{ {
float j = _minimumScale; double j = _minimumScale;
float i = (_maximumScale<FLT_MAX) ? double i = (_maximumScale<DBL_MAX) ?
_minimumScale+(_maximumScale-_minimumScale)*_autoScaleTransitionWidthRatio : _minimumScale+(_maximumScale-_minimumScale)*_autoScaleTransitionWidthRatio :
_minimumScale*(1.0f+_autoScaleTransitionWidthRatio); _minimumScale*(1.0+_autoScaleTransitionWidthRatio);
float c = 1.0f/(4.0f*(i-j)); double c = 1.0/(4.0*(i-j));
float b = 1.0f - 2.0f*c*i; double b = 1.0 - 2.0*c*i;
float a = j + b*b / (4.0f*c); double a = j + b*b / (4.0*c);
float k = -b / (2.0f*c); double k = -b / (2.0*c);
if (size<k) size = _minimumScale; if (size<k) size = _minimumScale;
else if (size<i) size = a + b*size + c*(size*size); else if (size<i) size = a + b*size + c*(size*size);
} }
if (_maximumScale<FLT_MAX) if (_maximumScale<DBL_MAX)
{ {
float n = _maximumScale; double n = _maximumScale;
float m = (_minimumScale>0.0) ? double m = (_minimumScale>0.0) ?
_maximumScale+(_minimumScale-_maximumScale)*_autoScaleTransitionWidthRatio : _maximumScale+(_minimumScale-_maximumScale)*_autoScaleTransitionWidthRatio :
_maximumScale*(1.0f-_autoScaleTransitionWidthRatio); _maximumScale*(1.0-_autoScaleTransitionWidthRatio);
float c = 1.0f / (4.0f*(m-n)); double c = 1.0 / (4.0*(m-n));
float b = 1.0f - 2.0f*c*m; double b = 1.0 - 2.0*c*m;
float a = n + b*b/(4.0f*c); double a = n + b*b/(4.0*c);
float p = -b / (2.0f*c); double p = -b / (2.0*c);
if (size>p) size = _maximumScale; if (size>p) size = _maximumScale;
else if (size>m) size = a + b*size + c*(size*size); else if (size>m) size = a + b*size + c*(size*size);
@ -230,9 +230,9 @@ void AutoTransform::accept(NodeVisitor& nv)
} }
else if (_autoRotateMode==ROTATE_TO_CAMERA) else if (_autoRotateMode==ROTATE_TO_CAMERA)
{ {
osg::Vec3 PosToEye = _position - eyePoint; osg::Vec3d PosToEye = _position - eyePoint;
osg::Matrix lookto = osg::Matrix::lookAt( osg::Matrix lookto = osg::Matrix::lookAt(
osg::Vec3(0,0,0), PosToEye, localUp); osg::Vec3d(0,0,0), PosToEye, localUp);
Quat q; Quat q;
q.set(osg::Matrix::inverse(lookto)); q.set(osg::Matrix::inverse(lookto));
setRotation(q); setRotation(q);

View File

@ -17,7 +17,7 @@
#include <osg/NodeVisitor> #include <osg/NodeVisitor>
#include <osg/Object> #include <osg/Object>
#include <osg/Quat> #include <osg/Quat>
#include <osg/Vec3> #include <osg/Vec3d>
// Must undefine IN and OUT macros defined in Windows headers // Must undefine IN and OUT macros defined in Windows headers
#ifdef IN #ifdef IN
@ -84,14 +84,14 @@ BEGIN_OBJECT_REFLECTOR(osg::AutoTransform)
__C5_AutoTransform_P1__asAutoTransform, __C5_AutoTransform_P1__asAutoTransform,
"", "",
""); "");
I_Method1(void, setPosition, IN, const osg::Vec3 &, pos, I_Method1(void, setPosition, IN, const osg::Vec3d &, pos,
Properties::NON_VIRTUAL, Properties::NON_VIRTUAL,
__void__setPosition__C5_Vec3_R1, __void__setPosition__C5_Vec3d_R1,
"", "",
""); "");
I_Method0(const osg::Vec3 &, getPosition, I_Method0(const osg::Vec3d &, getPosition,
Properties::NON_VIRTUAL, Properties::NON_VIRTUAL,
__C5_Vec3_R1__getPosition, __C5_Vec3d_R1__getPosition,
"", "",
""); "");
I_Method1(void, setRotation, IN, const osg::Quat &, quat, I_Method1(void, setRotation, IN, const osg::Quat &, quat,
@ -104,49 +104,49 @@ BEGIN_OBJECT_REFLECTOR(osg::AutoTransform)
__C5_Quat_R1__getRotation, __C5_Quat_R1__getRotation,
"", "",
""); "");
I_Method1(void, setScale, IN, float, scale, I_Method1(void, setScale, IN, double, scale,
Properties::NON_VIRTUAL, Properties::NON_VIRTUAL,
__void__setScale__float, __void__setScale__double,
"", "",
""); "");
I_Method1(void, setScale, IN, const osg::Vec3 &, scale, I_Method1(void, setScale, IN, const osg::Vec3d &, scale,
Properties::NON_VIRTUAL, Properties::NON_VIRTUAL,
__void__setScale__C5_Vec3_R1, __void__setScale__C5_Vec3d_R1,
"", "",
""); "");
I_Method0(const osg::Vec3 &, getScale, I_Method0(const osg::Vec3d &, getScale,
Properties::NON_VIRTUAL, Properties::NON_VIRTUAL,
__C5_Vec3_R1__getScale, __C5_Vec3d_R1__getScale,
"", "",
""); "");
I_Method1(void, setMinimumScale, IN, float, minimumScale, I_Method1(void, setMinimumScale, IN, double, minimumScale,
Properties::NON_VIRTUAL, Properties::NON_VIRTUAL,
__void__setMinimumScale__float, __void__setMinimumScale__double,
"", "",
""); "");
I_Method0(float, getMinimumScale, I_Method0(double, getMinimumScale,
Properties::NON_VIRTUAL, Properties::NON_VIRTUAL,
__float__getMinimumScale, __double__getMinimumScale,
"", "",
""); "");
I_Method1(void, setMaximumScale, IN, float, maximumScale, I_Method1(void, setMaximumScale, IN, double, maximumScale,
Properties::NON_VIRTUAL, Properties::NON_VIRTUAL,
__void__setMaximumScale__float, __void__setMaximumScale__double,
"", "",
""); "");
I_Method0(float, getMaximumScale, I_Method0(double, getMaximumScale,
Properties::NON_VIRTUAL, Properties::NON_VIRTUAL,
__float__getMaximumScale, __double__getMaximumScale,
"", "",
""); "");
I_Method1(void, setPivotPoint, IN, const osg::Vec3 &, pivot, I_Method1(void, setPivotPoint, IN, const osg::Vec3d &, pivot,
Properties::NON_VIRTUAL, Properties::NON_VIRTUAL,
__void__setPivotPoint__C5_Vec3_R1, __void__setPivotPoint__C5_Vec3d_R1,
"", "",
""); "");
I_Method0(const osg::Vec3 &, getPivotPoint, I_Method0(const osg::Vec3d &, getPivotPoint,
Properties::NON_VIRTUAL, Properties::NON_VIRTUAL,
__C5_Vec3_R1__getPivotPoint, __C5_Vec3d_R1__getPivotPoint,
"", "",
""); "");
I_Method1(void, setAutoUpdateEyeMovementTolerance, IN, float, tolerance, I_Method1(void, setAutoUpdateEyeMovementTolerance, IN, float, tolerance,
@ -222,23 +222,23 @@ BEGIN_OBJECT_REFLECTOR(osg::AutoTransform)
I_SimpleProperty(float, AutoUpdateEyeMovementTolerance, I_SimpleProperty(float, AutoUpdateEyeMovementTolerance,
__float__getAutoUpdateEyeMovementTolerance, __float__getAutoUpdateEyeMovementTolerance,
__void__setAutoUpdateEyeMovementTolerance__float); __void__setAutoUpdateEyeMovementTolerance__float);
I_SimpleProperty(float, MaximumScale, I_SimpleProperty(double, MaximumScale,
__float__getMaximumScale, __double__getMaximumScale,
__void__setMaximumScale__float); __void__setMaximumScale__double);
I_SimpleProperty(float, MinimumScale, I_SimpleProperty(double, MinimumScale,
__float__getMinimumScale, __double__getMinimumScale,
__void__setMinimumScale__float); __void__setMinimumScale__double);
I_SimpleProperty(const osg::Vec3 &, PivotPoint, I_SimpleProperty(const osg::Vec3d &, PivotPoint,
__C5_Vec3_R1__getPivotPoint, __C5_Vec3d_R1__getPivotPoint,
__void__setPivotPoint__C5_Vec3_R1); __void__setPivotPoint__C5_Vec3d_R1);
I_SimpleProperty(const osg::Vec3 &, Position, I_SimpleProperty(const osg::Vec3d &, Position,
__C5_Vec3_R1__getPosition, __C5_Vec3d_R1__getPosition,
__void__setPosition__C5_Vec3_R1); __void__setPosition__C5_Vec3d_R1);
I_SimpleProperty(const osg::Quat &, Rotation, I_SimpleProperty(const osg::Quat &, Rotation,
__C5_Quat_R1__getRotation, __C5_Quat_R1__getRotation,
__void__setRotation__C5_Quat_R1); __void__setRotation__C5_Quat_R1);
I_SimpleProperty(const osg::Vec3 &, Scale, I_SimpleProperty(const osg::Vec3d &, Scale,
__C5_Vec3_R1__getScale, __C5_Vec3d_R1__getScale,
__void__setScale__C5_Vec3_R1); __void__setScale__C5_Vec3d_R1);
END_REFLECTOR END_REFLECTOR

View File

@ -869,3 +869,114 @@ BEGIN_OBJECT_REFLECTOR(osgTerrain::ProxyLayer)
__void__setModifiedCount__unsigned_int); __void__setModifiedCount__unsigned_int);
END_REFLECTOR END_REFLECTOR
BEGIN_OBJECT_REFLECTOR(osgTerrain::SwitchLayer)
I_DeclaringFile("osgTerrain/Layer");
I_BaseType(osgTerrain::Layer);
I_Constructor0(____SwitchLayer,
"",
"");
I_ConstructorWithDefaults2(IN, const osgTerrain::SwitchLayer &, switchLayer, , IN, const osg::CopyOp &, copyop, osg::CopyOp::SHALLOW_COPY,
____SwitchLayer__C5_SwitchLayer_R1__C5_osg_CopyOp_R1,
"Copy constructor using CopyOp to manage deep vs shallow copy. ",
"");
I_Method0(osg::Object *, cloneType,
Properties::VIRTUAL,
__osg_Object_P1__cloneType,
"Clone the type of an object, with Object* return type. ",
"Must be defined by derived classes. ");
I_Method1(osg::Object *, clone, IN, const osg::CopyOp &, copyop,
Properties::VIRTUAL,
__osg_Object_P1__clone__C5_osg_CopyOp_R1,
"Clone an object, with Object* return type. ",
"Must be defined by derived classes. ");
I_Method1(bool, isSameKindAs, IN, const osg::Object *, obj,
Properties::VIRTUAL,
__bool__isSameKindAs__C5_osg_Object_P1,
"",
"");
I_Method0(const char *, libraryName,
Properties::VIRTUAL,
__C5_char_P1__libraryName,
"return the name of the object's library. ",
"Must be defined by derived classes. The OpenSceneGraph convention is that the namespace of a library is the same as the library name. ");
I_Method0(const char *, className,
Properties::VIRTUAL,
__C5_char_P1__className,
"return the name of the object's class type. ",
"Must be defined by derived classes. ");
I_Method0(void, clear,
Properties::NON_VIRTUAL,
__void__clear,
"",
"");
I_Method1(void, setActiveLayer, IN, unsigned int, i,
Properties::NON_VIRTUAL,
__void__setActiveLayer__unsigned_int,
"",
"");
I_Method0(unsigned int, getActiveLayer,
Properties::NON_VIRTUAL,
__unsigned_int__getActiveLayer,
"",
"");
I_Method2(void, setFileName, IN, unsigned int, i, IN, const std::string &, filename,
Properties::NON_VIRTUAL,
__void__setFileName__unsigned_int__C5_std_string_R1,
"",
"");
I_Method1(const std::string &, getFileName, IN, unsigned int, i,
Properties::NON_VIRTUAL,
__C5_std_string_R1__getFileName__unsigned_int,
"",
"");
I_Method2(void, setLayer, IN, unsigned int, i, IN, osgTerrain::Layer *, layer,
Properties::NON_VIRTUAL,
__void__setLayer__unsigned_int__Layer_P1,
"",
"");
I_Method1(osgTerrain::Layer *, getLayer, IN, unsigned int, i,
Properties::NON_VIRTUAL,
__Layer_P1__getLayer__unsigned_int,
"",
"");
I_Method1(const osgTerrain::Layer *, getLayer, IN, unsigned int, i,
Properties::NON_VIRTUAL,
__C5_Layer_P1__getLayer__unsigned_int,
"",
"");
I_Method1(void, addLayer, IN, const std::string &, filename,
Properties::NON_VIRTUAL,
__void__addLayer__C5_std_string_R1,
"",
"");
I_Method1(void, addLayer, IN, osgTerrain::Layer *, layer,
Properties::NON_VIRTUAL,
__void__addLayer__Layer_P1,
"",
"");
I_Method1(void, removeLayer, IN, unsigned int, i,
Properties::NON_VIRTUAL,
__void__removeLayer__unsigned_int,
"",
"");
I_Method0(unsigned int, getNumLayers,
Properties::NON_VIRTUAL,
__unsigned_int__getNumLayers,
"",
"");
I_SimpleProperty(unsigned int, ActiveLayer,
__unsigned_int__getActiveLayer,
__void__setActiveLayer__unsigned_int);
I_IndexedProperty(const std::string &, FileName,
__C5_std_string_R1__getFileName__unsigned_int,
__void__setFileName__unsigned_int__C5_std_string_R1,
0);
I_ArrayProperty(osgTerrain::Layer *, Layer,
__Layer_P1__getLayer__unsigned_int,
__void__setLayer__unsigned_int__Layer_P1,
__unsigned_int__getNumLayers,
__void__addLayer__Layer_P1,
0,
__void__removeLayer__unsigned_int);
END_REFLECTOR