The various methods we're talking about for figuring out a forward vector are 
rotating in different directions - here's a bit of test code to confirm.


Code:
FILE* fp = fopen("printout.txt", "w");
        osg::Vec3 f(0., 1., 0.);
        osg::Quat fq(0., 1., 0., 0.);
        osg::Quat q(osg::DegreesToRadians(45.0), osg::Vec3(0., 0., 1.));
        osg::Quat qc = q.conj();
        osg::Vec3 r1 = q*f;
        osg::Vec3 r2 = (q * fq * qc).asVec3();
        osg::Vec3 r3 = q.inverse() * f;
        fprintf(fp, "quat *  vec: %f %f %f\n", r1.x(), r1.y(), r1.z());
        fprintf(fp, "q * fq * qc: %f %f %f\n", r2.x(), r2.y(), r2.z());
        fprintf(fp, "q.inverse*f: %f %f %f\n", r3.x(), r3.y(), r3.z());
        fclose(fp);



Results:
quat *  vec: -0.707107 0.707107 0.000000
q * fq  * qc: 0.707107 0.707107 0.000000
q.inverse*f: 0.707107 0.707107 0.000000

Since the test rotation you've been using is close to pi/2, it looks like the 
axis is switched... but really, it's just rotated in the opposite direction 
than you expect.

When you get a rotation quat out of of a PAT or MatrixTransform, (I guess) it's 
giving you the coordinate system transform.  When you transform a coordinate 
system in one direction, it's equivalent to rotating vectors in the opposite 
direction.  So if you try and rotate a vector directly by this transform, ie by 
doing quat*vec, your forward vector will be rotated an equal amount but in the 
opposite direction from how the model appears on the screen.

By doing quat * vec * quat.conj(), or by doing quat.inverse() * vec, you're 
applying the coordinate system transform to your vector, and everything works 
out such that your forward vector and your on-screen model have rotated 
together.

I'm still quite new to these maths, so please, an expert should pitch in!  I am 
basing this all on my own experiences with moving objects around in osg.

Cheers,
Tom[/code]

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=29611#29611





_______________________________________________
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to