Sign in to follow this  
Scruffytuff

OpenGL NURBS curves in XNA

Recommended Posts

Not strictly DirectX, but close. I'm trying to find a way to convert a set of 8 vertices into a closed curve under XNA. Like this: I've already achieved the effect I want using the NURBS support in OpenGL, but the project has migrated to XNA now so I'm back to the drawing board. Initially I though I could find a way to use the Curve and CurveKey classes to come up with something, but I'm struggling to find a way to get the tangents to create the effect. Any ideas? Thanks :)

Share this post


Link to post
Share on other sites
Hmm, I didn't even know there was a Curve class in XNA, so it seems I've been doing entirely too much work. I've been tinkering with a little spline lib myself that does this by adding some vertices at interpolated positions between the various control points. The number of additional vertices determine the general smoothness of the line and I obtain the interpolated positions using Vector2.CatmullRom, which conveniently doesn't require explicit tangents.

Hope this is of some help. If you're looking for a 'symmetric' tangent over a control point P1, I've found that P2 - P0 (that is, the vector from the previous control point to the next one) gives a nice approximation. I don't know for sure if it's anywhere near mathematically correct, but it works for me [smile]

Share this post


Link to post
Share on other sites
Don't worry, you haven't wasted your time. The Curve and CurveKey classes only really seem useful for simple interpolations like blending values over time. Think simple keyframe animation. I also suspect it's not going to be the fastest class given it's probably only intended to be evaluated a few times a tick.

Thanks for the Catmull-Rom tip, sounds ideal. I've also been looking into Vector2.Hermite as well, which uses 2 vectors and 2 tangents. Might also be useful.

I'm making a 2D soft-body bacteria, which can divide and bump into other bacteria and stuff, while looking all wonderful and squidgy :)

Edit: I think you're spot on about the tangent calculating, it mentions the same technique in the derivation here

Share this post


Link to post
Share on other sites

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

Sign in to follow this