I’ve been visiting this problem off and on for at least a year and have never found a very good solution.
I want to find the correct transformation (at run-time) that will position my model in the middle of the window such that the extents of the model are touching the left and right edges of the window and the top (and perhaps bottom) of the window. The user has the option to specify the location from which the coordinate system is viewed.
For example, if I draw the x, y, and z axis of this coordinate system, the top of the z axis touches the top of the window, and the x and y axiis rotate about this z axis and their max values touch the left and right edges of the window.
This coordinate system is right handed with Z up, a typical “data” coordinate system, not the “graphics” coordinate system with Z going to or away from the viewer.
Now the whole problem is that the domain of this coordinate system is not known until run time. I use glOrtho(xMin,xMax,yMin,…) and (after rotation) my window is not “big enough” to show the whole coordinate system.
I have tried all kinds of loops involving successive “growing” of the domain along each of the dimensions, finding where and how much to “grow” an axis by using glProject until the resultant window coordinates are within the drawing window. This has never worked the way that I’d like.
Has anyone ever solved this particular type of problem?
Any and all help is greatly appreciated!