Jump to content

Camera question


freetoplay
 Share

Recommended Posts

You can do some math and adjust camera.fov (and direction/target/alpha/beta).

scene.activeCamera.fov = 2.5;

I tried to see the bounding box to be able to programatically calculate the FOV, but maybe at least that camera property will help you get one step further.  Once you have a bounding box, you can do some math to have that all in the camera frustum.

Link to comment
Share on other sites

Here is how you fit a plane exactly in the frustum - it's a playground from Jerome.  That's the math for a plane.
https://playground.babylonjs.com/#UJWGY4#1

What I've done is that once you get your bounding box then you can work backwards.  I have done moving the camera backwards, so everything was in the frustum.  Here's a PG that I did that moves the camera (based on http://www.html5gamedevs.com/topic/31367-solved-determine-camera-distance-to-make-mesh-fit/ ) :

https://www.babylonjs-playground.com/#P6JAWE#11

Another option is to do isCompletelyInFrustum() - using mesh or camera, but again, you will need a bounding box... here is a PG that I made as well that explores that way.  I think you could do scaling and keep the positions of both the same.
https://playground.babylonjs.com/#050P3M
 

I was going to make you a PG, but I don't know how to get the bounding box from your mesh without calculating it from position vectors manually.  I think it might be a mesh._children[0] on the duck.  There are some posts how to get the bounding box on groups of imported meshes - I think you are going to need that first.

Anyway, as you can see - once you know how big the mesh is there are various ways to accomplish what you are after.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...