[osg-users] Orientating model in 3D space with quaternions

Sebastian Messerschmidt sebastian.messerschmidt at gmx.de
Thu Jul 2 10:25:34 PDT 2015


Hi Sonya,

Usually you use an cosine-matrix for this. It allows to determine the 
quaternion which translates one coordinate frame (i.e. 3 independent 
vectors) into another, but I think osg doesn't have this.
I think you can use the makeRotate by applying the resulting quaternion 
to the vec3(0,0,1) and (1,0,0) and using the makeRotate with the results 
somehow to get the inverse.

Cheers
Sebastian
> Dear All,
>
> I load a model with the following code in my program, p1 and p2 are 
> osg::Vec3 type variables and simply representing
> the each ends of object in spatial space ( I also use them to find the 
> direction vector). What I want to achive is: to place
> that model up vector always aligned  facing upward ( this doesn't mean 
> that it must coincidence/be parallel with global
> Z axis)  to achieve that  If I apply the quaternions then object is 
> positioned with correct direction vector (calulated via
> p1, p2)  but rolled with arbitrary angle along that direction vector, 
> which violates my conditional goal.
>
> It also seems that it's not a supprise that it produces that result 
> bcoz nowhere I specify the crucial right or up vector with
> quaternion which is required to position the object in 3D space. So 
> How am I supposed to correct that effect either with
> quaternions or matrices ?
>
>                   loadedModel = osgDB::readNodeFile("quad.obj");
>                   osg::Vec3Array* verlist= static_cast<osg::Vec3Array* 
> >(rubber_line->getVertexArray());
>                   osg::Vec3 p1 = (*verlist)[0];
>                   osg::Vec3 p2 = (*verlist)[1];
>
> osg::ref_ptr<osg::PositionAttitudeTransform> Transf = new 
> osg::PositionAttitudeTransform;
>                   Transf->setPosition( p1 );
>
>                   osg::Quat quad;
>                   osg::Matrix matrix, mat2;
>
> quad.makeRotate(osg::Vec3(0,1,0),p2-p1);
>
> Transf->setAttitude(quad);
>                     Transf->addChild(loadedModel);
>                     rootnode->addChild(Transf);
>
>
>
>
> _______________________________________________
> osg-users mailing list
> osg-users at lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20150702/32acd39b/attachment-0003.htm>


More information about the osg-users mailing list