-3

in this code:

Scan-line fill OpenGL/GLUT algorithm in C++

just this part: how it work can anyone explain to me what is that for ?

    void edgedetect(float x1,float y1,float x2,float y2,int *le,int *re)
{
    float temp,x,mx;
    int i;

    if(y1>y2)
    {
        temp=x1,x1=x2,x2=temp;
        temp=y1,y1=y2,y2=temp;
    }

    if(y1==y2)
        mx=x2-x1;
    else
        mx=(x2-x1)/(y2-y1);

    x=x1;

    for(i=int(y1);i<=(int)y2;i++)
    {
        if(x<(float)le[i]) le[i]=(int)x;
        if(x>(float)re[i]) re[i]=(int)x;
        x+=mx;
    }
}
Community
  • 1
  • 1
keyone2693
  • 619
  • 1
  • 4
  • 17

1 Answers1

1

It is computing the left and right edges (x coordinates) of the scan-lines. Y coordinate of a scan-line is implicitly defined as the array index of le&re. So for instance, the i'th scan-line is defined as the line from point (le[i], i) to (re[i], i).

You can imagine it as if you are horizontally scanning the scene from the bottom working your way up. And keeping x coordinates of where the scan-line hits the object first time (entering through the object on the left side) and where the scan-line hits the object second time (leaving the object from the right side).

Selçuk Cihan
  • 1,979
  • 2
  • 17
  • 30
  • 1
    It is Δx/Δy, the ratio for which, when you move one unit upwards, how much you should move in the horizontal direction. – Selçuk Cihan Dec 30 '15 at 13:11
  • for example if the y coordinates of tow points are the same(like 500).then the le[i]=x and re[i]=x so if the x1=100 & x2=300 the mx=200 but the le[i]=x and re[i]=x is it correct ? for the 500'th scan line – keyone2693 Dec 30 '15 at 13:37