Viewport Fitting

How can I transform an arbitrary 3D object such that it fits into the viewport centered. for example, inside the view volume with specific margins from the edges of the viewport?

Thanks.

Need to check the coordinates of the object and the camera origin.

Otherwise, keep the object fixed and then accordingly set the camera parameters so that the object gets housed in the view frustum of your camera.

Sounds to me like your problem is under-constrained, but in the interest of argument how about say maximizing the projection of a salient convex hull?

Solved. I just need to calculate a bounding volume of the object and makes it fit in the frustum based on a z-distance from the center.

Thanks.