I converted the example Blender 2.49b function to center the camera on a fixed point to the Blender 2.55 API. The problem that I have is that when using the camera to keyframe each rotation, this function sometimes rotates the camera in the wrong direction. For example,the camera will rotate from angle 3.14 to angle -2.13, even though the shorter correct angle is going from 3.14 to 4.15. This results in animations where the camera rotates all the way around instead of staying centered on the object. How do I adjust for this in this function?
def Look_At(camera, lookAt):
v1 = mathutils.Vector(lookAt)
v2 = mathutils.Vector(camera.location)
camMat = camera.matrix_world
newVec = v1 - v2
newQuat = newVec.to_track_quat('-Z', 'y')
rotMat = newQuat.to_matrix().to_4x4()
transMat = mu.Matrix.Translation(camMat.translation_part())
newMat = rotMat * transMat
camera.rotation_euler = newMat.to_euler()