Here is a method I use to set the view TransformGroup so that everything
inside a BoundingSphere is visible.
The viewers position is set to the center of the bounding sphere and then
moved back along the Z axis until radius of the sphere is within the view
frustum.
The calculation includes a scaling of 1.4 which can be adjusted depending on
how tightly the BoundingSphere fits the geometry.
/**
* Set the transform so that everything inside the BoundingSphere is
* visible
*/
private void setViewpoint( TransformGroup viewTG, BoundingSphere sceneBounds,
View view
) {
Transform3D viewTrans = new Transform3D();
Transform3D eyeTrans = new Transform3D();
// point the view at the center of the object
Point3d center = new Point3d();
sceneBounds.getCenter(center);
double radius = sceneBounds.getRadius();
Vector3d temp = new Vector3d(center);
viewTrans.set(temp);
// pull the eye back far enough to see the whole object
double eyeDist = 1.4*radius / Math.tan(view.getFieldOfView() / 2.0);
temp.x = 0.0;
temp.y = 0.0;
temp.z = eyeDist;
eyeTrans.set(temp);
viewTrans.mul(eyeTrans);
// set the view transform
viewTG.setTransform(viewTrans);
}
Rgds
Paul
----------------------------------------------------------
Paul Byrne Email : [EMAIL PROTECTED]
Sun Microsystems Phone : (650) 786 9926
Visualization Software Group Fax : (650) 786 5852
----------------------------------------------------------
===========================================================================
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".