Fit 3d model inside rect

have some problem that bothers me for some time.
I know that from math perspective it will be hard to calculate but I try to find some hacky way to have more or less acceptable result.

I have horizontal cylinder on the screen, and I would like to scale cylinder to fit plane (plane and camera is perpendicular to the screen)


its easy to calculate scale that would fit cylinder size inside rect but because of nature of perspective camera edges of cylinder are going outside react

Any ideas how to calculate scale so it would take into account perspective ? Basically FOV should be taken into account to make sure that cylinder is never outside of allowed rect space.

Ok found 1 hack.

moved cylinder back by radius size so objects are not on same z plane

1 Like