hedgewars/uUtils.pas
changeset 7565 00568d3054d0
parent 7386 e82a076df09b
parent 7548 c7a21fc530de
child 7896 67217e6108fd
equal deleted inserted replaced
7544:a72ace943bfd 7565:00568d3054d0
    41 
    41 
    42 function  IntToStr(n: LongInt): shortstring;
    42 function  IntToStr(n: LongInt): shortstring;
    43 function  StrToInt(s: shortstring): LongInt;
    43 function  StrToInt(s: shortstring): LongInt;
    44 function  FloatToStr(n: hwFloat): shortstring;
    44 function  FloatToStr(n: hwFloat): shortstring;
    45 
    45 
    46 function  DxDy2Angle(const _dY, _dX: hwFloat): GLfloat;
    46 function  DxDy2Angle(const _dY, _dX: hwFloat): GLfloat; inline;
    47 function  DxDy2Angle32(const _dY, _dX: hwFloat): LongInt;
    47 function  DxDy2Angle32(const _dY, _dX: hwFloat): LongInt;
    48 function  DxDy2AttackAngle(const _dY, _dX: hwFloat): LongInt;
    48 function  DxDy2AttackAngle(const _dY, _dX: hwFloat): LongInt;
    49 function  DxDy2AttackAnglef(const _dY, _dX: extended): LongInt;
    49 function  DxDy2AttackAnglef(const _dY, _dX: extended): LongInt;
    50 
    50 
    51 procedure SetLittle(var r: hwFloat);
    51 procedure SetLittle(var r: hwFloat);
   184 begin
   184 begin
   185 FloatToStr:= cstr(n) + '_' + inttostr(Lo(n.QWordValue))
   185 FloatToStr:= cstr(n) + '_' + inttostr(Lo(n.QWordValue))
   186 end;
   186 end;
   187 
   187 
   188 
   188 
   189 function DxDy2Angle(const _dY, _dX: hwFloat): GLfloat;
   189 function DxDy2Angle(const _dY, _dX: hwFloat): GLfloat; inline;
   190 var dY, dX: Extended;
   190 var dY, dX: Extended;
   191 begin
   191 begin
   192 dY:= _dY.QWordValue / $100000000;
   192 dY:= hwFloat2Float(_dY);
   193 if _dY.isNegative then
   193 dX:= hwFloat2Float(_dX);
   194     dY:= - dY;
       
   195 dX:= _dX.QWordValue / $100000000;
       
   196 if _dX.isNegative then
       
   197     dX:= - dX;
       
   198 DxDy2Angle:= arctan2(dY, dX) * 180 / pi
   194 DxDy2Angle:= arctan2(dY, dX) * 180 / pi
   199 end;
   195 end;
   200 
   196 
   201 function DxDy2Angle32(const _dY, _dX: hwFloat): LongInt;
   197 function DxDy2Angle32(const _dY, _dX: hwFloat): LongInt;
   202 const _16divPI: Extended = 16/pi;
   198 const _16divPI: Extended = 16/pi;
   203 var dY, dX: Extended;
   199 var dY, dX: Extended;
   204 begin
   200 begin
   205 dY:= _dY.QWordValue / $100000000;
   201 dY:= hwFloat2Float(_dY);
   206 if _dY.isNegative then
   202 dX:= hwFloat2Float(_dX);
   207     dY:= - dY;
       
   208 dX:= _dX.QWordValue / $100000000;
       
   209 if _dX.isNegative then
       
   210     dX:= - dX;
       
   211 DxDy2Angle32:= trunc(arctan2(dY, dX) * _16divPI) and $1f
   203 DxDy2Angle32:= trunc(arctan2(dY, dX) * _16divPI) and $1f
   212 end;
   204 end;
   213 
   205 
   214 function DxDy2AttackAngle(const _dY, _dX: hwFloat): LongInt;
   206 function DxDy2AttackAngle(const _dY, _dX: hwFloat): LongInt;
   215 const MaxAngleDivPI: Extended = cMaxAngle/pi;
   207 const MaxAngleDivPI: Extended = cMaxAngle/pi;
   216 var dY, dX: Extended;
   208 var dY, dX: Extended;
   217 begin
   209 begin
   218 dY:= _dY.QWordValue / $100000000;
   210 dY:= hwFloat2Float(_dY);
   219 if _dY.isNegative then
   211 dX:= hwFloat2Float(_dX);
   220     dY:= - dY;
       
   221 dX:= _dX.QWordValue / $100000000;
       
   222 if _dX.isNegative then
       
   223     dX:= - dX;
       
   224 DxDy2AttackAngle:= trunc(arctan2(dY, dX) * MaxAngleDivPI)
   212 DxDy2AttackAngle:= trunc(arctan2(dY, dX) * MaxAngleDivPI)
   225 end;
   213 end;
   226 
   214 
   227 function DxDy2AttackAnglef(const _dY, _dX: extended): LongInt; inline;
   215 function DxDy2AttackAnglef(const _dY, _dX: extended): LongInt; inline;
   228 begin
   216 begin