   Locking Perspective Camera to Square
  Using: XNAThis is fairly simple to do with an orthographic view but using perspective I'm having a bit of trouble keeping the camera locked on a 3d box. I was thinking I could project the corners of the box and just move the camera position according to that but the amount to move all depends on the distance from the corners.Any tips?   
  I'd use a bounding sphere around the box.- sphere will have radius ''r.- sphere will be at distance 'd' from camera viewpoint, that would be the unknown.- camera has fov.and r / d = tan(fov / 2)-> d = r / tan(fov / 2)I'd place the camera at distance 'd' from the box. 'd' should also be greater than 'r', obviously. I usually use a 'look at' function to place a camera in a scene. This takes a camera position (the 'eye'), a focus point (the 'target'), and a desired 'up' direction. From that, the target would be the centre of the box, the direction of view would be (target - eye).and I'd move 'eye' like so :Quote:float r = box.radius();camera.dir = (box.centre - camera.eye);camera.dir.normalise();camera.eye = box.centre - camera.dir * (r / tan(camera.fov * 0.5f));;  alternatively, if you don't like a bounding sphere, you can calculate the projected size of the box along the camera's up and right axes, and use that as a guide to calculate the required distance.   ;  I'll try both. Thanks!   