Added scale parameter into PositionAttitudeTransform.
Added pivotPoint parameter into AnimationPathCallack.
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
################################################################
|
||||
# Dependency library which have been installed on this system
|
||||
|
||||
GDAL_INSTALLED = yes
|
||||
GDAL_INSTALLED = no
|
||||
JASPER_INSTALLED = yes
|
||||
|
||||
FREETYPE_INSTALLED = yes
|
||||
|
||||
@@ -187,6 +187,7 @@ class SG_EXPORT AnimationPathCallback : public NodeCallback
|
||||
public:
|
||||
|
||||
AnimationPathCallback():
|
||||
_pivotPoint(0.0f,0.0f,0.0f),
|
||||
_useInverseMatrix(false),
|
||||
_timeOffset(0.0),
|
||||
_timeMultiplier(1.0),
|
||||
@@ -198,6 +199,7 @@ class SG_EXPORT AnimationPathCallback : public NodeCallback
|
||||
AnimationPathCallback(const AnimationPathCallback& apc,const CopyOp& copyop):
|
||||
NodeCallback(apc,copyop),
|
||||
_animationPath(apc._animationPath),
|
||||
_pivotPoint(apc._pivotPoint),
|
||||
_useInverseMatrix(apc._useInverseMatrix),
|
||||
_timeOffset(apc._timeOffset),
|
||||
_timeMultiplier(apc._timeMultiplier),
|
||||
@@ -211,6 +213,7 @@ class SG_EXPORT AnimationPathCallback : public NodeCallback
|
||||
|
||||
AnimationPathCallback(AnimationPath* ap,double timeOffset=0.0f,double timeMultiplier=1.0f):
|
||||
_animationPath(ap),
|
||||
_pivotPoint(0.0f,0.0f,0.0f),
|
||||
_useInverseMatrix(false),
|
||||
_timeOffset(timeOffset),
|
||||
_timeMultiplier(timeMultiplier),
|
||||
@@ -221,11 +224,12 @@ class SG_EXPORT AnimationPathCallback : public NodeCallback
|
||||
|
||||
|
||||
void setAnimationPath(AnimationPath* path) { _animationPath = path; }
|
||||
|
||||
AnimationPath* getAnimationPath() { return _animationPath.get(); }
|
||||
|
||||
const AnimationPath* getAnimationPath() const { return _animationPath.get(); }
|
||||
|
||||
|
||||
inline void setPivotPoint(const Vec3& pivot) { _pivotPoint = pivot; }
|
||||
inline const Vec3& getPivotPoint() const { return _pivotPoint; }
|
||||
|
||||
void setUseInverseMatrix(bool useInverseMatrix) { _useInverseMatrix = useInverseMatrix; }
|
||||
bool getUseInverseMatrix() const { return _useInverseMatrix; }
|
||||
|
||||
@@ -252,6 +256,7 @@ class SG_EXPORT AnimationPathCallback : public NodeCallback
|
||||
public:
|
||||
|
||||
ref_ptr<AnimationPath> _animationPath;
|
||||
osg::Vec3 _pivotPoint;
|
||||
bool _useInverseMatrix;
|
||||
double _timeOffset;
|
||||
double _timeMultiplier;
|
||||
|
||||
@@ -33,6 +33,7 @@ class SG_EXPORT PositionAttitudeTransform : public Transform
|
||||
Transform(pat,copyop),
|
||||
_position(pat._position),
|
||||
_attitude(pat._attitude),
|
||||
_scale(pat._scale),
|
||||
_pivotPoint(pat._pivotPoint) {}
|
||||
|
||||
|
||||
@@ -42,32 +43,32 @@ class SG_EXPORT PositionAttitudeTransform : public Transform
|
||||
virtual const PositionAttitudeTransform* asPositionAttitudeTransform() const { return this; }
|
||||
|
||||
inline void setPosition(const Vec3& pos) { _position = pos; dirtyBound(); }
|
||||
|
||||
inline const Vec3& getPosition() const { return _position; }
|
||||
|
||||
|
||||
inline void setAttitude(const Quat& quat) { _attitude = quat; dirtyBound(); }
|
||||
|
||||
inline const Quat& getAttitude() const { return _attitude; }
|
||||
|
||||
|
||||
inline void setScale(const Vec3& scale) { _scale = scale; dirtyBound(); }
|
||||
inline const Vec3& getScale() const { return _scale; }
|
||||
|
||||
|
||||
inline void setPivotPoint(const Vec3& pivot) { _pivotPoint = pivot; dirtyBound(); }
|
||||
|
||||
inline const Vec3& getPivotPoint() const { return _pivotPoint; }
|
||||
|
||||
|
||||
virtual bool computeLocalToWorldMatrix(Matrix& matrix,NodeVisitor* nv) const;
|
||||
|
||||
virtual bool computeWorldToLocalMatrix(Matrix& matrix,NodeVisitor* nv) const;
|
||||
|
||||
|
||||
|
||||
protected :
|
||||
|
||||
virtual ~PositionAttitudeTransform() {}
|
||||
|
||||
Vec3 _position;
|
||||
Quat _attitude;
|
||||
Vec3 _scale;
|
||||
Vec3 _pivotPoint;
|
||||
};
|
||||
|
||||
|
||||
@@ -111,8 +111,9 @@ class AnimationPathCallbackVisitor : public NodeVisitor
|
||||
{
|
||||
public:
|
||||
|
||||
AnimationPathCallbackVisitor(const AnimationPath::ControlPoint& cp, bool useInverseMatrix):
|
||||
AnimationPathCallbackVisitor(const AnimationPath::ControlPoint& cp, const osg::Vec3& pivotPoint, bool useInverseMatrix):
|
||||
_cp(cp),
|
||||
_pivotPoint(pivotPoint),
|
||||
_useInverseMatrix(useInverseMatrix) {}
|
||||
|
||||
virtual void apply(MatrixTransform& mt)
|
||||
@@ -123,7 +124,7 @@ class AnimationPathCallbackVisitor : public NodeVisitor
|
||||
else
|
||||
_cp.getMatrix(matrix);
|
||||
|
||||
mt.setMatrix(matrix);
|
||||
mt.setMatrix(osg::Matrix::translate(-_pivotPoint)*matrix);
|
||||
}
|
||||
|
||||
virtual void apply(PositionAttitudeTransform& pat)
|
||||
@@ -134,16 +135,21 @@ class AnimationPathCallbackVisitor : public NodeVisitor
|
||||
_cp.getInverse(matrix);
|
||||
pat.setPosition(matrix.getTrans());
|
||||
pat.setAttitude(_cp._rotation.inverse());
|
||||
pat.setScale(osg::Vec3(1.0f/_cp._scale.x(),1.0f/_cp._scale.y(),1.0f/_cp._scale.z()));
|
||||
pat.setPivotPoint(_pivotPoint);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
pat.setPosition(_cp._position);
|
||||
pat.setAttitude(_cp._rotation);
|
||||
pat.setScale(_cp._scale);
|
||||
pat.setPivotPoint(_pivotPoint);
|
||||
}
|
||||
}
|
||||
|
||||
AnimationPath::ControlPoint _cp;
|
||||
osg::Vec3 _pivotPoint;
|
||||
bool _useInverseMatrix;
|
||||
};
|
||||
|
||||
@@ -178,7 +184,7 @@ void AnimationPathCallback::update(osg::Node& node)
|
||||
AnimationPath::ControlPoint cp;
|
||||
if (_animationPath->getInterpolatedControlPoint(getAnimationTime(),cp))
|
||||
{
|
||||
AnimationPathCallbackVisitor apcv(cp,_useInverseMatrix);
|
||||
AnimationPathCallbackVisitor apcv(cp,_pivotPoint,_useInverseMatrix);
|
||||
node.accept(apcv);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,8 @@
|
||||
|
||||
using namespace osg;
|
||||
|
||||
PositionAttitudeTransform::PositionAttitudeTransform()
|
||||
PositionAttitudeTransform::PositionAttitudeTransform():
|
||||
_scale(1.0f,1.0f,1.0f)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -23,12 +24,14 @@ bool PositionAttitudeTransform::computeLocalToWorldMatrix(Matrix& matrix,NodeVis
|
||||
if (_referenceFrame==RELATIVE_TO_PARENTS)
|
||||
{
|
||||
matrix.preMult(osg::Matrix::translate(-_pivotPoint)*
|
||||
osg::Matrix::scale(_scale)*
|
||||
osg::Matrix::rotate(_attitude)*
|
||||
osg::Matrix::translate(_position));
|
||||
}
|
||||
else // absolute
|
||||
{
|
||||
matrix = osg::Matrix::translate(-_pivotPoint)*
|
||||
osg::Matrix::scale(_scale)*
|
||||
osg::Matrix::rotate(_attitude)*
|
||||
osg::Matrix::translate(_position);
|
||||
}
|
||||
@@ -42,12 +45,14 @@ bool PositionAttitudeTransform::computeWorldToLocalMatrix(Matrix& matrix,NodeVis
|
||||
{
|
||||
matrix.postMult(osg::Matrix::translate(-_position)*
|
||||
osg::Matrix::rotate(_attitude.inverse())*
|
||||
osg::Matrix::scale(1.0f/_scale.x(),1.0f/_scale.y(),1.0f/_scale.z())*
|
||||
osg::Matrix::translate(_pivotPoint));
|
||||
}
|
||||
else // absolute
|
||||
{
|
||||
matrix = osg::Matrix::translate(-_position)*
|
||||
osg::Matrix::rotate(_attitude.inverse())*
|
||||
osg::Matrix::scale(1.0f/_scale.x(),1.0f/_scale.y(),1.0f/_scale.z())*
|
||||
osg::Matrix::translate(_pivotPoint);
|
||||
}
|
||||
return true;
|
||||
|
||||
@@ -31,6 +31,7 @@ void AnimationPathCallback::write(DataOutputStream* out){
|
||||
throw Exception("AnimationPathCallback::write(): Could not cast this osg::AnimationPathCallback to an osg::Object.");
|
||||
// Write AnimationPathCallback's properties.
|
||||
|
||||
out->writeVec3(_pivotPoint);
|
||||
out->writeDouble(_timeOffset);
|
||||
out->writeDouble(_timeMultiplier);
|
||||
out->writeDouble(_firstTime);
|
||||
@@ -61,6 +62,7 @@ void AnimationPathCallback::read(DataInputStream* in){
|
||||
else
|
||||
throw Exception("AnimationPathCallback::read(): Could not cast this osg::AnimationPathCallback to an osg::Object.");
|
||||
// Read AnimationPathCallback's properties
|
||||
_pivotPoint = in->readVec3();
|
||||
_timeOffset = in->readDouble();
|
||||
_timeMultiplier = in->readDouble();
|
||||
_firstTime = in->readDouble();
|
||||
|
||||
@@ -32,6 +32,7 @@ void PositionAttitudeTransform::write(DataOutputStream* out){
|
||||
|
||||
out->writeVec3(getPosition());
|
||||
out->writeQuat(getAttitude());
|
||||
out->writeVec3(getScale());
|
||||
out->writeVec3(getPivotPoint());
|
||||
}
|
||||
|
||||
@@ -51,6 +52,7 @@ void PositionAttitudeTransform::read(DataInputStream* in){
|
||||
// Read PositionAttitudeTransform's properties
|
||||
setPosition(in->readVec3());
|
||||
setAttitude(in->readQuat());
|
||||
setScale(in->readVec3());
|
||||
setPivotPoint(in->readVec3());
|
||||
|
||||
}
|
||||
|
||||
@@ -388,6 +388,7 @@ osg::Drawable* ReaderWriterOBJ::makeDrawable_duplicateCoords(GLMmodel* obj, GLMg
|
||||
// geometry
|
||||
osg::Geometry* geom = new osg::Geometry;
|
||||
|
||||
geom->setUseDisplayList(false);
|
||||
// geom->setUseVertexBufferObjects(true);
|
||||
|
||||
// primitives are only triangles
|
||||
@@ -491,6 +492,7 @@ osg::Drawable* ReaderWriterOBJ::makeDrawable_useSeperateIndices(GLMmodel* obj, G
|
||||
// geometry
|
||||
osg::Geometry* geom = new osg::Geometry;
|
||||
|
||||
geom->setUseDisplayList(false);
|
||||
// geom->setUseVertexBufferObjects(true);
|
||||
|
||||
// the following code for mapping the coords, normals and texcoords
|
||||
@@ -604,15 +606,15 @@ osg::Drawable* ReaderWriterOBJ::makeDrawable_useSeperateIndices(GLMmodel* obj, G
|
||||
geom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::TRIANGLES,0,ntris*3));
|
||||
|
||||
}
|
||||
|
||||
#if 0
|
||||
osgUtil::TriStripVisitor tsv;
|
||||
tsv.stripify(*geom);
|
||||
#endif
|
||||
|
||||
if (obj->numnormals==0)
|
||||
{
|
||||
osgUtil::SmoothingVisitor tsv;
|
||||
tsv.smooth(*geom);
|
||||
}
|
||||
|
||||
return geom;
|
||||
}
|
||||
|
||||
@@ -167,18 +167,33 @@ bool AnimationPathCallback_readLocalData(osg::Object &obj, osgDB::Input &fr)
|
||||
osg::AnimationPathCallback *apc = dynamic_cast<osg::AnimationPathCallback*>(&obj);
|
||||
if (!apc) return false;
|
||||
|
||||
bool itrAdvanced = false;
|
||||
bool iteratorAdvanced = false;
|
||||
|
||||
if (fr.matchSequence("pivotPoint %f %f %f"))
|
||||
{
|
||||
osg::Vec3 pivot;
|
||||
fr[1].getFloat(pivot[0]);
|
||||
fr[2].getFloat(pivot[1]);
|
||||
fr[3].getFloat(pivot[2]);
|
||||
|
||||
apc->setPivotPoint(pivot);
|
||||
|
||||
fr += 4;
|
||||
iteratorAdvanced = true;
|
||||
}
|
||||
|
||||
if (fr.matchSequence("timeOffset %f"))
|
||||
{
|
||||
fr[1].getFloat(apc->_timeOffset);
|
||||
fr+=2;
|
||||
itrAdvanced = true;
|
||||
iteratorAdvanced = true;
|
||||
}
|
||||
|
||||
else if(fr.matchSequence("timeMultiplier %f"))
|
||||
{
|
||||
fr[1].getFloat(apc->_timeMultiplier);
|
||||
fr+=2;
|
||||
itrAdvanced = true;
|
||||
iteratorAdvanced = true;
|
||||
}
|
||||
|
||||
static osg::ref_ptr<osg::AnimationPath> s_path = new osg::AnimationPath;
|
||||
@@ -187,10 +202,10 @@ bool AnimationPathCallback_readLocalData(osg::Object &obj, osgDB::Input &fr)
|
||||
{
|
||||
osg::AnimationPath* animpath = dynamic_cast<osg::AnimationPath*>(object.get());
|
||||
if (animpath) apc->setAnimationPath(animpath);
|
||||
itrAdvanced = true;
|
||||
iteratorAdvanced = true;
|
||||
}
|
||||
|
||||
return itrAdvanced;
|
||||
return iteratorAdvanced;
|
||||
}
|
||||
|
||||
|
||||
@@ -202,6 +217,7 @@ bool AnimationPathCallback_writeLocalData(const osg::Object &obj, osgDB::Output
|
||||
if (!apc) return false;
|
||||
|
||||
|
||||
fw.indent() <<"pivotPoint " <<apc->getPivotPoint()<<std::endl;
|
||||
fw.indent() <<"timeOffset " <<apc->_timeOffset<<std::endl;
|
||||
fw.indent() <<"timeMultiplier " <<apc->_timeMultiplier << std::endl;
|
||||
|
||||
|
||||
@@ -55,7 +55,20 @@ bool PositionAttitudeTransform_readLocalData(Object& obj, Input& fr)
|
||||
iteratorAdvanced = true;
|
||||
}
|
||||
|
||||
if (fr.matchSequence("pivot %f %f %f"))
|
||||
if (fr.matchSequence("scale %f %f %f"))
|
||||
{
|
||||
osg::Vec3 scale;
|
||||
fr[1].getFloat(scale[0]);
|
||||
fr[2].getFloat(scale[1]);
|
||||
fr[3].getFloat(scale[2]);
|
||||
|
||||
transform.setScale(scale);
|
||||
|
||||
fr += 4;
|
||||
iteratorAdvanced = true;
|
||||
}
|
||||
|
||||
if (fr.matchSequence("pivotPoint %f %f %f"))
|
||||
{
|
||||
osg::Vec3 pivot;
|
||||
fr[1].getFloat(pivot[0]);
|
||||
@@ -78,6 +91,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()<<"scale "<<transform.getScale()<<std::endl;
|
||||
fw.indent()<<"pivotPoint "<<transform.getPivotPoint()<<std::endl;
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user