فهرست منبع

设备方案,地磁相机大小自适应

lvjincheng 3 سال پیش
والد
کامیت
d74e8ed94d

+ 15 - 10
Assets/BowArrow/Scripts/Bluetooth/AimHandler.cs

@@ -192,6 +192,7 @@ public class AimHandler : MonoBehaviour
                     this.ellipseScript.setEllipseLocalScaleAndCenter(MagCalibrater._Radius, MagCalibrater._Center * ratio);
                     //设置绘制图像相机的对应位置
                     this.ellipseScript.setCameraPos(MagCalibrater._Center * ratio);
+                    this.ellipseScript.setCameraSize(MagCalibrater._Radius);
                 }
 
                 MagCalibrationButton.GetComponentInChildren<Text>().text = "开始地磁计校准";
@@ -300,16 +301,19 @@ public class AimHandler : MonoBehaviour
         float myr = TwoByteToFloat(bytes[22], bytes[21]);
         float mzr = TwoByteToFloat(bytes[24], bytes[23]);
 
-        Acc = new Vector3(-az, ay, -ax) / 32768 * 16;
-        Gyr = new Vector3(yaw, -pitch, roll) / 32768 * 2;
-        Mag = new Vector3(-z, y, x) / 32768 * 256; //旧版
-        //Acc = new Vector3(ax, ay, az) / 32768 * 16;
-        //Gyr = new Vector3(roll, pitch, yaw) / 32768 * 2;
-        //Mag = new Vector3(z, x, -y) / 32768 * 256;//第一个6+3硬件
-        //Acc = new Vector3(-az, ax, -ay) / 32768 * 16;
-        //Gyr = new Vector3(-yaw, roll, -pitch) / 32768 * 2;
-        //Mag = new Vector3(mzr, mxr, -myr) / 32768 * 256;//第二个6+3硬件
-
+        if (CommonConfig.devicePlan == 0) {
+            Acc = new Vector3(-az, ay, -ax) / 32768 * 16;
+            Gyr = new Vector3(yaw, -pitch, roll) / 32768 * 2;
+            Mag = new Vector3(-z, y, x) / 32768 * 256; //旧版
+        } else if (CommonConfig.devicePlan == 1) {
+            Acc = new Vector3(ax, ay, az) / 32768 * 16;
+            Gyr = new Vector3(roll, pitch, yaw) / 32768 * 2;
+            Mag = new Vector3(z, x, -y) / 32768 * 256;//第一个6+3硬件
+        } else if (CommonConfig.devicePlan == 2) {
+            Acc = new Vector3(-az, ax, -ay) / 32768 * 16;
+            Gyr = new Vector3(-yaw, roll, -pitch) / 32768 * 2;
+            Mag = new Vector3(mzr, mxr, -myr) / 32768 * 256;//第二个6+3硬件
+        } 
 
         AccObj.transform.GetChild(0).localPosition = Acc;
 
@@ -345,6 +349,7 @@ public class AimHandler : MonoBehaviour
                 Debug.LogWarning(_center + " == "+ _center.magnitude);
                 //设置绘制图像相机的对应位置
                 this.ellipseScript.setCameraPos(_center/2);
+                this.ellipseScript.setCameraSize(_center.magnitude);
             }
             Mag = MagCalibrater.Update(Mag);
 

+ 18 - 11
Assets/BowArrow/Scripts/Bluetooth/BluetoothAim.cs

@@ -4,22 +4,29 @@ using UnityEngine;
 using System.Collections.Generic;
 using UnityEngine.UI;
 using DG.Tweening;
