It should work! I am using basicaly the same mechanism, except that I'm preparing several views from which you can look at the object. The one you described is only looking along z direction from + to -.
 
Here is another algorithm where you can also specify rotation angles rx, ry, rz in radians. The values 0, 0, 0 generates the same transform as in your algorithm. Try experimenting with various angles to see which one fits you best. Some tips: if the upward direction for your model is along +z axis, you should try rx = Math.PI / 3; ry = 0.0; rz = Math.PI / 4. If the upward direction is along +y axis, then try rx = -Math.PI / 6; ry = Math.PI / 4; rz = 0.0
 
BoundingSphere fit=(BoundingSphere)objRoot.getBounds();
double rad=fit.getRadius();
Point3d ctr=new Point3d();
fit.getCenter(ctr);
View view=universe.getViewer().getView();
double viewDistance=2.0*rad/Math.tan(View.getFieldofView()/2.0);
Transform3D dist = new Transform3D();
dist.set(new Vector3d(0, 0, viewDistance));
Transform3D rotation = new Transform3D();
rotation.setEuler(new Vector3d(rx, ry, rz));
rotation.mul(dist);
Transform3D viewTrf = new Transform3D();
viewTrf.set(new Vector3d(center.x, center.y, center.z));
viewTrf.mul(rotation);
TransformGroup vpTrans=universe.getViewingPlatform().getViewPlatformTransform();
vpTrans.setTransform(viewTrf);
 
Cheers,
 
Florin
-----Urspr�ngliche Nachricht-----
Von: Dirk L. van Krimpen [mailto:[EMAIL PROTECTED]
Gesendet: Mittwoch, 19. M�rz 2003 09:39
An: [EMAIL PROTECTED]
Betreff: Re: [JAVA3D] Fit image in frame

 
Hi Jasmine,
 
I got good results with:
 
BoundingSphere fit=(BoundingSphere)objRoot.getBounds();
double rad=fit.getRadius();
Point3d ctr=new Point3d();
fit.getCenter(ctr);
View view=universe.getViewer().getView();
Vector3d viewvector=new Vector3d(ctr);
double viewDistance=2.0*rad/Math.tan(View.getFieldofView()/2.0);
viewVector.z=viewDistance;
Transform3D viewTrf=new Transform3D();
viewTrf.set(viewVector);
TransformGroup vpTrans=universe.getViewingPlatform().getViewPlatformTransform();
vpTrans.setTransform(viewTrf);
 
This will shift your geometry to the center of your canvas. After this you may set the radius of "fit" to your liking (usually people like to have at least some space between the frame borders and the geometry).
 
Please, give it a try. I am interested to know if it worked for you as well.
 
Thanks, Dirk
----- Original Message -----
Sent: Wednesday, March 19, 2003 5:47 AM
Subject: [JAVA3D] Fit image in frame

Hi all,
i am doing a program in which there is a command. When selected, the displayed image has to be scaled to fit it nicely into the frame. My question is that how do I knowhow big/small I have to scale the image in order for it to fit in the frame?
 
==
Jasmine Kwok

Reply via email to