Won't promise its optimal but here is the code from the Xj3D vrml
loader. Haven't really looked into optimizng this for the new release.
If others have sugesstions on how to improve this will glady take them.
void updateTransform() {
//System.out.println(this);
tempVec.x = -vfCenter[0];
tempVec.y = -vfCenter[1];
tempVec.z = -vfCenter[2];
trans2.setIdentity();
trans2.setTranslation(tempVec);
//System.out.println("-C "+trans2);
float scaleVal = 1.0f;
if (floatEq(vfScale[0], vfScale[1]) &&
floatEq(vfScale[0], vfScale[2])) {
scaleVal = vfScale[0];
trans1.set(scaleVal);
//System.out.println("S"+trans1);
} else {
// non-uniform scale
//System.out.println("Non Uniform Scale");
tempAxis.x = vfScaleOrientation[0];
tempAxis.y = vfScaleOrientation[1];
tempAxis.z = vfScaleOrientation[2];
tempAxis.angle = -vfScaleOrientation[3];
double tempAxisNormalizer = Math.sqrt(
tempAxis.x*tempAxis.x +
tempAxis.y*tempAxis.y +
tempAxis.z*tempAxis.z );
tempAxis.x/=tempAxisNormalizer;
tempAxis.y/=tempAxisNormalizer;
tempAxis.z/=tempAxisNormalizer;
trans1.set(tempAxis);
trans3.mul(trans1, trans2);
trans1.setScale (new Vector3d(vfScale[0], vfScale[1],
vfScale[2]));
trans2.mul(trans1, trans3);
tempAxis.x = vfScaleOrientation[0];
tempAxis.y = vfScaleOrientation[1];
tempAxis.z = vfScaleOrientation[2];
tempAxis.angle = vfScaleOrientation[3];
trans1.set(tempAxis);
}
trans3.mul(trans1, trans2);
//System.out.println("Sx-C"+trans3);
float magSq = (vfRotation[0] * vfRotation[0] +
vfRotation[1] * vfRotation[1] +
vfRotation[2] * vfRotation[2]);
if (magSq < ZEROEPS) {
// all zeros, use the default
// ?? does this still happen
tempAxis.x = 0.0;
tempAxis.y = 0.0;
//tempAxis.y = 1.0;
tempAxis.z = 0.0;
System.out.println("!!!Transform3D: magSq == 0");
} else {
if ((magSq > 1.01) || (magSq < 0.99)) {
float mag = (float) Math.sqrt((double)magSq);
tempAxis.x = vfRotation[0] / mag;
tempAxis.y = vfRotation[1] / mag;
tempAxis.z = vfRotation[2] / mag;
} else {
tempAxis.x = vfRotation[0];
tempAxis.y = vfRotation[1];
tempAxis.z = vfRotation[2];
}
}
tempAxis.angle = vfRotation[3];
trans1.set(tempAxis);
//System.out.println("R"+trans1);
trans2.mul(trans1, trans3);
//System.out.println("RxSx-C"+trans2);
tempVec.x = vfCenter[0];
tempVec.y = vfCenter[1];
tempVec.z = vfCenter[2];
trans1.setIdentity();
trans1.setTranslation(tempVec);
//System.out.println("C"+trans1);
//trans1.set(1.0, tempVec);
trans3.mul(trans1,trans2);
//System.out.println("CxRxSx-C"+trans3);
tempVec.x = vfTranslation[0];
tempVec.y = vfTranslation[1];
tempVec.z = vfTranslation[2];
trans1.setIdentity();
trans1.setTranslation(tempVec);
//trans1.set(1.0, tempVec);
trans2.mul(trans1, trans3);
//System.out.println("TxCxRxSx-C"+trans2);
//trans2.normalize();
//if(browser.debug)System.out.println(trans2+"
"+trans2.getType());
try {
implTG.setTransform(trans2);
} catch (javax.media.j3d.BadTransformException bte) {
bte.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
Silvere Martin-Michiellot wrote:
>
> Hi,
>
> given by the VRML 97 spec:
>
> Given a 3-dimensional point P and Transform node, P is transformed
> into point P' in its parent's coordinate system by a series of
> intermediate transformations. In matrix transformation notation,
> where C (center), SR (scaleOrientation), T (translation), R
> (rotation), and S (scale) are the equivalent transformation matrices,
>
> P' = T * C * R * SR * S * -SR * -C * P
>
--
Alan Hudson
President: Yumetech, Inc. http://www.yumetech.com/
Web3D Open Source Chair http://www.web3d.org/TaskGroups/source/
===========================================================================
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".