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.
This commit is contained in:
@@ -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();
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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<DOFTransform&>(obj);
|
||||
DOFTransform& dof = static_cast<DOFTransform&>(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<const DOFTransform&>(obj);
|
||||
|
||||
fw.indent()<<"PutMatrix "<<transform.getPutMatrix()<<std::endl;
|
||||
|
||||
fw.indent()<<"minHPR "<<transform.getMinHPR()<<std::endl;
|
||||
fw.indent()<<"maxHPR "<<transform.getMaxHPR()<<std::endl;
|
||||
fw.indent()<<"incrementHPR "<<transform.getIncrementHPR()<<std::endl;
|
||||
fw.indent()<<"currentHPR "<<transform.getCurrentHPR()<<std::endl;
|
||||
|
||||
fw.indent()<<"minTranslate "<<transform.getMinTranslate()<<std::endl;
|
||||
fw.indent()<<"maxTranslate "<<transform.getMaxTranslate()<<std::endl;
|
||||
fw.indent()<<"incrementTranslate "<<transform.getIncrementTranslate()<<std::endl;
|
||||
fw.indent()<<"currentTranslate "<<transform.getCurrentTranslate()<<std::endl;
|
||||
|
||||
fw.indent()<<"minScale "<<transform.getMinScale()<<std::endl;
|
||||
fw.indent()<<"axScale "<<transform.getMaxScale()<<std::endl;
|
||||
fw.indent()<<"incrementScale "<<transform.getIncrementScale()<<std::endl;
|
||||
fw.indent()<<"currentScale "<<transform.getCurrentScale()<<std::endl;
|
||||
|
||||
fw.indent()<<"limitationFlags 0x"<<hex<<transform.getLimitationFlags()<<dec<<std::endl;
|
||||
|
||||
fw.indent()<<"animationOn ";
|
||||
if (transform.getAnimationOn()) fw<<"TRUE"<<std::endl;
|
||||
else fw<<"FALSE"<<std::endl;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -51,6 +51,19 @@ bool PositionAttitudeTransform_readLocalData(Object& obj, Input& fr)
|
||||
|
||||
transform.setAttitude(att);
|
||||
|
||||
fr += 5;
|
||||
iteratorAdvanced = true;
|
||||
}
|
||||
|
||||
if (fr.matchSequence("pivot %f %f %f"))
|
||||
{
|
||||
osg::Vec3 pivot;
|
||||
fr[1].getFloat(pivot[0]);
|
||||
fr[2].getFloat(pivot[1]);
|
||||
fr[3].getFloat(pivot[2]);
|
||||
|
||||
transform.setPivotPoint(pivot);
|
||||
|
||||
fr += 4;
|
||||
iteratorAdvanced = true;
|
||||
}
|
||||
@@ -65,6 +78,7 @@ bool PositionAttitudeTransform_writeLocalData(const Object& obj, Output& fw)
|
||||
|
||||
fw.indent()<<"position "<<transform.getPosition()<<std::endl;
|
||||
fw.indent()<<"attitude "<<transform.getAttitude()<<std::endl;
|
||||
fw.indent()<<"pivotPoint "<<transform.getPivotPoint()<<std::endl;
|
||||
|
||||
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user