hedgewars/uUtils.pas
changeset 12810 6023a4f06013
parent 12794 28782e03b8f0
child 12860 1b2b84315d27
child 13094 c9cdbf630447
equal deleted inserted replaced
12809:a889cb350930 12810:6023a4f06013
    55 function  DxDy2Angle(const _dY, _dX: hwFloat): real; inline;
    55 function  DxDy2Angle(const _dY, _dX: hwFloat): real; inline;
    56 function  DxDy2Angle32(const _dY, _dX: hwFloat): LongInt;
    56 function  DxDy2Angle32(const _dY, _dX: hwFloat): LongInt;
    57 function  DxDy2AttackAngle(const _dY, _dX: hwFloat): LongInt;
    57 function  DxDy2AttackAngle(const _dY, _dX: hwFloat): LongInt;
    58 function  DxDy2AttackAnglef(const _dY, _dX: extended): LongInt;
    58 function  DxDy2AttackAnglef(const _dY, _dX: extended): LongInt;
    59 
    59 
    60 function PointDistance(const x1, x2, y1, y2: hwFloat; checkWrap: boolean): hwFloat;
       
    61 
       
    62 procedure SetLittle(var r: hwFloat);
    60 procedure SetLittle(var r: hwFloat);
    63 
    61 
    64 function  Str2PChar(const s: shortstring): PChar;
    62 function  Str2PChar(const s: shortstring): PChar;
    65 function  DecodeBase64(s: shortstring): shortstring;
    63 function  DecodeBase64(s: shortstring): shortstring;
    66 
    64 
   377 function DxDy2AttackAnglef(const _dY, _dX: extended): LongInt; inline;
   375 function DxDy2AttackAnglef(const _dY, _dX: extended): LongInt; inline;
   378 begin
   376 begin
   379 DxDy2AttackAnglef:= trunc(arctan2(_dY, _dX) * (cMaxAngle/pi))
   377 DxDy2AttackAnglef:= trunc(arctan2(_dY, _dX) * (cMaxAngle/pi))
   380 end;
   378 end;
   381 
   379 
   382 function PointDistance(const x1, x2, y1, y2: hwFloat; checkWrap: boolean): hwFloat;
       
   383 var dist_center, dist_across: hwFloat;
       
   384 vx1, vx2, vy1, vy2: hwFloat;
       
   385 begin
       
   386     // Sort values
       
   387     vx1:= x1;
       
   388     vx2:= x2;
       
   389     vy1:= y1;
       
   390     vy2:= y2;
       
   391     if x1 < x2 then
       
   392         begin
       
   393         vx1:= x2;
       
   394         vx2:= x1;
       
   395         end;
       
   396     if y1 < y2 then
       
   397         begin
       
   398         vy1:= y2;
       
   399         vy2:= y1;
       
   400         end;
       
   401     if checkWrap and (WorldEdge = weWrap) then
       
   402         begin
       
   403         dist_center:= Distance(vx2-vx1, vy2-vy1);
       
   404         dist_across:= Distance((vx2 - int2hwFloat(LeftX)) + (int2hwFloat(RightX) - vx1), vy2-vy1);
       
   405         if (dist_across < dist_center) then
       
   406             PointDistance:= dist_across
       
   407         else
       
   408             PointDistance:= dist_center;
       
   409         end
       
   410     else
       
   411         PointDistance:= Distance(vx2-vx1, vy2-vy1);
       
   412 end;
       
   413 
   380 
   414 procedure SetLittle(var r: hwFloat);
   381 procedure SetLittle(var r: hwFloat);
   415 begin
   382 begin
   416 r:= SignAs(cLittle, r)
   383 r:= SignAs(cLittle, r)
   417 end;
   384 end;