Dynamic camera placement


I’ve had a browse through the archives and have managed to get rid of quite a few bugs from doing so, but I couldn’t find anythin on this, apologies if my search technique needs work.

I’m developing motion capture data modelling software, and initially that simply means converting motion capture files to 3D co-ordinates (done) and plotting them in opengl (done).

The sequences are animating correctly, in an acceptable time, however, I can’t seem to find a way of placing the camera in a way that is able to view an entire sequence generically. With a small amount of fiddling for a particular sequence it is relatively easy to gain a good camera position, however this is just over fitting a solution for a given parameter.

Anybody have any ideas?

I’m developing in Python and this is some relevant code:

self.limits is an array of the following:

(ZXY is a bizarre artifact of mocap sequences and they are stored in that order for this reason)

print self.limits
camerax,cameray,cameraz,zmiddle = self.findCamera()
perspective = cameraz-self.limits[3]

Here is the function findCamera:

def findCamera(self):	
	temp = zeros(3)
	for i in range(2) :
	     temp[i] = self.limits[i] - self.limits[i+2]
	cameraz = (temp.max()*47.)/40.
	cameray = (self.limits[2] + self.limits[5])/2.
	camerax = (self.limits[1] + self.limits[4])/2.
	zmiddle = (self.limits[0]+self.limits[3])/2
	return camerax,cameray,cameraz,zmiddle

If your scene has a bounding sphere with radius r and the smaller of the horizontal and vertical field of view of your camera is phi you can compute the distance t at which to place the camera from the scene center by solving t * tan(phi) >= r for t.