Sign in to follow this  
simotix

Bezier curve question

Recommended Posts

I am trying to make a curved like and I believe what I want to do is a 'bezier curve'. What I want to do is get a texture, then curve it around about four points (I could use this as a billboarded sprite). Does anyone know where I could find a tutorial on how to do this? [Edited by - simotix on March 24, 2008 8:41:52 AM]

Share this post


Link to post
Share on other sites
Did you perhaps make a typing error?

You say you want to curve a texture around four textures. People aren't sure exactly what you want to do. :)

Share this post


Link to post
Share on other sites
Yes, you can use cubic Bezier curves to do this. The 4 points are the control points and are used in a parametric equation that defines the points on the curve. You can probably google this or find it in any reasonable text on computer graphics. Once you write the code to parametrically compute points along the Bezier curve, you can easily find a few points along the curve at which to place billboards.

Share this post


Link to post
Share on other sites
Well, I did not want to just place sprites at the location (if I did this then there would be open spaces). I want to be able to sort of "bend a texture" in the way that a bezier curve would. Should I use a pixel shader to do this?

Share this post


Link to post
Share on other sites
In order to do this, you'll need to build some geometry (i.e. triangles) that follow the curve and then texture them.

Share this post


Link to post
Share on other sites
Do you or anyone happen to know some sort of place that would show a tutorial or demo to do this? I believe I have a grasp with the math behind it, however, I do not see how this could accurately been done in DirectX. Not even with a shader.

Share this post


Link to post
Share on other sites
Well, you can't create geometry from within a vertex or pixel shader. I suppose this might be possible with a geometry shader (DX10), but I've never used them so I don't know for sure. You're probably going to have to build your geometry on the CPU.

Once you have your control points for the actual curve, you can take the first derivative to find a second curve (with one less control point) that evaluates to a tangent vector at each point on the original. This first derivative is called the hodograph, and there is a really simple method to calculate it (you can google for it). Once you have these two curves (the original and the hodograph), you can evaluate points along the curve and the corresponding tangent vectors. If you translate the points by some distance along a vector perpendicular to the tangent, and alternate to either side of the curve, you can construct a series of triangles that follows the curve and has a "width" sufficient to texture.

Hopefully this makes sense. While I haven't done exactly what you are trying to accomplish before, I have done some neat stuff with Bezier curves and it's really not as difficult as it sounds.

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