hedgewars/uUtils.pas
changeset 12744 058a5d373e4a
parent 12735 83d62800d215
child 12789 28782e03b8f0
equal deleted inserted replaced
12743:f45ffb4cf1e1 12744:058a5d373e4a
    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 
    60 procedure SetLittle(var r: hwFloat);
    62 procedure SetLittle(var r: hwFloat);
    61 
    63 
    62 function  Str2PChar(const s: shortstring): PChar;
    64 function  Str2PChar(const s: shortstring): PChar;
    63 function  DecodeBase64(s: shortstring): shortstring;
    65 function  DecodeBase64(s: shortstring): shortstring;
    64 
    66 
   375 function DxDy2AttackAnglef(const _dY, _dX: extended): LongInt; inline;
   377 function DxDy2AttackAnglef(const _dY, _dX: extended): LongInt; inline;
   376 begin
   378 begin
   377 DxDy2AttackAnglef:= trunc(arctan2(_dY, _dX) * (cMaxAngle/pi))
   379 DxDy2AttackAnglef:= trunc(arctan2(_dY, _dX) * (cMaxAngle/pi))
   378 end;
   380 end;
   379 
   381 
       
   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;
   380 
   413 
   381 procedure SetLittle(var r: hwFloat);
   414 procedure SetLittle(var r: hwFloat);
   382 begin
   415 begin
   383 r:= SignAs(cLittle, r)
   416 r:= SignAs(cLittle, r)
   384 end;
   417 end;