Explorar el Código

替换benny文件

eraser hace 4 años
padre
commit
404c660519

+ 23 - 17
Assets/BowArrow/Scripts/Bluetooth/BluetoothAim.cs

@@ -176,8 +176,6 @@ class AimHandler
     Vector3 Gyr = default;
     Vector3 Mag = default;
     o09Axis _9Axis = new o09Axis();
-    //是否校正地磁计
-    bool bAjustMagnetometer = false;
     //转换读取的数据,无符号->有符号
     float TwoByteToFloat(byte b1, byte b2) 
     {
@@ -225,24 +223,20 @@ class AimHandler
             MagCalibrationButton.onClick.AddListener(delegate {
 
                 // if (MagCalibrater.Calibration)
-                if (bAjustMagnetometer)
+                if (MagCalibrater.Calibration)
                 {
-                    // MagCalibrater.Calibration = false;
-                    bAjustMagnetometer = false;
+                    Debug.Log(MagCalibrater.Calibration);
+                    MagCalibrater.Calibration = false;
+                    Debug.Log(MagCalibrater.Calibration);
                     MagCalibrationButton.GetComponentInChildren<Text>().text = "开始地磁计校准";
-                    float[] dataFloats = new float[6];
-                    dataFloats[0] = MagCalibrater.Center.x;
-                    dataFloats[1] = MagCalibrater.Center.y;
-                    dataFloats[2] = MagCalibrater.Center.z;
-                    dataFloats[3] = MagCalibrater.Radius.x;
-                    dataFloats[4] = MagCalibrater.Radius.y;
-                    dataFloats[5] = MagCalibrater.Radius.z;
                 }
                 else
                 {
-                    // MagCalibrater.Calibration = true;
-                    bAjustMagnetometer = true;
-                    MagCalibrationButton.GetComponentInChildren<Text>().text = "停止地磁计校准";    
+                    Debug.Log(MagCalibrater.Calibration);
+                    MagCalibrater.Calibration = true;
+
+                    Debug.Log(MagCalibrater.Calibration);
+                    MagCalibrationButton.GetComponentInChildren<Text>().text = "停止地磁计校准";
                 }
             });
         }
@@ -340,8 +334,20 @@ class AimHandler
         TimeGap = ms - msOld;
         msOld = ms;
 
-        newRotation = _9Axis.Update(Acc * 10, Gyr, Mag, TimeGap);
-        
+        _9Axis.Update(Acc * 10, Gyr, Mag, TimeGap);
+        if(_9Axis.States.Count() < 10){
+            newRotation = _9Axis.States.Last().Qua;
+        }
+        else
+        {
+            int MuliteLerpCount = 10;
+            for (var i = 0;i< MuliteLerpCount;++i)
+            {
+                newRotation = Quaternion.Slerp(newRotation, _9Axis.States[_9Axis.States.Count() - MuliteLerpCount + i].Qua, 1/(i+1));
+            }
+        }
+
+
         receiveDataCount++;
         if (!hasAutoIdentity && receiveDataCount == 5) {
             doIdentity = true;

+ 7 - 6
Assets/BowArrow/Scripts/Bluetooth/o09Axis.cs

@@ -63,13 +63,13 @@ public class o0MagneticCalibraterSimple//默认在无磁干扰环境下,有磁
         this.Radius = Radius;
     }
 
-    Vector3 Min = new Vector3(float.MaxValue, float.MaxValue, float.MaxValue);
-    Vector3 Max = new Vector3(float.MinValue, float.MinValue, float.MinValue);
+    Vector3 Min = new Vector3(float.MinValue, float.MinValue, float.MinValue);
+    Vector3 Max = new Vector3(float.MaxValue, float.MaxValue, float.MaxValue);
     public bool Calibration
     {
         get
         {
-            return Min != new Vector3(float.MaxValue, float.MaxValue, float.MaxValue) && Max != new Vector3(float.MinValue, float.MinValue, float.MinValue);
+            return !(Min == new Vector3(float.MinValue, float.MinValue, float.MinValue) && Max == new Vector3(float.MaxValue, float.MaxValue, float.MaxValue));
         }
         set
         {
@@ -80,8 +80,8 @@ public class o0MagneticCalibraterSimple//默认在无磁干扰环境下,有磁
             }
             else
             {
-                Min = default;
-                Max = default;
+                Min = new Vector3(float.MinValue, float.MinValue, float.MinValue);
+                Max = new Vector3(float.MaxValue, float.MaxValue, float.MaxValue);
             }
         }
     }
@@ -106,6 +106,7 @@ public class o0MagneticCalibraterSimple//默认在无磁干扰环境下,有磁
                 Max.z = v.z;
             _Center = (Max + Min) / 2;
             _Radius = (Max - Min) / 2;
+            return v;
         }
         v -= _Center;
         v = new Vector3(v.x / _Radius.x, v.y / _Radius.y, v.z / _Radius.z);
@@ -377,7 +378,7 @@ public class o09Axis
     o0Project.Variance HardwareVarianceAcc = new o0Project.Variance(1000);
     o0Project.Variance HardwareVarianceMag = new o0Project.Variance(1000);
 
-    List<State> States = new List<State>();
+    public List<State> States = new List<State>();
 
     Vector3 AccOld;
     Vector3 GyrOld;