Polygon of transparent pixels in pascal

To detect collisions with hidden objects, the following code using zengl generates points around the edges of the texture (for development time):

tex_GetData(txtr, myData );
for h:=0 to txtr.Height-1 do
begin
    for w:=0 to txtr.Width-1  do
    begin
        if  (PByte(Ptr(myData) + w* 4 + h * realWidth * 4 +3)^>50)and (PByte(Ptr(myData) + w* 4 + h * realWidth * 4 +3)^<150) then
        begin
            inc(counter);
            if counter mod (cn)=0 then
                if cntr<>100 then
                    begin
                    inc(cntr);
                    // setlength(points,(cntr+1));

                    points[cntr].X:=w;

                    points[cntr].y:=w;

                    end ; 

The problem is creating a polygon from given points. The polygon does not rotate correctly. Now, trying to detect the first pixels along each edge, iterating through the width (from 0 to width), and each time the width increases by one height, it will iterate from the top (= 0) until pexil first becomes transparent and will reset to zero when the width increases by one before scanning the upper area. loops do not work here:

//Top
w:=1;
h:=1;

for w:=0 to texture.Width-1 do
    while(h<txtr.Height-2)do
    begin  

        if  (PByte(Ptr(myData) + w* 4 + h * realWidth * 4 +3)^)=255 then
        begin
            inc(h);

            inc(cntr);
            setlength(points,(cntr+1));
            points[cntr].X:=w;

            points[cntr].y:=h;
            continue;
        end;

        break;


    end ;

. , , , :

for i:=1 to length(points)-1 do
    begin
        pr2d_Line(points[i].X,points[i].y,points[i+1].X,points[i+1].y,$FF0000,255);
    End;

.

Update

  if  (PByte(Ptr(myData) + w* 4 + h * realWidth * 4 +3)^)=255 then

pbytearray ( [w, h] , ). , , , : , , , , . , , , , , , .

+4
source share

Source: https://habr.com/ru/post/1606171/


All Articles