Hi,

seems like the matrix.getrotate is broken again. 'osgunittests quat' also reports lots of problems.
sorry, I've spoken too soon. Matrix.getrotate is fine. The unittests report false positives (q = -q is OK), will fix this.
I promise to still fix the unittests...


For your problem angles, quat(angle,axis) = -1 * osgTrans.getRotate(), which is fine ito the rotation. It seems that quat.getRotate is the culprit. Still looking...
I was wrong again, quat.getRotate is also fine. The expectation (yours and mine) of what quat.getRotate(angle, axis) does was wrong.

quat.getRotate _sets_ both the axis and angle. The axis is not a parameter in the sense of asking "What is the angle about this axis?", it is set by the call. If you print out the axis as well as the angle you will see that all is well, e.g. 271 deg about (0 0 -1) is the same as 89 about (0 0 1).

I attach a modified version of your test.

Sorry for all the noise, hope this clears it up.

regards
jp


jp

I'm comparing with old working versions, will let you know.

jp

[EMAIL PROTECTED] wrote:
I've run into a problem using Quaternion rotation with osg::Matrixd that I 
can't seem to figure out. Consider the following test example and resulting 
output:

#define DEG2RAD(d) d*(2*M_PI/360.0)
#define RAD2DEG(r) r*360.0/2*M_PI

void testQuaternionRotation()
{
        osg::Matrixd osgTrans;
        osgTrans.set(osg::Matrix::identity());
        osg::Vec3f axis(0.0,0.0,1.0);
        double osgTransAngle,osgQuatAngle;


        printf("\n*** Doing a 360 deg quaternion rotation about z-axis using OSG 
***\n");
        for(int i = 0; i < 360; ++i)
        {
                double angle = DEG2RAD(i);
                osg::Quat quat(angle,axis);
                quat.getRotate(osgQuatAngle,axis);

                //Set the quat rotation on matrix
                osgTrans.setRotate(quat);
                quat = osgTrans.getRotate();
                quat.getRotate(osgTransAngle,axis);
                printf("Rot: %.1f osgQang: %.1f osgTransAng: 
%.1f\n",RAD2DEG(angle),RAD2DEG(osgQuatAngle),RAD2DEG(osgTransAngle));
        }
}

Output:
Rot: 268.0 osgQang: 268.0 osgTransAng: 268.0
Rot: 269.0 osgQang: 269.0 osgTransAng: 269.0
Rot: 270.0 osgQang: 270.0 osgTransAng: 90.0
Rot: 271.0 osgQang: 271.0 osgTransAng: 89.0

Reading back rotation angles in the 4'th quadrant gives me invalid values. I 
would have expected to either get negative angle or the angle that I used to 
rotate about the z-axis. Am I missing a elementary consept here or is this an 
actual bug in the implementation?
Setting the matrix using a quaternion with angles from the 4'th quaderant seems 
to be working just fine, it's only reading it back that doesn't work.

Thanks for any help on this,
Filip
_______________________________________________
osg-users mailing list
osg-users@lists.openscenegraph.org
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.

#include <osg/Quat>
#include <osg/Matrixd>
#include <osg/io_utils>

#include <iostream>
#include <math.h>

int main(void)
{

    osg::Matrixd osgTrans;
    osgTrans.set(osg::Matrix::identity());
    osg::Vec3f axis(0.0,0.0,1.0);
    double osgTransAngle,osgQuatAngle;


    printf("\n*** Doing a 360 deg quaternion rotation about z-axis using OSG ***\n");
    for(int i = 0; i < 360; ++i)
    {
	double angle = (double)i/180.0*M_PI;
	osg::Quat quat(angle,axis);
	quat.getRotate(osgQuatAngle,axis);
	std::cout << quat << "\n" << axis << "\n";
	    
	//Set the quat rotation on matrix
	osgTrans.setRotate(quat);
	quat = osgTrans.getRotate();
	quat.getRotate(osgTransAngle,axis);
	std::cout << quat << "\n" << axis << "\n";
	    
	printf("Rot: %.1f osgQang: %.1f osgTransAng: %.1f\n",angle/M_PI*180.0, osgQuatAngle/M_PI*180.0, osgTransAngle/M_PI*180.0);
    }
}
_______________________________________________
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to