Allegro.cc Forums » Programming Questions » Bezier curve thingy..

 This thread is locked; no one can reply to it.
 Bezier curve thingy..
 Richard Phipps Member #1,632 November 2001 Ok,Following on for an earlier conversation with 23yrold.This is a link to some bezier curve code http://www.allegro.cc/go.php?http://agdn.netfirms.com/html/bezier.htmI have integrated the code into StylePaint, but it still draws straight lines. I take it the original code is correct?hmm...confused.
 miran Member #2,407 June 2002 Aren't you supposed to be watching football right now? Manchaster is leading 1:0, you know...on topic: while you're doing Bézier curves you could also do B-splines in general (Béziers are just a special case of B-splines). I think it would be a really cool feature and probably not to difficult to implement. I have some code if you want... --sig used to be here
 Richard Phipps Member #1,632 November 2001 It's 2-0 now!I'm watching football, drinking beer and programming. And getting confused!It seems that it's only drawing a line between control points 0 and 4.Here's one of the functions I'm using. No C++```int find_curve_x_point(float c) { float x; x = (control_point[0].x*(c * c * c) + control_point[1].x*(3 * c * c * (1 - c)) + control_point[2].x*(3 * c * (1 - c) * (1 - c)) + control_point[3].x*((1 - c) * (1 - c) * (1 - c))); return (int)x; } ``` Does that look ok?The problem is I was good at maths when I was in school, but I've forgotten it all now!
 miran Member #2,407 June 2002 Yeah that looks OK. Question is, are you using it the right way... The c parameter should be a real number going from 0.0 to 1.0 (in a for loop that calls the function you have).off topic: I'm watching Milan:Bayern myself. It's 2:1, Inzaghi scored another goal (now he has 8 goals in 4 matches!) --sig used to be here
 Richard Phipps Member #1,632 November 2001 So Bayern are going to crash out?? I've worked out the problem. It's actually working correctly, BUT I thought that control points 1 & 2 would lie on the actual drawn curve. Instead they act like real control points. DOH! Guess the words 'control point' gave it away eh?Any idea how to modify it so the control points lie on the curve? I hate trying to draw curves in a paint program where you have to move control points which are miles/kilometres away from the line.Cheers,Rich.
 miran Member #2,407 June 2002 Well, that's the thing with Bézier curves, only the first and the last control points are actually on the curve, the curve just goes approximately in the direction of all the others (there can be any number of them in general). And that's where B-splines come in. If you move one control point the entire Bézier curve changes but if you have a B-Spline only a small part of the curve around that point is changed. --sig used to be here
 Richard Phipps Member #1,632 November 2001 And do B-Splines lie on the drawn curve?Is your B-spline code in C or C++?
 miran Member #2,407 June 2002 No they're not (but they come closer). You wouldn't want the curve to go through the control points anyway because with most algorithms you will end up with a curve that oscilates way too much, the curve will go from point A to point B but may do all sorts of crazy things on the way. There are algorithms that tackle this but I always thought that was too complicated to be worth the effort.My code is in C (sort of) but I don't know if it will help you in any way as it is not commented or anything (means you will have to have a book or something to understand). It's not a program that does something usefull anyway, it just draws one non-periodic B-spline curve and a periodic B-spline curve on a hardcoded set of control points. It's just a little test I wrote when I was learning B-spline surfaces (as in 3D surfaces). Anyway you can temporarily get it here.Must go now, tell me tomorrow if you find it usefull... --sig used to be here
 Go to: Allegro Development Installation, Setup & Configuration Allegro.cc Comments Off-Topic Ordeals The Depot Game Design & Concepts Programming Questions Recent Threads