I’ve got some primitive version of bezier curve drawing
routine, here it is
void DrawBezier(float ax, float ay,
float bx, float by,
float cx, float cy,
float dx, float dy, unsigned color)
{
float step = 1.0/1000.0;
for(float t=0; t<=1; t+=step)
{
float u = 1.0-t;
float a = u*u*u;
float b = 3.0*u*u*t;
float c = 3.0*u*t*t;
float d = t*t*t;
float x = ax*a + bx*b + cx*c + dx*d;
float y = ay*a + by*b + cy*c + dy*d;
SetPixel(int(x),int(y), color);
}
}
This is terribly slow because of slow float->int casting,
at least on my old pentium 4 (such casting consumes 90% of time here
really, 3k beziers/second versus 30k beziers/s when setpixel is commented).
So I got an idea to rewrite it to fixed point arthimetic but I am not
much experienced with this – how to rewrite it to fixed point?
(notice that t is in the range of 0.0 to 1.0 )
EDIT:
The second part of question: how to estimate the length of bezier
curve in pixels (pixels need to be drawn)? Got no idea
Allrite I ve done it such way
It is 3.5 x faster becouse of no float to int conversions.
When I measured times of calculations it is about 115 ms
versus 80 ms, (3k of it and on my old processor), so ints
are not so much faster here (aqbout 30% only :O )