Jump to content

How to make sure more two or more objects inside viewport?


Flexman
 Share

Recommended Posts

I was wondering if any of you smart chaps have an idea on how to position a camera so that two entities (or more) are always visible? Taking into account varying screen resolutions. In 3DS MAX this would be a "zoom to extents of multiple objects".

6600 2.4G / GTX 460 280.26 / 4GB Windows 7

Author: GROME Terrain Modeling for Unity, UDK, Ogre3D from PackT

Tricubic Studios Ltd. ~ Combat Helo

Link to comment
Share on other sites

That might work in a blank scene like an editor.

 

The problem is that the camera is in a busy cockpit. The goal is to have a hotkey move the camera to quickly look down at different parts of the cockpit up close.

 

screenshot2356.jpg

 

My chosen method is to dolly the camera backwards until two (or more) objects, in this case two screens, fill the viewport. The solution should be is a simple triangle problem.

 

targetAABB = combined AABB volume of required entities.

 

  bboxW = (targetAABB.w * 0.5) / tan(game.scene.camfov * 0.5) ;
  bboxH = (targetAABB.h * 0.5) / tan(game.scene.camfov * 0.5) ;
  dollyZ = max(bboxW, bboxH) ;

 

The camera is positioned at the centre of the TargetAABB volume and dollied backwards by "dollyZ"

 

  camerapos = Vec3(targetAABB.cx, targetAABB.cy, targetAABB.cz - dollyZ);

 

For the most part that works if the screen resolution/aspect ratio is square. HOWEVER...

I need a third step, adapt it for the current aspect ratio. This is where it falls down. If the screen is 3840x1024 pixels with a camera FoV of 120 degrees (a letterbox shaped screen) the top and bottom of the objects are off screen. Like this...

 

screenshot2359.jpg

 

 

I'm scratching my head on how to cram the aspect ratio into this. Changing the FoV to solve this is not allowed.

 

*update*

 

OK. Seems if I fudge the following... aspect is screenwidth / screenheight

 

  bboxW = (targetAABB.w * aspect) / tan(game.scene.camfov * 0.5) ;
  bboxH = (targetAABB.h * aspect) / tan(game.scene.camfov * 0.5) ;
  dollyZ = max(bboxW, bboxH) + 0.05 ;

 

It seems to work. 0.05 is added as a little extra. The result for our near worst case looks like this...

 

screenshot2361.jpg

 

Now I have to hide the joystick as it's getting in the way of the virtual cockpit raycasts.

Edited by Flexman

6600 2.4G / GTX 460 280.26 / 4GB Windows 7

Author: GROME Terrain Modeling for Unity, UDK, Ogre3D from PackT

Tricubic Studios Ltd. ~ Combat Helo

Link to comment
Share on other sites

I would just make pivots which are placed at each cockpit view spot. The rotation and position of the pivot determines how many surrounding instruments are seen, and it is completely aspect ratio independant, as you wouldn't ever have such aspect ratio that you couldn't even see 2 instruments. The pivot should be a bit further away anyway, since else the instruments would be too big on some screens, and that would make them as unreadable as if they were to small.

Ryzen 9 RX 6800M ■ 16GB XF8 Windows 11 ■
Ultra ■ LE 2.53DWS 5.6  Reaper ■ C/C++ C# ■ Fortran 2008 ■ Story ■
■ Homepage: https://canardia.com ■

Link to comment
Share on other sites

Yes, that's how I did it originally, pivot points all over. In practice it doesn't work out too well. When players have tripple-head devices (or even 5 screens with Eyefinity setups) things can still get clipped. What looked good on one setup was clipped on another, it became a pain adjusting things to work on different display sizes. You're dealing with objects that have vital buttons arrayed around the outer edges where any form of clipping renders the instrument near useless. So yes good in theory, practice not so much :/

 

For tutorials it's handy to be able to script "show me this instrument" or "this switch panel" and not have to setup camera positions, just add the object name.

6600 2.4G / GTX 460 280.26 / 4GB Windows 7

Author: GROME Terrain Modeling for Unity, UDK, Ogre3D from PackT

Tricubic Studios Ltd. ~ Combat Helo

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.

 Share

×
×
  • Create New...