Sign in to follow this  
  • entries
    53
  • comments
    225
  • views
    69038

Curves

Sign in to follow this  
Milkshake

259 views

Prototyping on the side project continues this week as I move from collision mesh support to curves. Now I must admit, back when I was designing the basic framework for my engine, the idea of supporting curves never seriously crossed my mind. But one of the things I'm hoping to get out of this prototype is a better idea of how my engine could handle other types of games, and hopefully score some new/improved/more generalised capabilities to boot. And that is exactly where curves fit in.

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):

x

So, anyway now that I have the basic Curve shape working, I'm off to try and do something useful with it!

Cheers!
Sign in to follow this  


4 Comments


Recommended Comments

Very nice work. The last time I stuffed around with curves (for movement paths for 3D objects), I ended up using Catmull-ROM.

Share this comment


Link to comment
Curves are definitely an under appreciated art I think. I know I hadn't even looked at them up until a week ago. I read up a little on Catmull-Rom and they look pretty nifty (as I can get a smooth curve without explicitly stored tangents), so I'll definitely be adding support for these soon - so thanks for the pointer!

Share this comment


Link to comment
Didn't understand a word of that post. You lost me at "Curve". But just wanted to say I seriously like the UI in your editor.

Share this comment


Link to comment
If you compliment my editor, you can diss my curves any time you want =)

Strangely enough though, I think I enjoyed coding the editor even less than the curves. But having said that, I just got my constrain-to-curve physics working which makes me super dooper happy.

Share this comment


Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now