simplify rc-plane's angle-adjustment-after-wrap code
authorsheepluva
Thu, 06 Feb 2014 19:05:22 +0100
changeset 10110 a7aed2eea727
parent 10109 91d126fbd7bd
child 10111 459bc720cea1
child 10112 275ad81e4718
simplify rc-plane's angle-adjustment-after-wrap code
hedgewars/uGearsHandlersMess.pas
--- a/hedgewars/uGearsHandlersMess.pas	Tue Feb 04 23:53:43 2014 +0400
+++ b/hedgewars/uGearsHandlersMess.pas	Thu Feb 06 19:05:22 2014 +0100
@@ -3316,25 +3316,22 @@
 var
     HHGear: PGear;
     i: LongInt;
-    dX, dY, X, Y : hwFloat;
+    dX, dY : hwFloat;
     fChanged: boolean;
     trueAngle: Longword;
     t: PGear;
 begin
-    if WorldWrap(Gear) and (WorldEdge <> weWrap) then
-        begin
-        Y.isNegative:= false;
-        Y.QWordValue:= 4294967296 * 112;
-        X.isNegative:= false;
-        X.QWordValue:= 4294967296 * 35;
-        dX.isNegative:= false;
-        dX.QWordValue:= 4294967296 * 1152;
-
-        dY:=hwAbs(Gear^.dX*4);
-        dY:= dY + hwPow(dY,3)/_6 + _3 * hwPow(dY,5) / _40 + _5 * hwPow(dY,7) / Y + X * hwPow(dY,9) / dX;
-        Gear^.Angle:= hwRound(dY*_2048 / _PI);
-        if not Gear^.dY.isNegative then Gear^.Angle:= 2048-Gear^.Angle;
-        if Gear^.dX.isNegative then Gear^.Angle:= 4096-Gear^.Angle;
+    if WorldWrap(Gear) then
+        begin
+            if (WorldEdge = weBounce) then // mirror
+                Gear^.Angle:= 4096 - Gear^.Angle
+            else if (WorldEdge = weSea) then // rotate 90 degree
+                begin
+                // sea-wrapped gears move upwards, so let's mirror angle if needed
+                if Gear^.Angle < 2048 then
+                    Gear^.Angle:= 4096 - Gear^.Angle;
+                Gear^.Angle:= (Gear^.Angle + 1024) mod 4096;
+                end;
         end;
     AllInactive := false;