Преглед изворни кода

地磁校准自动调整相机

lvjincheng пре 3 година
родитељ
комит
1611e16cb4

+ 11 - 13
Assets/BowArrow/Scripts/Bluetooth/AimHandler.cs

@@ -142,8 +142,8 @@ public class AimHandler : MonoBehaviour
             {
                 MagCalibrater.Calibration = calibration;
                 MagCalibrationButton.GetComponentInChildren<Text>().text = "停止地磁计校准";
-                this.cMaxVector = new Vector3(0, 0, 0);
-                this.cMinVector = new Vector3(0, 0, 0);
+                this.cMaxVector = new Vector3(float.MinValue, float.MinValue, float.MinValue);
+                this.cMinVector = new Vector3(float.MaxValue, float.MaxValue, float.MaxValue);
                 this.ellipseScript.ellipseTran.gameObject.SetActive(false);
             }
             else
@@ -218,6 +218,7 @@ public class AimHandler : MonoBehaviour
                     varianceV /= listArray.Length;
                     isCalibrateMagPerfect = varianceV < 0.001;
                     Debug.Log("jc-地磁校准方差=" + varianceV);
+                    PopupMgr.ins.ShowTip("地磁校准方差 = " + varianceV);
                 }
                 #endregion
             }
@@ -337,19 +338,16 @@ public class AimHandler : MonoBehaviour
             {
                 this.ellipseScript.AddAndUpdatePointArray(Mag);
 
-                if (Mag.magnitude > this.cMaxVector.magnitude)
-                {
-                    this.cMaxVector = Mag;
-                }
-                else if (Mag.magnitude < this.cMinVector.magnitude) {
-                    this.cMinVector = Mag;
-                }
+                if (Mag.x > cMaxVector.x) cMaxVector.x = Mag.x;
+                if (Mag.y > cMaxVector.y) cMaxVector.y = Mag.y;
+                if (Mag.z > cMaxVector.z) cMaxVector.z = Mag.z;
+                if (Mag.x < cMinVector.x) cMinVector.x = Mag.x;
+                if (Mag.y < cMinVector.y) cMinVector.y = Mag.y;
+                if (Mag.z < cMinVector.z) cMinVector.z = Mag.z;
 
-                Vector3 _center = this.cMaxVector - this.cMinVector;
-                Debug.LogWarning(_center + " == "+ _center.magnitude);
                 //设置绘制图像相机的对应位置
-                this.ellipseScript.setCameraPos(_center/2);
-                this.ellipseScript.setCameraSize(_center.magnitude);
+                this.ellipseScript.setCameraPos((this.cMaxVector + this.cMinVector)/2);
+                this.ellipseScript.setCameraSize(this.cMaxVector - this.cMinVector);
             }
             Mag = MagCalibrater.Update(Mag);
 

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

@@ -235,7 +235,7 @@ public class o09AxisCS
     {
         //Quaternion qua = default;
 
-        int averageCount = Math.Max(States.Count, 50);
+        int averageCount = Math.Max(States.Count, 10);
         Vector3 aveAcc = Vector3.zero;
         Vector3 aveMag = Vector3.zero;
         for (var i = 0; i < averageCount; ++i)

+ 0 - 8
Assets/BowArrow/test-ellipse/Ellipse.cs

@@ -51,14 +51,6 @@ public class Ellipse : MonoBehaviour
         // this.cameraZTran.localPosition = new Vector3(center.x, center.y, this.cameraZTran.localPosition.z);
     }
 
-    //描绘点的时候,相机大小自适应
-    public void setCameraSize(float magLen) {
-        this.cameraX.orthographicSize 
-        = this.cameraY.orthographicSize  
-        = this.cameraZ.orthographicSize 
-        = magLen / 2 * 1.5f;
-    }
-
     //最后绘制圆的时候,相机大小自适应
     public void setCameraSize(Vector3 circleSize) {
         Vector3 vs = new Vector3();