Author Topic: How to fit 3d object to the window automatically?  (Read 6409 times)

Offline dankor

  • byte
  • *
  • Posts: 8
    • View Profile
How to fit 3d object to the window automatically?
« 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


Offline Melssj5

  • double
  • *****
  • Posts: 724
    • View Profile
Re: How to fit 3d object to the window automatically?
« Reply #1 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!
Nada por ahora

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11963
    • View Profile
    • http://www.jpct.net
Re: How to fit 3d object to the window automatically?
« Reply #2 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.
« Last Edit: May 24, 2007, 06:08:16 pm by EgonOlsen »

Offline dankor

  • byte
  • *
  • Posts: 8
    • View Profile
Re: How to fit 3d object to the window automatically?
« Reply #3 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?.


Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11963
    • View Profile
    • http://www.jpct.net
Re: How to fit 3d object to the window automatically?
« Reply #4 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.

Offline cyberkilla

  • float
  • ****
  • Posts: 413
    • View Profile
    • http://futurerp.net
Re: How to fit 3d object to the window automatically?
« Reply #5 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:)
http://futurerp.net - Text Based MMORPG
http://beta.rpwar.com - 3D Isometric MMORPG