Jump to content
  • Advertisement
Sign in to follow this  
Quak

Rendering n-degree bezier splines

This topic is 4940 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, i want to render a 2d bezier spline with an abitrary degree. This is the function i have written but it doesn't work like expected because pixels are drawn outside the screen. If i just render the lines from point p0 to pn it works ( n = degree ). B is the bernstein polynomial.
void CBezierSpline::Render( void ) const
{
        //rendering control lines
	for ( int i=0; i<degree; i++ )
	{
		DrawLine32( (&p0), (&p0)[i+1], grey ); 
	}

	float B, t;
	vector2 pt0, pt1;

	t = 0.1f;
	pt0 = p0;

	for ( int j=0; j < 10; j++ )
	{
                pt1 = vec2_origin; //FIXED: added this line

		for ( int k=0; k<=degree; k++ )
		{
                        //compute the polynomial where k is the index to the control point and t€[0,1]
			B = maths::nueki( degree, k ) * powf( t, k ) * powf( 1.0f - t, degree - k );
			pt1 += (&p0)[k] * B;
		}

		DrawLine32( pt0, pt1, color );

		pt0 = pt1;
                //render the curve with fixed steps of 0.1
		t += 0.1f;
	}
}
 





Can you find a mistake in my function ? thank you for your help Quak EDIT: I found the mistake and corrected the code above. [Edited by - Quak on June 10, 2005 3:54:34 PM]

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!