Fly Me Through the Moon

In a post to Dir3d-l, the ever-helpful Toxi provides code on one way to handle camera movement in both 2D and 3D:

>>I want to implement flying from a bird’s eyepoint over a 3D landscape
>>as an animation (not user controlled). Basically I need to move the
>>camera within predetermined paths, right? Now, what is the sanest way to
>>impelement this? Has anyone done this?
> Your best bet is probably a Catmull-Rom spline: give it a number of control
> points and it makes a nice curved path between them. Here’s the code for
> drawing one into an image object – hopefully the translation into a camera
> movement should be obvious enough

i’d say so too… i’ve written a generic CR class i’ve used for a randomized camera fly-through in a game. the code is based on some java source and supports both bezier & CR type curves in 2d or 3d:

1) define the curve vertices
2) set t=0

then every frame do:

3) set camerapos to gSpline.calcCPoint(t)
4) camera.pointat(gSpline.calcCPoint(t+step_speed))
5) set t=t+step_speed

hth! k.