How to fit 3d object to the window automatically?

Started by dankor, May 24, 2007, 12:36:56 PM

Previous topic - Next topic

dankor

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


Melssj5

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!
Nada por ahora

EgonOlsen

#2
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.

dankor

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?.


EgonOlsen

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.

cyberkilla

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:)
http://futurerp.net - Text Based MMORPG
http://beta.rpwar.com - 3D Isometric MMORPG