-using UnityEngine.SceneManagement;
 /* 蓝牙瞄准模块 */
 public class BluetoothAim : MonoBehaviour
 {
     readonly string targetDeviceName = "Bbow_20210501";
 
-    //旧设备-服务和特征
-    readonly string targetDeviceService = "0000fff0"; //字母用小写
-    readonly string targetDeviceCharacteristicWrite = "0000fff2"; //字母用小写
-    readonly string targetDeviceCharacteristicNotify = "0000fff1"; //字母用小写
-
-    //新设备-服务和特征
-    //readonly string targetDeviceService = "6e400001"; //字母用小写
-    //readonly string targetDeviceCharacteristicWrite = "6e400002"; //字母用小写
-    //readonly string targetDeviceCharacteristicNotify = "6e400003"; //字母用小写
-
+    string targetDeviceService {
+        get {
+            if (CommonConfig.devicePlan == 0) return "0000fff0";
+            return "6e400001";
+        }
+    }
+    string targetDeviceCharacteristicWrite {
+        get {
+            if (CommonConfig.devicePlan == 0) return "0000fff2";
+            return "6e400002";
+        }
+    }
+    string targetDeviceCharacteristicNotify {
+        get {
+            if (CommonConfig.devicePlan == 0) return "0000fff1";
+            return "6e400003";
+        }
+    }
 
     BluetoothHelper bluetoothHelper;
     BluetoothHelperCharacteristic characteristicWrite;

+ 3 - 0
Assets/BowArrow/Scripts/CommonConfig.cs

@@ -10,6 +10,9 @@ public class CommonConfig
     //是否属于发布版本?-标记用于特别处理某些功能,比如屏蔽内部测试才有功能
     public static bool isReleaseVersion = false;
 
+    //设备方案
+    public static readonly int devicePlan = 0;
+
     /**环数精度小数位 */
     public static readonly int ringsPrecision = 1;
     /**箭的速度精度小数位 */

+ 29 - 12
Assets/BowArrow/test-ellipse/Ellipse.cs

@@ -13,9 +13,16 @@ public class Ellipse : MonoBehaviour
     public Transform cameraYTran;
     public Transform cameraZTran;
 
+    private Camera cameraX;
+    private Camera cameraY;
+    private Camera cameraZ;
+
     // Start is called before the first frame update
     void Start()
     {
+        cameraX = cameraXTran.GetComponent<Camera>();
+        cameraY = cameraYTran.GetComponent<Camera>();
+        cameraZ = cameraZTran.GetComponent<Camera>();
         particleSystem0 = GetComponentInChildren<ParticleSystem>();
         /*ArrayList arrayList = new ArrayList();
         for (int i = 0; i < 100000; i++) {
@@ -28,31 +35,41 @@ public class Ellipse : MonoBehaviour
         this.DrawPointCloud(arrayList);*/
     }
 
-    // Update is called once per frame
-    void Update()
-    {
-      
-    }
     //绘制椭圆的大小
     public void setEllipseLocalScaleAndCenter(Vector3 radius,Vector3 center) {
-
         this.ellipseTran.localScale = radius;
         this.ellipseTran.localPosition = center;
-
     }
 
-    //设置camera 的观测位置
-    float cameraOffsetScale = 1.0f;
     public void setCameraPos(Vector3 center)
     {
-        this.cameraXTran.localPosition = new Vector3(center.x - 10 * cameraOffsetScale, center.y, center.z);
-        this.cameraYTran.localPosition = new Vector3(center.x, center.y + 10 * cameraOffsetScale, center.z);
-        this.cameraZTran.localPosition = new Vector3(center.x, center.y, center.z - 10 * cameraOffsetScale);
+        this.cameraXTran.localPosition = new Vector3(center.x - 10, center.y, center.z);
+        this.cameraYTran.localPosition = new Vector3(center.x, center.y + 10, center.z);
+        this.cameraZTran.localPosition = new Vector3(center.x, center.y, center.z - 10);
         // this.cameraXTran.localPosition = new Vector3(this.cameraXTran.localPosition.x, center.y, center.z);
         // this.cameraYTran.localPosition = new Vector3(center.x, this.cameraYTran.localPosition.y, center.z);
         // 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();
+        vs.x = Mathf.Abs(circleSize.x); 
+        vs.y = Mathf.Abs(circleSize.y); 
+        vs.z = Mathf.Abs(circleSize.z);
+        this.cameraX.orthographicSize = Mathf.Max(circleSize.y, circleSize.z) / 2 * 1.5f; 
+        this.cameraY.orthographicSize = Mathf.Max(circleSize.x, circleSize.z) / 2 * 1.5f; 
+        this.cameraZ.orthographicSize = Mathf.Max(circleSize.x, circleSize.y) / 2 * 1.5f; 
+    }
+
 
     public void AddAndUpdatePointArray(Vector3 addPoint) {
         this.arrayList.Add(addPoint);