Hi,
order of transformations matter.
rotate * translate != translate * rotate
You can also visualise the tranformations either from a fixed coordinate
system of from moving with the transformed object.
You probably need just another translation to move the origin of the
pyramid to the tip.
E.g. transformations when moving with the object.
1) translate so that tip is at 0,0,0
2) rotate so that it points where you want
3) translate to final position
jp
John Galt wrote:
Hi,
I am trying to move a pyramid in the following manner.
(X,Y,Z,Roll,Pitch,Yaw) -> read from a txt file.
Move the pyramid by (X,Y,Z) and then rotate it about its peak by (Roll, Pitch,
Yaw)
Here's the code I made till now:
osg::AnimationPath* animationPath =
createAnimationPath("autoPath2.txt",0.1);
{...
Defined the Pyramid
...
}
const osg::BoundingSphere& bs = pyramidGeode->getBound();
float size = radius/bs.radius()*0.3f;
osg::MatrixTransform* positioned = new osg::MatrixTransform;
positioned->setDataVariance(osg::Object::STATIC);
positioned->setMatrix(osg::Matrix::translate(-bs.center())*
osg::Matrix::scale(size,size,size)*
osg::Matrix::rotate(osg::inDegrees(-90.0f),0.0f,0.0f,1.0f));
positioned->addChild(pyramidGeode);
osg::PositionAttitudeTransform* xform = new
osg::PositionAttitudeTransform;
xform->setUpdateCallback(new
osg::AnimationPathCallback(animationPath,0.0,1.0));
xform->addChild(positioned);
model->addChild(xform);
My animation is defined as follows:
osg::AnimationPath* createAnimationPath(std::string filename,double deltatime)
{
std::ifstream infile;
infile.open(filename.c_str(),std::ios::in);
double time=0.0f;
osg::AnimationPath* animationPath = new osg::AnimationPath;
animationPath->setLoopMode(osg::AnimationPath::LOOP);
while(infile.is_open() && !infile.eof())
{
double x,y,z,r,p,ya;
infile >> x >> y >> z>> r>> p>>ya;
osg::Vec3 position(x,y,z);
osg::Quat rotation;
rotation.makeRotate( osg::DegreesToRadians(r), osg::Vec3(-1,0,0),
osg::DegreesToRadians(p), osg::Vec3(0,-1,0) ,
osg::DegreesToRadians(ya), osg::Vec3(0,0,1) );
animationPath->insert(time,osg::AnimationPath::ControlPoint(position,rotation));
time += deltatime;
}
infile.close();
return animationPath;
}
But what this does is move the pyramid by X,Y,Z and rotate it by Roll,Pitch,Yaw
about the ORIGIN!
I want to rotate it around its peak and not the origin. Can you suggest any modifications?
Thank you!
Cheers,
John
------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=25432#25432
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
--
This message is subject to the CSIR's copyright terms and conditions, e-mail legal notice, and implemented Open Document Format (ODF) standard.
The full disclaimer details can be found at http://www.csir.co.za/disclaimer.html.
This message has been scanned for viruses and dangerous content by MailScanner,
and is believed to be clean. MailScanner thanks Transtec Computers for their support.
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org