|
Jasmine,
What you could do is the
following:
Just after "double rad=fit.getRadius();"
print out the radius. You will notice that, depending on the shapes involved,
this radius will vary. Anyhow, I added after "viewTrf.set(viewVector);"
the following statement "viewTrf.setScale(rad * factor);" This factor
depends on things like your current scale and viewscale set, so it may be
different to the factor I used. You probably have to experiment a
little to find the most suitable factor. But, when done, you'll notice every
shape or combinations of them, nicely fit into your view. It may be that
sometimes the distance between your view edges and the geometry is not always
equal. For instance, the distance at the bottom may sometimes be a little
different to that on the top. The reason is that we calculate the area being
shown in your view by using a bounding sphere and not every shape fills the
space so nicely into all directions as a sphere. So, you will notice, ball-like
or cubical shapes fit nicer than something wich is bended, long and thin. Just
logical. However, I noticed that even at high end commercial Cad systems this
sometimes is the case. So, they probably use bounding spheres as
well.
By the way, I believe for Parallel
projection it is not longer necessary to calculate the view distance vector
using FieldofView etc. So, I just gave it a distance large enough to prevent
shapes from entering the front clipping plane. It all worked
fine.
Success, Dirk
----- Original Message -----
Sent: Friday, March 21, 2003 2:33
AM
Subject: Re: [JAVA3D] Fit image in
frame
Thats great!
However, in my case, whenever I'm using parallel
projection, the code merely moves the image into the center
of the frame, and does not resize it to fit the
frame.
I tried adjusting the radius but it results in
different sizes in the 2 different projections.
What range of values would be good for the
radius?
Do you have any idea what else is the cause for
this?
Regards,
Jasmine
----- Original Message -----
Sent: Thursday, March 20, 2003 7:14
PM
Subject: Re: [JAVA3D] Fit image in
frame
Jasmine,
Honestly speaking, I never used parallel
projection. So, I tried it out, changed the ProjectionPolicy and it worked
as well with parallel projections.
Regards, Dirk
----- Original Message -----
Sent: Thursday, March 20, 2003 6:58
AM
Subject: Re: [JAVA3D] Fit image in
frame
Hi Dirk,
I have tried the codes, and it works well for
perspective projection. Is there any chance that this method works for
parallel projection as well?
Regards,
Jasmine
----- Original Message -----
Sent: Wednesday, March 19, 2003
6:39 PM
Subject: 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
|