Ken,

I had to do this the other day, this is what I ended up with. If anyone sees
a problem with the code below, please drop me a line...

Hope it helps,

Daniel Selman

Tornado Labs Ltd.

Email:   [EMAIL PROTECTED]
Web:     www.tornadolabs.com
Phone:   +44 (0131) 343 2513
Fax:     +44 07070 800 483


Matrix3d m1 = new Matrix3d();
m_Transform3D.get( m1 );

// extract the rotation angles from the upper 3x3 rotation
// component of the 4x4 transformation matrix
m_Rotation.x = java.lang.Math.atan2( m1.getElement( 2, 1 ),
1.getElement( 2, 2 ) );
m_Rotation.y = java.lang.Math.acos( m1.getElement( 2, 0 ) );
m_Rotation.z = java.lang.Math.atan2( m1.getElement( 1, 0 ),
1.getElement( 0, 0 ) );

// now try to ensure that the values are positive by adding 2PI if
necessary...
if( m_Rotation.x < 0.0 )
        m_Rotation.x += 2 * java.lang.Math.PI;

if( m_Rotation.y < 0.0 )
        m_Rotation.y += 2 * java.lang.Math.PI;

if( m_Rotation.z < 0.0 )
        m_Rotation.z += 2 * java.lang.Math.PI;

return m_Rotation;

-----Original Message-----
From: Todd Densmore [mailto:[EMAIL PROTECTED]]
Sent: 17 February 1999 05:02
To: dselman
Subject: Fwd: [java3d] Getting rotation angles from Tranform3D


>Date: Mon, 15 Feb 1999 20:03:55 -0600
>From: Ken Warner <[EMAIL PROTECTED]>
>X-Mailer: Mozilla 4.5 [en] (WinNT; I)
>X-Accept-Language: en
>To: "[EMAIL PROTECTED]" <[EMAIL PROTECTED]>
>Subject: [java3d] Getting rotation angles from Tranform3D
>Sender: [EMAIL PROTECTED]
>X-MDaemon-Deliver-To: [EMAIL PROTECTED]
>
>Hi,
>
>Let assume that I've rotated an object using MouseRotate and that I have
>the current
>Transform3D because I've implemented the MouseBehaviorCallback
>interface.
>
>How do I get the rotation angles of my object from each axis around the
>origin from that Transform3D?
>
>Ignoring the inefficiencies of making new Vector3d's each time I enter
>this method --
>
>This is where I am.  What is a good way to end up with RotX; RotY; RotZ?
>
>public void transformChanged(int type, Transform3D transform)
> {
>  Vector3d xpos = new Vector3d(1.0, 0.0, 0.0);
>  Vector3d ypos = new Vector3d(0.0, 1.0, 0.0);
>  Vector3d zpos = new Vector3d(0.0, 0.0, 1.0);
>
>   double RotX, RotY, RotZ;
>
>  //System.out.println(Integer.toString(type) + transform.toString());
>  //transform.transform(xpos);
>  //System.out.println(xpos.toString());
>
>  //transform.transform(ypos);
>  //System.out.println(ypos.toString());
>
>  transform.transform(ypos); //Applies the current transform to the y
>axis
>
>// Fiddle with result of applying current transform to y axis...
>  System.out.println(ypos.x + " " + ypos.y);
>  double angle = Math.atan2(ypos.x,ypos.y);
>  System.out.println(angle);
>  //System.out.println(ypos.toString() + "\n");
>
> }
>
>
>
>
>=====================================================================
>To subscribe/unsubscribe, send mail to [EMAIL PROTECTED]
>Java 3D Home Page: http://java.sun.com/products/java-media/3D/
>


Tornado Labs, Ltd.     [EMAIL PROTECTED]
24 Orchard Brae Avenue       www.tornadolabs.com
Edinburgh EH4 2HN                   07051 314159
Scotland, UK.


=====================================================================
To subscribe/unsubscribe, send mail to [EMAIL PROTECTED]
Java 3D Home Page: http://java.sun.com/products/java-media/3D/

Reply via email to