ozRocker Posted June 30, 2017 Share Posted June 30, 2017 I'm wondering if there's a way I can determine the Y position of a camera so the mesh its looking at completely fills the viewport. Basically I have a camera above the ground which is looking down to the ground at a 45 degree angle and is focusing on certain objects on the ground. Is this possible? Quote Link to comment Share on other sites More sharing options...
Wingnut Posted June 30, 2017 Share Posted June 30, 2017 Hi Oz. Not sure if this will help, but check out this thread, and its final playground link. No promises. ozRocker 1 Quote Link to comment Share on other sites More sharing options...
sable Posted June 30, 2017 Share Posted June 30, 2017 http://www.babylonjs-playground.com/#GQWGC0#3 is what I've used before, which I adapted from https://www.opengl.org/discussion_boards/showthread.php/169865-Zoom-to-fit-screen/page2 Looks like a similar solution to the one at the end of the thread @Wingnut posted. ozRocker 1 Quote Link to comment Share on other sites More sharing options...
ozRocker Posted June 30, 2017 Author Share Posted June 30, 2017 Wow! Thanks so much fellas! This is super useful. I tried searching the forums before but couldn't find anything Quote Link to comment Share on other sites More sharing options...
ozRocker Posted June 30, 2017 Author Share Posted June 30, 2017 This is weird. Both of those examples use mesh.getBoundingInfo().boundingBox.extendSizeWorld My mesh doesn't have extendSizeWorld, it only has extendSize. I'm using a merged mesh for this. Quote Link to comment Share on other sites More sharing options...
ozRocker Posted June 30, 2017 Author Share Posted June 30, 2017 I figured it out. the latest babylon.js preview has "extendSizeWorld". I've been reluctant to use the preview version cos the inspector is completely broken :/ Quote Link to comment Share on other sites More sharing options...
sable Posted June 30, 2017 Share Posted June 30, 2017 My example uses boundingSphere instead, which I think should exist in 2.5 as well. Using the sphere means that any rotation of the mesh you're focusing on should fit in the viewport. Quote Link to comment Share on other sites More sharing options...
ozRocker Posted July 3, 2017 Author Share Posted July 3, 2017 On 30/06/2017 at 2:15 PM, sable said: My example uses boundingSphere instead, which I think should exist in 2.5 as well. Using the sphere means that any rotation of the mesh you're focusing on should fit in the viewport. Thank you! I couldn't get it working then I realised that mesh scale needs to be 1, so once I got that sorted it worked perfectly Quote Link to comment Share on other sites More sharing options...
sable Posted July 3, 2017 Share Posted July 3, 2017 Hadn't thought about scaling. You could use let radius = mesh.getBoundingInfo().boundingSphere.radiusWorld; to get it working for any scale. ozRocker and Pryme8 2 Quote Link to comment Share on other sites More sharing options...
ozRocker Posted July 4, 2017 Author Share Posted July 4, 2017 I have a mesh that only rotates around the Y-axis so I found that boundingSphere is too restrictive because it checks on every axis. Is there a way to use a bounding sphere (or maybe bounding cylinder) for this kind of situation. At the moment the mesh ends up a bit too small with some space around it Quote Link to comment Share on other sites More sharing options...
Pryme8 Posted July 4, 2017 Share Posted July 4, 2017 Use a bounding box instead of a sphere then, find the axis with the longest measurement. When I get home I'll show you the way I did it for a client. This is fairly simple to do without the preview version of bjs Quote Link to comment Share on other sites More sharing options...
ozRocker Posted July 4, 2017 Author Share Posted July 4, 2017 24 minutes ago, Pryme8 said: Use a bounding box instead of a sphere then, find the axis with the longest measurement. When I get home I'll show you the way I did it for kirakira. This is fairly simple to do without the preview version of bjs I'm trying to steer clear of the preview version 'cos of the broken inspector but I'll use it if I absolutely have to. But I'm wondering if a bounding box will work. The point of the bounding sphere was that it works on all rotations. A bounding box calculation will cause the mesh to go out of the viewport on its diagonals like in this example https://www.babylonjs-playground.com/#P6JAWE#6 (if you rotate by hand the diagonals will bust out of the viewport) A bounding cylinder would be perfect because that would calculate only on the Y-axis rotation. Quote Link to comment Share on other sites More sharing options...
Pryme8 Posted July 4, 2017 Share Posted July 4, 2017 I thought I had it then I ran tests, give me a second.https://www.babylonjs-playground.com/#P6JAWE#7 this does not work fully yet, I did not have much time to look at it though.https://www.babylonjs-playground.com/#P6JAWE#9 there we go I think this may work...@ozRockerhttps://www.babylonjs-playground.com/#P6JAWE#10 This shows it pushed to the extreme, I tried both orientations and it seems to work have not tested any with y height yet. maybe switch from a ground to a cube. Quote Link to comment Share on other sites More sharing options...
jerome Posted July 4, 2017 Share Posted July 4, 2017 tan(fov * 0.5) = visual height / distance to the camera visual width = visual height * aspectRatio Pryme8 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.