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

Sonya Blade sonyablade2010 at hotmail.com
Thu Jul 2 23:38:15 PDT 2015


Hi Sebastian,
> 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.Does anybody can confirm also that there is not a feature like that in osg? These 3 vectors may seem that they are independent but actually they are dependant, because knowing any 2 of them you can always get the 3rd one with cross product of first two.So any modifications on one of them affects others as well.
>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. I already tried that without succes, the glitch here is at the bare minimum I have to define 2 vectors (up/direction, up/right, direction/right etcc combinaton) but I don't how to combine those two into a quaternion ? 
I forgot to mention that I get plenty of following errorson console screen, when I assign direction vector, this happens when I try to pan, move, zoom of whole scene. Could that be the source of discrepancy ?   
CullVisitor::apply(Geode&) detected NaN,    depth=nan, center=(0 -2.5 0),    matrix={        nan nan nan nan        nan nan nan nan        nan nan nan nan        35 -35 0 1} 
Date: Thu, 2 Jul 2015 19:25:34 +0200
From: sebastian.messerschmidt at gmx.de
To: osg-users at lists.openscenegraph.org
Subject: Re: [osg-users] Orientating model in 3D space with quaternions


  
    
  
  
    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

    
    

  


_______________________________________________
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/20150703/de25d581/attachment-0003.htm>


More information about the osg-users mailing list