From c8ef144532bf805efe16da5bf653c3e7e2ed827a Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Thu, 28 Aug 2008 09:43:00 +0000 Subject: [PATCH] Converted AutoTransform to use doubles. --- include/osg/AutoTransform | 44 +++++----- src/osg/AutoTransform.cpp | 66 +++++++-------- src/osgWrappers/osg/AutoTransform.cpp | 76 +++++++++--------- src/osgWrappers/osgTerrain/Layer.cpp | 111 ++++++++++++++++++++++++++ 4 files changed, 204 insertions(+), 93 deletions(-) diff --git a/include/osg/AutoTransform b/include/osg/AutoTransform index e41c6aa64..b92435e82 100644 --- a/include/osg/AutoTransform +++ b/include/osg/AutoTransform @@ -42,26 +42,26 @@ class OSG_EXPORT AutoTransform : public Transform virtual AutoTransform* asAutoTransform() { return this; } virtual const AutoTransform* asAutoTransform() const { return this; } - inline void setPosition(const Vec3& pos) { _position = pos; _matrixDirty=true; dirtyBound(); } - inline const Vec3& getPosition() const { return _position; } + inline void setPosition(const Vec3d& pos) { _position = pos; _matrixDirty=true; dirtyBound(); } + inline const Vec3d& getPosition() const { return _position; } inline void setRotation(const Quat& quat) { _rotation = quat; _matrixDirty=true; dirtyBound(); } 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); - inline const Vec3& getScale() const { return _scale; } + void setScale(const Vec3d& scale); + inline const Vec3d& getScale() const { return _scale; } - void setMinimumScale(float minimumScale) { _minimumScale = minimumScale; } - float getMinimumScale() const { return _minimumScale; } + void setMinimumScale(double minimumScale) { _minimumScale = minimumScale; } + double getMinimumScale() const { return _minimumScale; } - void setMaximumScale(float maximumScale) { _maximumScale = maximumScale; } - float getMaximumScale() const { return _maximumScale; } + void setMaximumScale(double maximumScale) { _maximumScale = maximumScale; } + double getMaximumScale() const { return _maximumScale; } - inline void setPivotPoint(const Vec3& pivot) { _pivotPoint = pivot; _matrixDirty=true; dirtyBound(); } - inline const Vec3& getPivotPoint() const { return _pivotPoint; } + inline void setPivotPoint(const Vec3d& pivot) { _pivotPoint = pivot; _matrixDirty=true; dirtyBound(); } + inline const Vec3d& getPivotPoint() const { return _pivotPoint; } void setAutoUpdateEyeMovementTolerance(float tolerance) { _autoUpdateEyeMovementTolerance = tolerance; } @@ -98,32 +98,32 @@ class OSG_EXPORT AutoTransform : public Transform virtual ~AutoTransform() {} - Vec3 _position; - Vec3 _pivotPoint; - float _autoUpdateEyeMovementTolerance; + Vec3d _position; + Vec3d _pivotPoint; + double _autoUpdateEyeMovementTolerance; AutoRotateMode _autoRotateMode; bool _autoScaleToScreen; mutable Quat _rotation; - mutable Vec3 _scale; + mutable Vec3d _scale; mutable bool _firstTimeToInitEyePoint; mutable osg::Vec3 _previousEyePoint; mutable osg::Vec3 _previousLocalUp; mutable Viewport::value_type _previousWidth; mutable Viewport::value_type _previousHeight; - mutable osg::Matrix _previousProjection; - mutable osg::Vec3 _previousPosition; + mutable osg::Matrixd _previousProjection; + mutable osg::Vec3d _previousPosition; - float _minimumScale; - float _maximumScale; - float _autoScaleTransitionWidthRatio; + double _minimumScale; + double _maximumScale; + double _autoScaleTransitionWidthRatio; void computeMatrix() const; - mutable bool _matrixDirty; - mutable osg::Matrix _cachedMatrix; + mutable bool _matrixDirty; + mutable osg::Matrixd _cachedMatrix; }; } diff --git a/src/osg/AutoTransform.cpp b/src/osg/AutoTransform.cpp index a9f753a2d..aa99d4783 100644 --- a/src/osg/AutoTransform.cpp +++ b/src/osg/AutoTransform.cpp @@ -18,14 +18,14 @@ using namespace osg; AutoTransform::AutoTransform(): - _autoUpdateEyeMovementTolerance(0.0f), + _autoUpdateEyeMovementTolerance(0.0), _autoRotateMode(NO_ROTATION), _autoScaleToScreen(false), - _scale(1.0f,1.0f,1.0f), + _scale(1.0,1.0,1.0), _firstTimeToInitEyePoint(true), - _minimumScale(0.0f), - _maximumScale(FLT_MAX), - _autoScaleTransitionWidthRatio(0.25f), + _minimumScale(0.0), + _maximumScale(DBL_MAX), + _autoScaleTransitionWidthRatio(0.25), _matrixDirty(true) { // setNumChildrenRequiringUpdateTraversal(1); @@ -49,7 +49,7 @@ AutoTransform::AutoTransform(const AutoTransform& pat,const CopyOp& copyop): // setNumChildrenRequiringUpdateTraversal(getNumChildrenRequiringUpdateTraversal()+1); } -void AutoTransform::setScale(const Vec3& scale) +void AutoTransform::setScale(const Vec3d& scale) { _scale = scale; if (_scale.x()<_minimumScale) _scale.x() = _minimumScale; @@ -87,14 +87,14 @@ bool AutoTransform::computeWorldToLocalMatrix(Matrix& matrix,NodeVisitor*) const { matrix.postMult(osg::Matrix::translate(-_position)* 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)); } else // absolute { matrix = osg::Matrix::translate(-_position)* 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); } return true; @@ -138,21 +138,21 @@ void AutoTransform::accept(NodeVisitor& nv) height = viewport->height(); } - osg::Vec3 eyePoint = cs->getEyeLocal(); - osg::Vec3 localUp = cs->getUpLocal(); - osg::Vec3 position = getPosition(); + osg::Vec3d eyePoint = cs->getEyeLocal(); + osg::Vec3d localUp = cs->getUpLocal(); + osg::Vec3d position = getPosition(); const osg::Matrix& projection = *(cs->getProjectionMatrix()); bool doUpdate = _firstTimeToInitEyePoint; if (!_firstTimeToInitEyePoint) { - osg::Vec3 dv = _previousEyePoint-eyePoint; + osg::Vec3d dv = _previousEyePoint-eyePoint; if (dv.length2()>getAutoUpdateEyeMovementTolerance()*(eyePoint-getPosition()).length2()) { doUpdate = true; } - osg::Vec3 dupv = _previousLocalUp-localUp; + osg::Vec3d dupv = _previousLocalUp-localUp; // rotating the camera only affects ROTATE_TO_* if (_autoRotateMode && dupv.length2()>getAutoUpdateEyeMovementTolerance()) @@ -179,35 +179,35 @@ void AutoTransform::accept(NodeVisitor& nv) 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; - float i = (_maximumScale0.0) ? + double n = _maximumScale; + double m = (_minimumScale>0.0) ? _maximumScale+(_minimumScale-_maximumScale)*_autoScaleTransitionWidthRatio : - _maximumScale*(1.0f-_autoScaleTransitionWidthRatio); - float c = 1.0f / (4.0f*(m-n)); - float b = 1.0f - 2.0f*c*m; - float a = n + b*b/(4.0f*c); - float p = -b / (2.0f*c); + _maximumScale*(1.0-_autoScaleTransitionWidthRatio); + double c = 1.0 / (4.0*(m-n)); + double b = 1.0 - 2.0*c*m; + double a = n + b*b/(4.0*c); + double p = -b / (2.0*c); if (size>p) size = _maximumScale; 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) { - osg::Vec3 PosToEye = _position - eyePoint; + osg::Vec3d PosToEye = _position - eyePoint; osg::Matrix lookto = osg::Matrix::lookAt( - osg::Vec3(0,0,0), PosToEye, localUp); + osg::Vec3d(0,0,0), PosToEye, localUp); Quat q; q.set(osg::Matrix::inverse(lookto)); setRotation(q); diff --git a/src/osgWrappers/osg/AutoTransform.cpp b/src/osgWrappers/osg/AutoTransform.cpp index da598a054..5d4414eca 100644 --- a/src/osgWrappers/osg/AutoTransform.cpp +++ b/src/osgWrappers/osg/AutoTransform.cpp @@ -17,7 +17,7 @@ #include #include #include -#include +#include // Must undefine IN and OUT macros defined in Windows headers #ifdef IN @@ -84,14 +84,14 @@ BEGIN_OBJECT_REFLECTOR(osg::AutoTransform) __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, - __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, - __C5_Vec3_R1__getPosition, + __C5_Vec3d_R1__getPosition, "", ""); I_Method1(void, setRotation, IN, const osg::Quat &, quat, @@ -104,49 +104,49 @@ BEGIN_OBJECT_REFLECTOR(osg::AutoTransform) __C5_Quat_R1__getRotation, "", ""); - I_Method1(void, setScale, IN, float, scale, + I_Method1(void, setScale, IN, double, scale, 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, - __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, - __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, - __void__setMinimumScale__float, + __void__setMinimumScale__double, "", ""); - I_Method0(float, getMinimumScale, + I_Method0(double, getMinimumScale, Properties::NON_VIRTUAL, - __float__getMinimumScale, + __double__getMinimumScale, "", ""); - I_Method1(void, setMaximumScale, IN, float, maximumScale, + I_Method1(void, setMaximumScale, IN, double, maximumScale, Properties::NON_VIRTUAL, - __void__setMaximumScale__float, + __void__setMaximumScale__double, "", ""); - I_Method0(float, getMaximumScale, + I_Method0(double, getMaximumScale, 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, - __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, - __C5_Vec3_R1__getPivotPoint, + __C5_Vec3d_R1__getPivotPoint, "", ""); I_Method1(void, setAutoUpdateEyeMovementTolerance, IN, float, tolerance, @@ -222,23 +222,23 @@ BEGIN_OBJECT_REFLECTOR(osg::AutoTransform) I_SimpleProperty(float, AutoUpdateEyeMovementTolerance, __float__getAutoUpdateEyeMovementTolerance, __void__setAutoUpdateEyeMovementTolerance__float); - I_SimpleProperty(float, MaximumScale, - __float__getMaximumScale, - __void__setMaximumScale__float); - I_SimpleProperty(float, MinimumScale, - __float__getMinimumScale, - __void__setMinimumScale__float); - I_SimpleProperty(const osg::Vec3 &, PivotPoint, - __C5_Vec3_R1__getPivotPoint, - __void__setPivotPoint__C5_Vec3_R1); - I_SimpleProperty(const osg::Vec3 &, Position, - __C5_Vec3_R1__getPosition, - __void__setPosition__C5_Vec3_R1); + I_SimpleProperty(double, MaximumScale, + __double__getMaximumScale, + __void__setMaximumScale__double); + I_SimpleProperty(double, MinimumScale, + __double__getMinimumScale, + __void__setMinimumScale__double); + I_SimpleProperty(const osg::Vec3d &, PivotPoint, + __C5_Vec3d_R1__getPivotPoint, + __void__setPivotPoint__C5_Vec3d_R1); + I_SimpleProperty(const osg::Vec3d &, Position, + __C5_Vec3d_R1__getPosition, + __void__setPosition__C5_Vec3d_R1); I_SimpleProperty(const osg::Quat &, Rotation, __C5_Quat_R1__getRotation, __void__setRotation__C5_Quat_R1); - I_SimpleProperty(const osg::Vec3 &, Scale, - __C5_Vec3_R1__getScale, - __void__setScale__C5_Vec3_R1); + I_SimpleProperty(const osg::Vec3d &, Scale, + __C5_Vec3d_R1__getScale, + __void__setScale__C5_Vec3d_R1); END_REFLECTOR diff --git a/src/osgWrappers/osgTerrain/Layer.cpp b/src/osgWrappers/osgTerrain/Layer.cpp index d1d027ec5..8dcce3b3f 100644 --- a/src/osgWrappers/osgTerrain/Layer.cpp +++ b/src/osgWrappers/osgTerrain/Layer.cpp @@ -869,3 +869,114 @@ BEGIN_OBJECT_REFLECTOR(osgTerrain::ProxyLayer) __void__setModifiedCount__unsigned_int); 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 +