lvjincheng 4 ani în urmă
părinte
comite
36daf98cd6

+ 1 - 1
Assets/BowArrow/Scripts/Bluetooth/BluetoothAim.cs

@@ -367,7 +367,7 @@ class AimHandler
         }
         if (doIdentity)
         {
-            _9Axis.SetIdentity();
+            _9Axis.SetIdentityAccordingToRecords();
             if (controlObj != null)
             {
                 controlObj.localRotation = Quaternion.identity;

+ 16 - 2
Assets/BowArrow/Scripts/Bluetooth/o09Axis.cs

@@ -69,7 +69,7 @@ public class o0MagneticCalibraterSimple//默认在无磁干扰环境下,有磁
     {
         get
         {
-            return Min != default && Max != default;
+            return Min != new Vector3(float.MaxValue, float.MaxValue, float.MaxValue) && Max != new Vector3(float.MinValue, float.MinValue, float.MinValue);
         }
         set
         {
@@ -398,7 +398,7 @@ public class o09Axis
         if (this.TimeGapOld <= 0)
             return Last.Qua;
         States.Add(new State());
-        if (States.Count > 2)
+        if (States.Count > 200)
             States.RemoveAt(0);
         var state = States.Last();
         state.Acc = Acc;
@@ -445,4 +445,18 @@ public class o09Axis
         States.Last().Qua = Quaternion.identity;
         States.Last().Variance = 0.0000001;
     }
+    
+    public void SetIdentityAccordingToRecords()
+    {
+        AccIdentity = Vector3.zero;
+        foreach (var i in States)
+            AccIdentity += i.Acc;
+        AccIdentity /= States.Count;
+        MagIdentity = Vector3.zero;
+        foreach (var i in States)
+            MagIdentity += i.Mag;
+        MagIdentity /= States.Count;
+        States.Last().Qua = Quaternion.identity;
+        States.Last().Variance = 0.0000001;
+    }
 }