C:Fast Line Algorithm

Aus Weis nix

Wechseln zu: Navigation, Suche
// Extremely Fast Line Algorithm Var D (Addition Fixed Point)
// Copyright 2001, By Po-Han Lin
//
// This algorithm is free as long as credit
// is given to its author
//
// Lastest version at http://www.edepot.com/phl.html
//
void myPixel(SURFACE* surface, int x,int y) {
        // PLOT x,y point on surface
}
void myLine(SURFACE* surface, int x, int y, int x2, int y2) {
        bool yLonger=false;
        int incrementVal, endVal;
        int shortLen=y2-y;
        int longLen=x2-x;
        if (abs(shortLen)>abs(longLen)) {
                int swap=shortLen;
                shortLen=longLen;
                longLen=swap;
                yLonger=true;
        }
        endVal=longLen;
        if (longLen<0) {
                incrementVal=-1;
                longLen=-longLen;
        } else incrementVal=1;
        int decInc;
        if (longLen==0) decInc=0;
        else decInc = (shortLen << 16) / longLen;
        int j=0;
        if (yLonger) {
                for (int i=0;i!=endVal;i+=incrementVal) {
                        myPixel(plbInfo,x+(j >> 16),y+i);
                        j+=decInc;
                }
        } else {
                for (int i=0;i!=endVal;i+=incrementVal) {
                        myPixel(plbInfo,x+i,y+(j >> 16));
                        j+=decInc;
                }
        }
}
void mySquare(SURFACE* surface,int x, int y, int x2, int y2) {
        myLine(surface,x,y,x2,y2);
        myLine(surface,x2,y2,x2+(y-y2),y2+(x2-x));
        myLine(surface,x,y,x+(y-y2),y+(x2-x));
        myLine(surface,x+(y-y2),y+(x2-x),x2+(y-y2),y2+(x2-x));
}
void myRect(SURFACE* surface, int x, int y, int x2, int y2) {
        myLine(surface,x,y,x2,y);
        myLine(surface,x2,y,x2,y2);
        myLine(surface,x2,y2,x,y2);
        myLine(surface,x,y2,x,y);
}
Persönliche Werkzeuge