www.jpct.net

jPCT - a 3d engine for Java => Support => Topic started by: dankor on May 24, 2007, 12:36:56 pm

Title: How to fit 3d object to the window automatically?
Post by: dankor on May 24, 2007, 12:36:56 pm
Hello,

What is the way to fit the 3d object to the window automatically. Now I do it in this way:

world.getCamera().setPositionToCenter(obj);
world.getCamera().moveCamera(Camera.CAMERA_MOVEOUT, this.zoom); // every 3d object has diffrent initial zoom value.

Bye,

Daniel

Title: Re: How to fit 3d object to the window automatically?
Post by: Melssj5 on May 24, 2007, 05:51:29 pm
I guess there is not a direct or easy way to do it. But it should be a good idea to have something like that!
Title: Re: How to fit 3d object to the window automatically?
Post by: EgonOlsen on May 24, 2007, 06:03:45 pm
No, there is no build-in way to do this. But if you know the size of a particular mesh in world units (lets say a height of 10 units) and the size on screen for a particular camera distance (lets say 5 pixels for camera at -10), then you can calculate the size of any mesh at that distance if you know its height in world units (for example: height=20 units -> screenHeight= (5/10)*20=10). The size is linear even when doing the projection, so if you move to -20, the size would be 5, at -5 it would be 20 etc. By knowing this, it should be easy to calculate the correct distance yourself.
Title: Re: How to fit 3d object to the window automatically?
Post by: dankor on May 25, 2007, 09:09:19 am
Thank's a lot!

I understand Your solution , although 3D world is a black magic for me (I’ve read tutorial on Your page). But I don’t know anything about the 3D object passed to my applet like on  http://europe.nokia.com/e50 . So how can I guess the mesh size?.

Title: Re: How to fit 3d object to the window automatically?
Post by: EgonOlsen on May 25, 2007, 05:22:47 pm
Load the object in question, call build() on it, get the mesh from it and get the bounding box of that mesh. The absolute difference between minY and maxY should be the height.
Title: Re: How to fit 3d object to the window automatically?
Post by: cyberkilla on May 25, 2007, 09:12:35 pm
I suppose you could slowly zoom in,(while scanning the outer pixels of the viewport), and stop zooming as soon as you register a coloured pixel:)

Its the most interesting non-mathematical, weird workaround:)