Hi, I recommend (for clarity, not necassarily for speed) that you define 2 transform groups: 1) for rotating the object, 2) for translating the object. For example:
TG_Translate -> TG_Rotate -> Geometry(centered at (0,0,0)) In the case case you describe, I would actually set up 3 TransformGroups. TG_Translate -> TG_RotateAboutXAxis -> TG_RotateAboutYAxis -> Geometry. Then you can change the orientation of the object without having to translate to the origin, rotate, then "translate back from the origin". Then I would use AxisAngle rather than quaternions for the rotation. I have used quaternions for rotations, and they work just fine. (Except for the damn constructor which insists on normalizing the quaternion no mater what components you give the constructor. Which is like normalize a vector every time you allocate a new one...yuk.) Anyway, AxisAngle is simpler to understand.... No explicit math involved (like calculating the half angle, or the inverse of the quaternion....) Just set the (Transform3D) axis (x or y axis) and the angular amount to rotate. Cheers, Bob Gray -----Original Message----- From: Discussion list for Java 3D API [mailto:JAVA3D-INTEREST@;JAVA.SUN.COM]On Behalf Of Bhargavi Sura Sent: Wednesday, November 13, 2002 3:19 PM To: [EMAIL PROTECTED] Subject: [JAVA3D] Quaternions for Rotation Hi, I am using using Quats for rotation along X an Y axis. I need to apply rotations according to the mouse drag amount. I have extended the Behavior class and wrote MyMouseRotate class to do this. But it doesnt work. I have read the archives and other material about Quats for rotation but still I am not able to figure out where I am doing wrong. Can any of you please look at my code and help me to do in the right way? Thanks Bhargavi This is the piece of code I am using: -------------------------------------------------------------- targetTG.getTransform(transform3D); //Translate to Origin translate.setTranslation(new Vector3d(3980.47,-320.34,-205.63)); transform3D.mul(translate); Quat4d qprev = new Quat4d(); Quat4d qu; //= new Quat4d(); //qu.set(new AxisAngle4d(1.0,.0,.0, rotateX*RADIANS)); // I have also used AxisAngle instead of the constructor to create Quat with no luck// double ang= rotateX*RADIANS; qu = new Quat4d(1.0 * Math.sin(ang/2), 0.0 * Math.sin(ang/2), 0.0 * Math.sin(ang/2), Math.cos(ang/2)); //Quat for Xaxis transform3D.get(qprev); qprev.mul(qu); ang= rotateY*RADIANS; qu = new Quat4d(0.0 * Math.sin(ang/2), 1.0 * Math.sin(ang/2), 0.0 * Math.sin(ang/2), Math.cos(ang/2)); //qu.set(new AxisAngle4d(.0,1.0,.0, rotateY*RADIANS)); qprev.mul(qu); transform3D.set(qprev); //Translate back from origin// translate.setTranslation(new Vector3d(-3980.47,320.34,205.63)); transform3D.mul(translate); targetTG.setTransform(transform3D); ----------------------------------------------------------------- =========================================================================== 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". =========================================================================== 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".
