hedgewars/uCollisions.pas
changeset 6453 11c578d30bd3
parent 6279 7f724835ea57
child 6543 697e9b730189
equal deleted inserted replaced
6452:7c6f9b6672dc 6453:11c578d30bd3
   391 function CalcSlopeTangent(Gear: PGear; collisionX, collisionY: LongInt; var outDeltaX, outDeltaY: LongInt; TestWord: LongWord): boolean;
   391 function CalcSlopeTangent(Gear: PGear; collisionX, collisionY: LongInt; var outDeltaX, outDeltaY: LongInt; TestWord: LongWord): boolean;
   392 var ldx, ldy, rdx, rdy: LongInt;
   392 var ldx, ldy, rdx, rdy: LongInt;
   393     i, j, k, mx, my, li, ri, jfr, jto, tmpo : ShortInt;
   393     i, j, k, mx, my, li, ri, jfr, jto, tmpo : ShortInt;
   394     tmpx, tmpy: LongWord;
   394     tmpx, tmpy: LongWord;
   395     dx, dy, s: hwFloat;
   395     dx, dy, s: hwFloat;
   396     offset: Array[0..7,0..1] of ShortInt;
   396     offset: array[0..7,0..1] of ShortInt;
   397     isColl: Boolean;
   397     isColl: Boolean;
   398 
   398 
   399 begin
   399 begin
   400     dx:= Gear^.dX;
   400     dx:= Gear^.dX;
   401     dy:= Gear^.dY;
   401     dy:= Gear^.dY;
   521 end;
   521 end;
   522 
   522 
   523 function CalcSlopeBelowGear(Gear: PGear): hwFloat;
   523 function CalcSlopeBelowGear(Gear: PGear): hwFloat;
   524 var dx, dy: hwFloat;
   524 var dx, dy: hwFloat;
   525     collX, i, y, x, gx, sdx, sdy: LongInt;
   525     collX, i, y, x, gx, sdx, sdy: LongInt;
   526     isColl, succ: Boolean;
   526     isColl, bSucc: Boolean;
   527 begin
   527 begin
   528 
   528 
   529 
   529 
   530 y:= hwRound(Gear^.Y) + Gear^.Radius;
   530 y:= hwRound(Gear^.Y) + Gear^.Radius;
   531 gx:= hwRound(Gear^.X);
   531 gx:= hwRound(Gear^.X);
   558     Gear^.dX.isNegative:= (collX >= gx);
   558     Gear^.dX.isNegative:= (collX >= gx);
   559     Gear^.dY:= _1;
   559     Gear^.dY:= _1;
   560 
   560 
   561     sdx:= 0;
   561     sdx:= 0;
   562     sdy:= 0;
   562     sdy:= 0;
   563     succ := CalcSlopeTangent(Gear, collX, y, sdx, sdy, 255);
   563     bSucc := CalcSlopeTangent(Gear, collX, y, sdx, sdy, 255);
   564 
   564 
   565     // restore original dx/dy
   565     // restore original dx/dy
   566     Gear^.dX := dx;
   566     Gear^.dX := dx;
   567     Gear^.dY := dy;
   567     Gear^.dY := dy;
   568 
   568 
   569     if succ and (sdx <> 0) and (sdy <> 0) then
   569     if bSucc and (sdx <> 0) and (sdy <> 0) then
   570     begin
   570     begin
   571         dx := int2hwFloat(sdy) / (abs(sdx) + abs(sdy));
   571         dx := int2hwFloat(sdy) / (abs(sdx) + abs(sdy));
   572         dx.isNegative := (sdx * sdy) < 0;
   572         dx.isNegative := (sdx * sdy) < 0;
   573         exit (dx);
   573         exit (dx);
   574     end;
   574     end;