I'm searching for source code for fast bezier curve drawing. Any assistance would be appreciated!
Dan East
Dan East
A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.
struct gfxPOINT {
int nX;
int nY;
};
#define BZS 120 //Bezier Scaler for fixed point math
void DrawBezier(gfxPOINT *VertexPtr, unsigned short Color,
int XOffset, int YOffset, unsigned short *outbuf, int outbuf_w, int outbuf_h) {
//Dan: TODO: We can precalc several mults to constants that occur each iteration
//IE: VertexPtr[0].nX*(BZS*BZS*BZS)
int k=BZS/30;
int x1,x2,y1,y2;
x1 = VertexPtr[0].nX;
y1 = VertexPtr[0].nY;
for(int t=k;t<=BZS+k;t+=k){
//use Berstein polynomials
x2=(VertexPtr[0].nX*(BZS*BZS*BZS) +
t*(VertexPtr[0].nX*(-3*BZS*BZS)+t*((3*BZS)*VertexPtr[0].nX-VertexPtr[0].nX*t)))+
t*(VertexPtr[1].nX*(3*BZS*BZS)+ t*((-6*BZS)*VertexPtr[1].nX+VertexPtr[1].nX*3*t))+
t*t*(VertexPtr[2].nX*(3*BZS)-VertexPtr[2].nX*3*t)+
t*t*t*VertexPtr[3].nX;
x2/=(BZS*BZS*BZS);
y2=(VertexPtr[0].nY*(BZS*BZS*BZS) +
t*(VertexPtr[0].nY*(-3*BZS*BZS)+t*((3*BZS)*VertexPtr[0].nY-VertexPtr[0].nY*t)))+
t*(VertexPtr[1].nY*(3*BZS*BZS)+t*((-6*BZS)*VertexPtr[1].nY+ VertexPtr[1].nY*3*t))+
t*t*(VertexPtr[2].nY*(3*BZS)-VertexPtr[2].nY*3*t)+
t*t*t*VertexPtr[3].nY;
y2/=(BZS*BZS*BZS);
//draw curve segment
DrawLine(x1, y1, x2, y2, Color, XOffset, YOffset, outbuf, outbuf_w, outbuf_h);
x1 = x2;
y1 = y2;
}
}