
this works only for models with a rectangular bounding box, but to support irregular ones, just calculate the following steps for y and z and use the bigger distance of both.
first we want to get the distance from the camera to the front face of the bounding box. To do this we are using a little bit of algebra on the shown triangle:
the tangent of half the camera.arc gives you half the size of the opposite leg, if the the adjacent leg is 1
to get the size of the opposite leg for an arbitrary length, we just have to multiply it with it.
x = dist*tan(camera.arc/2)
now we just have to transpose this formula to get the distance:
dist = x/tan(camera.arc/2)
in our case x ist half the modelsize
Now there is one last step we have to take: add the distance from the face to the origin to it.
The code (didn't test it, so if it doesn't work find my mistakes =P) should be something like this:
float modelSize = (my.max_y-my.min_y)*0.5;
camDist = modelSize/tanv(camera.arc*0.5);
camDist += my.max_x;
vec_set(my.x, vector(camDist, 0, 0));
vec_rotate(my.x, camera.pan);
vec_add(my.x, camera.x);
vec_set(my.pan, camera.pan);
vec_inverse(my.pan);(
Maybe it's a little clearer now?^^
Scorpion
edit: of course you can also change the scale of the model instead of moving it to the right position. It's your choice.