Say I want my mesh (no gui object) to fill 80% of the window width. How to achieve that? I know how to scale my objects to keep proper aspect ratio when resizing the window, but I also need to be able to determine the size in the screen space. Thanks in advance!
To get an object whose bounding box is X% of the screen, you’ll have to use the camera projection matrix. 2 possibilities:
- scale object without modifying its position so it fits with you need.
- move the object along the camera Z so that it fits.
For possibility 1, I’d compute the size in clipspace for 1 world unit (projected(object) minus projected (object position + vector3(0,1,0))
then compute the scale that is the proportional value of that projection to the value you want.
For example, if the clipspace size is 0.1 and you want it to be 1.6 (80% of clip space), then scale your object *16.
Note: clip space is the coordinate system used for rendering which goes from -1 to +1 on X and Y axis.
3 Likes
@Cedric, thanks, I eventually ended up projecting the matrices from world to screen space and using bounding box as a reference space to scale the source model.
2 Likes