hedgewars/uLand.pas
changeset 561 19d2d422ff84
parent 547 b81a055f2d06
child 566 1c1cb593cb81
equal deleted inserted replaced
560:7bf2b554de0c 561:19d2d422ff84
   393                FillPoints^[i].y:= 1023 - FillPoints^[i].y;
   393                FillPoints^[i].y:= 1023 - FillPoints^[i].y;
   394            end;
   394            end;
   395      end
   395      end
   396 end;
   396 end;
   397 
   397 
       
   398 function CheckIntersect(V1, V2, V3, V4: TPoint): boolean;
       
   399 var c1, c2, dm: LongInt;
       
   400 begin
       
   401 dm:= (V4.y - V3.y) * (V2.x - V1.x) - (V4.x - V3.x) * (V2.y - V1.y);
       
   402 c1:= (V4.x - V3.x) * (V1.y - V3.y) - (V4.y - V3.y) * (V1.x - V3.x);
       
   403 if dm = 0 then exit(false);
       
   404 
       
   405 c2:= (V2.x - V3.x) * (V1.y - V3.y) - (V2.y - V3.y) * (V1.x - V3.x);
       
   406 if dm > 0 then
       
   407    begin
       
   408    if (c1 < 0) or (c1 > dm) then exit(false);
       
   409    if (c2 < 0) or (c2 > dm) then exit(false)
       
   410    end else
       
   411    begin
       
   412    if (c1 > 0) or (c1 < dm) then exit(false);
       
   413    if (c2 > 0) or (c2 < dm) then exit(false)
       
   414    end;
       
   415 
       
   416 //AddFileLog('1  (' + inttostr(V1.x) + ',' + inttostr(V1.y) + ')x(' + inttostr(V2.x) + ',' + inttostr(V2.y) + ')');
       
   417 //AddFileLog('2  (' + inttostr(V3.x) + ',' + inttostr(V3.y) + ')x(' + inttostr(V4.x) + ',' + inttostr(V4.y) + ')');
       
   418 CheckIntersect:= true
       
   419 end;
       
   420 
       
   421 function CheckSelfIntersect(var pa: TPixAr; ind: Longword): boolean;
       
   422 var i: Longword;
       
   423 begin
       
   424 if (ind <= 0) or (ind >= Pred(pa.Count)) then exit(false);
       
   425 for i:= 1 to pa.Count - 3 do
       
   426     if (i <= ind - 1) or (i >= ind + 2) then
       
   427       begin
       
   428       if (i <> ind - 1) and
       
   429          CheckIntersect(pa.ar[ind], pa.ar[ind - 1], pa.ar[i], pa.ar[i - 1]) then exit(true);
       
   430       if (i <> ind + 2) and
       
   431          CheckIntersect(pa.ar[ind], pa.ar[ind + 1], pa.ar[i], pa.ar[i - 1]) then exit(true);
       
   432       end;
       
   433 CheckSelfIntersect:= false
       
   434 end;
       
   435 
   398 procedure RandomizePoints(var pa: TPixAr);
   436 procedure RandomizePoints(var pa: TPixAr);
   399 const cEdge = 55;
   437 const cEdge = 55;
   400       cMinDist = 0;
   438       cMinDist = 8;
   401 var radz: array[0..Pred(cMaxEdgePoints)] of LongInt;
   439 var radz: array[0..Pred(cMaxEdgePoints)] of LongInt;
   402     i, k, dist: LongInt;
   440     i, k, dist, px, py: LongInt;
   403 begin
   441 begin
   404 radz[0]:= 0;
   442 radz[0]:= 0;
   405 for i:= 0 to Pred(pa.Count) do
   443 for i:= 0 to Pred(pa.Count) do
   406   with pa.ar[i] do
   444   with pa.ar[i] do
   407     if x <> NTPX then
   445     if x <> NTPX then
   419 
   457 
   420 for i:= 0 to Pred(pa.Count) do
   458 for i:= 0 to Pred(pa.Count) do
   421   with pa.ar[i] do
   459   with pa.ar[i] do
   422     if ((x and $FFFFF800) = 0) and ((y and $FFFFFC00) = 0) then
   460     if ((x and $FFFFF800) = 0) and ((y and $FFFFFC00) = 0) then
   423       begin
   461       begin
       
   462       px:= x;
       
   463       py:= y;
   424       x:= x + LongInt(GetRandom(7) - 3) * (radz[i] * 5 div 7) div 3;
   464       x:= x + LongInt(GetRandom(7) - 3) * (radz[i] * 5 div 7) div 3;
   425       y:= y + LongInt(GetRandom(7) - 3) * (radz[i] * 5 div 7) div 3
   465       y:= y + LongInt(GetRandom(7) - 3) * (radz[i] * 5 div 7) div 3;
       
   466       if CheckSelfIntersect(pa, i) then
       
   467          begin
       
   468          x:= px;
       
   469          y:= py
       
   470          end;
   426       end
   471       end
   427 end;
   472 end;
   428 
   473 
   429 
   474 
   430 procedure GenBlank(var Template: TEdgeTemplate);
   475 procedure GenBlank(var Template: TEdgeTemplate);
   438 
   483 
   439 SetPoints(Template, pa);
   484 SetPoints(Template, pa);
   440 for i:= 1 to Template.BezierizeCount do
   485 for i:= 1 to Template.BezierizeCount do
   441     begin
   486     begin
   442     BezierizeEdge(pa, _0_5);
   487     BezierizeEdge(pa, _0_5);
       
   488     RandomizePoints(pa);
   443     RandomizePoints(pa)
   489     RandomizePoints(pa)
   444     end;
   490     end;
   445 for i:= 1 to Template.RandPassesCount do RandomizePoints(pa);
   491 for i:= 1 to Template.RandPassesCount do RandomizePoints(pa);
   446 BezierizeEdge(pa, _0_1);
   492 BezierizeEdge(pa, _0_1);
   447 
   493