Rather than hacking in some special purpose dynamics code (which is more or less what the prototype needs), the plan is to define a shiny new (and re-usable) Shape called a Curve which can be re-used anywhere I might want to drive something off a Curve. This friendly chap could then be used to drive a camera through a cut scene, define a one (or even a network) of paths for the pathfinding logic, layout the racing line around a car track, set the trajectory of some particles, define the path an enemy walks along, constrain physics objects to for a flying fox or something, rendering a dynamically generated curve (like a cable), etc. And by making it a Shape, it could in theory plug in anywhere any other Shape could be used (so it would be pretty straight forward to add collidable curves, to have the path finding support both navigation meshes and navigation curves, etc).
I guess this is a good spot to stop and just warn people that this is a journal entry about one of the most boring types of geometry known to man - so if you want to stop reading here, I won't be in the least offended.
Anyway, my first task was to pick a curve representation. I quickly discarded the idea of supporting NURBS/hermite curves as just far too much work, expensive to evaluate, and just plain frustrating to layout, and settled on some basic but predictable b-splines (at least I think they're b-splines, and as no one else can see the code right now, you'll just have to take my word for it). Next I had to work out how I was going to store the data for the curve in a way my object system would be able to expose and serialise it for me. The challenge here is that I wanted my curves to be able to carry many different types of optional information (e.g. curve tangents, orientation, curve speed, camera track, curve path finding cost, curve frame time, etc) but I didn't want to have to create separate classes for each combination of data I might need. I knocked up a couple of quick prototypes, and then I realised where I'd seen this problem before: this was exactly an animation curve! I quickly derived my curve data off the animation class and I had all the channel handling and data management code for free. This also has the added bonus of allowing me to feed 3D curve data straight into the animation engine if I ever want to animate an object along a curve (e.g. camera fly throughs etc).
The final hurdle was trying to convert Maya's NURBS curves into a more basic spline equivalent. After I worked out that Maya's curves are actually parameterised from 0 to the (number of Cvs - 2) it was pretty easy to pull off the positions and tangents. The curve path between control points isn't identical, but it's good enough.
Here's the obligatory screen shot of a striking blue curve in the in-game editor (because by default, they don't render in the game itself):
So, anyway now that I have the basic Curve shape working, I'm off to try and do something useful with it!
Cheers!