> How to use quaternion to do rotation about an arbitrary axis in Java3D?
> e.g: Quat4f
A good introduction to quaternions is at:
http://www.gamasutra.com/features/programming/19980703/quaternions_01.htm
To rotate about an arbitrary axis, AxisAngle4f is probably a better bet, the
fields of AxisAngles4f are:
angle: the amount to rotate, specified in radians use Math.toRadians()
to convert degress to radians.
x,y,z: the vector to rotate around. For example, to rotate around
the Z axis, use x=0, y=0, z=1.
To rotate around an axis at a point other than the origin you need to combine
transformations. You translate to put make the transformation point be at the
origin, rotate the object and then translate back. That is:
Transform3D trans = new Transform3D();
Transform3D temp = new Transform3D();
Vector3d translate = new Vector3d();
AxisAngle4d axis = new AxisAngle4d();
// translate so that x1,y1,z1 is at the origin
translate.x = -x1;
translate.y = -y1;
translate.z = -z1;
trans.set(translate);
// make a transform with the rotation
axis.angle = Math.toRadians(r);
axis.x = vx;
axis.y = vy;
axis.z = vz;
temp.set(axis);
// combine the translation and rotation
trans.mul(temp, trans);
// make a transform to move back
translate.x = x1;
translate.y = y1;
translate.z = z1;
temp.set(translate);
// combine the translation with the previous transformation
trans.mul(temp, trans);
Doug Gehringer
Sun Microsystems
===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA3D-INTEREST". For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".