From 55d4affdedc04b1915f4728e4498a8e756bf7f9e Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Tue, 27 Aug 2002 20:18:43 +0000 Subject: [PATCH] Added support for DOFTransforms into .osg format, and add pivot point support to the PositionAttitudeTransform .osg support. Removed a double light reference in the osglight demo. --- include/osg/DOFTransform | 56 ++++++--- include/osg/PositionAttitudeTransform | 2 +- include/osg/Quat | 35 ++---- src/Demos/osglight/osglight.cpp | 2 - src/osgPlugins/osg/DOFTransform.cpp | 112 +++++++++++++++++- .../osg/PositionAttitudeTransform.cpp | 14 +++ 6 files changed, 175 insertions(+), 46 deletions(-) diff --git a/include/osg/DOFTransform b/include/osg/DOFTransform index a2d779f06..2d2394259 100644 --- a/include/osg/DOFTransform +++ b/include/osg/DOFTransform @@ -42,43 +42,63 @@ class SG_EXPORT DOFTransform : public Transform virtual void traverse(NodeVisitor& nv); - void setMinHPR(const Vec3& hpr) {_minHPR = hpr;} + void setMinHPR(const Vec3& hpr) { _minHPR = hpr;} + const Vec3& getMinHPR() const { return _minHPR;} + void setMaxHPR(const Vec3& hpr) {_maxHPR = hpr;} - void setCurrentHPR(const Vec3& hpr) {_currentHPR = hpr;} + const Vec3& getMaxHPR() const { return _maxHPR;} + void setIncrementHPR(const Vec3& hpr) {_incrementHPR = hpr;} + const Vec3& getIncrementHPR() const { return _incrementHPR;} + + void setCurrentHPR(const Vec3& hpr) {_currentHPR = hpr;} + const Vec3& getCurrentHPR() const {return _currentHPR;} void updateCurrentHPR(const Vec3& hpr); + void setMinTranslate(const Vec3& translate) {_minTranslate = translate;} + const Vec3& getMinTranslate() const { return _minTranslate;} + void setMaxTranslate(const Vec3& translate) {_maxTranslate = translate;} - void setCurrentTranslate(const Vec3& translate){_currentTranslate = translate;} - void setIncrementTranslate(const Vec3& translate) {_incrementTranslate = translate;} + const Vec3& getMaxTranslate() const { return _maxTranslate;} + + void setIncrementTranslate(const Vec3& translate) { _incrementTranslate = translate;} + const Vec3& getIncrementTranslate() const { return _incrementTranslate;} + + void setCurrentTranslate(const Vec3& translate){ _currentTranslate = translate;} + inline const Vec3& getCurrentTranslate() const { return _currentTranslate;} void updateCurrentTranslate(const Vec3& translate); - void setMinScale(const Vec3& scale) {_minScale = scale;} - void setMaxScale(const Vec3& scale) {_maxScale = scale;} - void setCurrentScale(const Vec3& scale) {_currentScale = scale;} - void setIncrementScale(const Vec3& scale) {_incrementScale = scale;} + + void setMinScale(const Vec3& scale) { _minScale = scale;} + const Vec3& getMinScale() const { return _minScale;} + + void setMaxScale(const Vec3& scale) { _maxScale = scale;} + const Vec3& getMaxScale() const { return _maxScale;} + + void setIncrementScale(const Vec3& scale) { _incrementScale = scale;} + const Vec3& getIncrementScale() const { return _incrementScale;} + + void setCurrentScale(const Vec3& scale) { _currentScale = scale;} + inline const Vec3& getCurrentScale() const { return _currentScale;} void updateCurrentScale(const Vec3& scale); - void setPutMatrix(const Matrix& put) {_Put = put;} - void setInversePutMatrix(const Matrix& inversePut) {_inversePut = inversePut;} - - void setLimitationFlags(const unsigned long flags) {_limitationFlags = flags;} - - inline const Vec3& getCurrentHPR() const {return _currentHPR;} - inline const Vec3& getCurrentTranslate() const {return _currentTranslate;} - inline const Vec3& getCurrentScale() const {return _currentScale;} + void setPutMatrix(const Matrix& put) { _Put = put;} inline const Matrix& getPutMatrix() const {return _Put;} + + void setInversePutMatrix(const Matrix& inversePut) { _inversePut = inversePut;} inline const Matrix& getInversePutMatrix() const {return _inversePut;} - inline const unsigned long getLimitationFlags() const {return _limitationFlags;} + void setLimitationFlags(unsigned long flags) { _limitationFlags = flags;} + inline unsigned long getLimitationFlags() const {return _limitationFlags;} + inline void setAnimationOn(bool do_animate) {_animationOn = do_animate;} - inline const bool animationOn() const {return _animationOn;} + inline bool getAnimationOn() const {return _animationOn;} void animate(); diff --git a/include/osg/PositionAttitudeTransform b/include/osg/PositionAttitudeTransform index 439fd7da7..a7e73c630 100644 --- a/include/osg/PositionAttitudeTransform +++ b/include/osg/PositionAttitudeTransform @@ -42,7 +42,7 @@ class SG_EXPORT PositionAttitudeTransform : public Transform void setPivotPoint(const Vec3& pivot) { _pivotPoint = pivot; dirtyBound(); } - const Vec3& setPivotPoint() const { return _pivotPoint; } + const Vec3& getPivotPoint() const { return _pivotPoint; } virtual const bool computeLocalToWorldMatrix(Matrix& matrix,NodeVisitor* nv) const; diff --git a/include/osg/Quat b/include/osg/Quat index 29738d63e..929bc52d6 100644 --- a/include/osg/Quat +++ b/include/osg/Quat @@ -61,6 +61,18 @@ class SG_EXPORT Quat _fv = v; } + inline float& operator [] (int i) { return _fv[i]; } + inline float operator [] (int i) const { return _fv[i]; } + + inline float& x() { return _fv[0]; } + inline float& y() { return _fv[1]; } + inline float& z() { return _fv[2]; } + inline float& w() { return _fv[3]; } + + inline float x() const { return _fv[0]; } + inline float y() const { return _fv[1]; } + inline float z() const { return _fv[2]; } + inline float w() const { return _fv[3]; } /* ------------------------------------------------------------- BASIC ARITHMETIC METHODS @@ -105,29 +117,6 @@ class SG_EXPORT Quat return (*this); // enable nesting } -// /// Binary multiply -// inline const Quat operator*(const Quat& rhs) const -// { -// return Quat( _fv[3]*rhs._fv[0] + _fv[0]*rhs._fv[3] + _fv[1]*rhs._fv[2] - _fv[2]*rhs._fv[1], -// _fv[3]*rhs._fv[1] - _fv[0]*rhs._fv[2] + _fv[1]*rhs._fv[3] + _fv[2]*rhs._fv[0], -// _fv[3]*rhs._fv[2] + _fv[0]*rhs._fv[1] - _fv[1]*rhs._fv[0] + _fv[2]*rhs._fv[3], -// _fv[3]*rhs._fv[3] - _fv[0]*rhs._fv[0] - _fv[1]*rhs._fv[1] - _fv[2]*rhs._fv[2] ); -// } -// -// /// Unary multiply -// inline Quat& operator*=(const Quat& rhs) -// { -// float x = _fv[3]*rhs._fv[0] + _fv[0]*rhs._fv[3] + _fv[1]*rhs._fv[2] - _fv[2]*rhs._fv[1]; -// float y = _fv[3]*rhs._fv[1] - _fv[0]*rhs._fv[2] + _fv[1]*rhs._fv[3] + _fv[2]*rhs._fv[0]; -// float z = _fv[3]*rhs._fv[2] + _fv[0]*rhs._fv[1] - _fv[1]*rhs._fv[0] + _fv[2]*rhs._fv[3]; -// _fv[3] = _fv[3]*rhs._fv[3] - _fv[0]*rhs._fv[0] - _fv[1]*rhs._fv[1] - _fv[2]*rhs._fv[2]; -// -// _fv[2] = z; -// _fv[1] = y; -// _fv[0] = x; -// -// return (*this); // enable nesting -// } /// Divide by scalar inline const Quat operator / (const float& rhs) const diff --git a/src/Demos/osglight/osglight.cpp b/src/Demos/osglight/osglight.cpp index 29eeb0b64..48747a7ed 100644 --- a/src/Demos/osglight/osglight.cpp +++ b/src/Demos/osglight/osglight.cpp @@ -147,8 +147,6 @@ osg::Node* createLights(osg::BoundingBox& bb,osg::StateSet* rootStateSet) mt->addChild(lightS2); mt->addChild(markerGeode); - lightGroup->addChild(lightS2); - lightGroup->addChild(mt); return lightGroup; diff --git a/src/osgPlugins/osg/DOFTransform.cpp b/src/osgPlugins/osg/DOFTransform.cpp index cf59c42f7..328831fb8 100644 --- a/src/osgPlugins/osg/DOFTransform.cpp +++ b/src/osgPlugins/osg/DOFTransform.cpp @@ -6,6 +6,7 @@ using namespace osg; using namespace osgDB; +using namespace std; // forward declare functions to use later. bool DOFTransform_readLocalData(Object& obj, Input& fr); @@ -26,9 +27,93 @@ bool DOFTransform_readLocalData(Object& obj, Input& fr) { bool iteratorAdvanced = false; - DOFTransform& transform = static_cast(obj); + DOFTransform& dof = static_cast(obj); + + if (fr.matchSequence("PutMatrix {")) + { + fr += 2; // skip over "putMatrix {" + iteratorAdvanced = true; + + bool matched = true; + for(int k=0;k<16 && matched;++k) + { + matched = fr[k].isFloat(); + } + if (matched) + { + osg::Matrix matrix; + int k=0; + for(int i=0;i<4;++i) + { + for(int j=0;j<4;++j) + { + fr[k].getFloat(matrix(i,j)); + k++; + } + } + + dof.setPutMatrix(matrix); + dof.setInversePutMatrix(Matrix::inverse(matrix)); + } + + fr.advanceToEndOfCurrentBlock(); + } + + +#define ReadVec3(A,B) { \ + if (fr[0].matchWord(B) && \ + fr[1].getFloat(vec3[0]) && \ + fr[2].getFloat(vec3[1]) && \ + fr[3].getFloat(vec3[2])) \ + { \ + dof.A(vec3); \ + fr+=4; \ + iteratorAdvanced = true; \ + } \ +} + + Vec3 vec3; + + ReadVec3(setMinHPR,"minHPR") + ReadVec3(setMaxHPR,"maxHPR") + ReadVec3(setIncrementHPR,"incrementHPR") + ReadVec3(setCurrentHPR,"currentHPR") + + ReadVec3(setMinTranslate,"minTranslate") + ReadVec3(setMaxTranslate,"maxTranslate") + ReadVec3(setIncrementTranslate,"incrementTranslate") + ReadVec3(setCurrentTranslate,"currentTranslate") + + ReadVec3(setMinScale,"minScale") + ReadVec3(setMaxScale,"maxScale") + ReadVec3(setIncrementScale,"incrementScale") + ReadVec3(setCurrentScale,"currentScale") + + + if (fr.matchSequence("limitationFlags %i")) + { + unsigned int flags; + fr[1].getUInt(flags); + dof.setLimitationFlags(flags); + + fr += 2; + iteratorAdvanced = true; + + } + + if (fr[0].matchWord("animationOn")) + { + + if (fr[1].matchWord("TRUE")) dof.setAnimationOn(true); + else if (fr[1].matchWord("FALSE")) dof.setAnimationOn(false); + + fr += 2; + iteratorAdvanced = true; + + } + +#undef ReadVec3 - return iteratorAdvanced; } @@ -37,5 +122,28 @@ bool DOFTransform_writeLocalData(const Object& obj, Output& fw) { const DOFTransform& transform = static_cast(obj); + fw.indent()<<"PutMatrix "<