Added scale parameter into PositionAttitudeTransform.
Added pivotPoint parameter into AnimationPathCallack.
This commit is contained in:
@@ -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