Hello everyone, rather than trying to recreate a quaternion library, I thought I would simply try to use what was in Java3D. I’m simply trying to get a sphere to rotate in all 3 axes: roll, pitch, and yaw… but am having difficulties… The code is below. Here is what is happening … I can pitch (rotate around x-axis) fine, but if I roll to the right or left by 90 degrees and then pitch, the ball appears to yaw.
private void drawBall( GL2 gl )
{
/* now add the texture */
rdsTexture.enable( gl );
rdsTexture.bind( gl );
/* rotate for inclination and toolface */
AxisAngle4f pitchAA = new AxisAngle4f( 1.0f , 0 , 0 , ( float ) Math.toRadians( pitch + 90 ) );
Quat4f pitchQuat = new Quat4f( );
pitchQuat.set( pitchAA );
AxisAngle4f rollAA = new AxisAngle4f( 0 , 0 , 1.0f , ( float ) Math.toRadians( roll + 180 ) );
Quat4f rollQuat = new Quat4f( );
rollQuat.set( rollAA );
AxisAngle4f yawAA = new AxisAngle4f( 0 , 1.0f , 0 , ( float ) Math.toRadians( yaw ) );
Quat4f yawQuat = new Quat4f( );
yawQuat.set( yawAA );
result.mul( yawQuat , pitchQuat );
result.mul( rollQuat );
float[ ] m = new float[ 16 ];
gl.glGetFloatv( GL2.GL_MODELVIEW_MATRIX , m , 0 );
Transform3D transform = new Transform3D( m );
transform.setRotation( result );
Matrix4f m4 = new Matrix4f( );
transform.get( m4 );
float[ ] modelView = new float[ ] { m4.m00 , m4.m01 , m4.m02 , m4.m03 , m4.m10 , m4.m11 , m4.m12 , m4.m13 ,
m4.m20 , m4.m21 , m4.m22 , m4.m23 , m4.m30 , m4.m31 , m4.m32 , m4.m33 , };
/* the default view is straight and level */
gl.glMultMatrixf( modelView , 0 );
/* draw a sphere */
GLUquadric quadric = glu.gluNewQuadric( );
glu.gluQuadricTexture( quadric , true );
glu.gluSphere( quadric , 6.0f , 64 , 64 );
}