Procházet zdrojové kódy

修改这些问题
2、校准对应关系是反的
3、按键功能感觉没有使用(单击,双击)
4、之前反馈的那个干扰问题还在,请见视频

slambb před 7 měsíci
rodič
revize
b9084b30d0

+ 2 - 6
Assets/BowArrow/DoubleScene/Scripts/GameAssistUIDoublePlayer.cs

@@ -133,9 +133,7 @@ public class GameAssistUIDoublePlayer : MonoBehaviour
             {
                 if (SceneManager.GetActiveScene().name == "InfraredGameDouble")
                 {
-                    //InfraredDemo._ins?.SetAdjustPointsOffset(PlayerType.FirstPlayer);
-                    //左边校准小点
-                    InfraredDemo._ins?.SetAdjustPointsOffset(PlayerType.SecondPlayer);
+                    InfraredDemo._ins?.SetAdjustPointsOffset(PlayerType.FirstPlayer);
                 }
                 //else
                 //{
@@ -166,9 +164,7 @@ public class GameAssistUIDoublePlayer : MonoBehaviour
             {
                 if (SceneManager.GetActiveScene().name == "InfraredGameDouble")
                 {
-                    //InfraredDemo._ins?.SetAdjustPointsOffset(PlayerType.SecondPlayer);
-                    //右边校准大点
-                    InfraredDemo._ins?.SetAdjustPointsOffset(PlayerType.FirstPlayer);
+                    InfraredDemo._ins?.SetAdjustPointsOffset(PlayerType.SecondPlayer);
                 }
                 else {
                     //使用新模式重置2p

+ 67 - 47
Assets/BowArrow/InfraredCamera/InfraredDemo.cs

@@ -259,6 +259,8 @@ public class InfraredDemo : JCUnityLib.ViewBase
     public static bool running { get => infraredCameraHelper != null; }
     private bool _inited;
 
+    Camera leftCamera = null;
+    Camera rightCamera = null;
 
     #region 参数控制
 
@@ -660,49 +662,43 @@ public class InfraredDemo : JCUnityLib.ViewBase
                 if (SB_EventSystem.ins) SB_EventSystem.ins.MoveSimulateMouseByInfrared(point);
                 //移动目标游戏
                 if (GeneratingTarget.gm != null) GeneratingTarget.gm.shootingEvent.OnPositionUpdate(point);
+
+                ShowUICrosshairs(cameraLocation, 0);
             };
+
             //双点情况下更新
             infraredCameraHelper.OnPositionUpdate2 += (Vector2[] points, Vector2[] cameraLocations) =>
             {
-                string _posText = "";
-               // HideUICrosshairs(0);
-               // HideUICrosshairs(1);
+
+                // 获取左右相机
+                if (leftCamera == null) leftCamera = GameObject.Find("BowCameraFixedFirst")?.GetComponent<Camera>();
+                if (rightCamera == null) rightCamera = GameObject.Find("BowCameraFixedSecond")?.GetComponent<Camera>();
                 float halfScreenWidth = Screen.width / 2f; // 假设为全屏宽度的一半
                 for (int i = 0; i < points.Length; i++)
                 {
                     Vector2 point = points[i];
                     // 判断是否为右屏并调整坐标
-                    if (i == 1)
-                    {
-                        point.x -= halfScreenWidth; // 同步到右屏坐标系
-                    }
+                    //if (i == 1)
+                    //{
+                    //    point.x -= halfScreenWidth; // 同步到右屏坐标系
+                    //}
 
-                    Ray ray = Camera.main.ScreenPointToRay(point);
-                    Vector3 rayEndPoint = ray.GetPoint(200);
-                    Quaternion quat = Quaternion.LookRotation(rayEndPoint - Camera.main.transform.position);
-                    if (i == 1)
+                    if (i == 0 && leftCamera != null) 
                     {
+                        Ray ray1 = leftCamera.ScreenPointToRay(point);
+                        Vector3 rayEndPoint1 = ray1.GetPoint(200);
+                        Quaternion quat = Quaternion.LookRotation(rayEndPoint1 - ray1.origin);
                         if (CameraToLook.ins != null) CameraToLook.ins.localRotation = quat;
-
-                       // ShowUICrosshairs(cameraLocations[0], 0);
-                      //  ShowGameUICrosshairs(points[0], 0);
-                        _posText += "红0:" + points[0].ToString("F2");
-
+                        ShowUICrosshairs(cameraLocations[0], 0);
                     }
-                    if (i == 0) //大点算2p
+                    if (i == 1 && rightCamera != null)  //大点算2p
                     {
-                        if (CameraToLookNew.ins != null)
-                        {
-                            Transform m_controlObj = CameraToLookNew.ins.transform;
-                            m_controlObj.localRotation = quat;
-                        }
-
-                        //ShowUICrosshairs(cameraLocations[1], 1);
-                       // ShowGameUICrosshairs(points[1], 1);
-                        _posText += "\n";
-                        _posText += "黄1:" + points[1].ToString("F2");
+                        Ray ray2 = rightCamera.ScreenPointToRay(point);
+                        Vector3 rayEndPoint2 = ray2.GetPoint(200);
+                        Quaternion quat = Quaternion.LookRotation(rayEndPoint2 - ray2.origin);
+                        if (CameraToLookNew.ins != null) CameraToLookNew.ins.localRotation2P = quat;
+                        ShowUICrosshairs(cameraLocations[1], 1);
                     }
-                   // if (PosInfo) PosInfo.text = _posText;
                 }
 
             };
@@ -955,25 +951,25 @@ public class InfraredDemo : JCUnityLib.ViewBase
         if (ScreenLocate.Main)
         {
             var _sl = ScreenLocate.Main;
-            var buffer = _sl.infraredSpotBuffer;
-            if (buffer != null)
-            {
-                for (int i = 0; i < buffer.Length; i++)
-                {
-                    if (buffer[i].CameraLocation != null)
-                    {
-                        //添加一个偏移量,使得最后输出的准心是指向正中心
-                        Vector2 newPoint2 = _sl.GetOffsetCameraLocation(buffer[i].CameraLocation.Value);
-                        // 检测到光点 
-                        var pos = newPoint2.pixelToLocalPosition_AnchorCenter(_sl.mUVCCameraInfo.Size, _cameraRender.rectTransform.rect);
-                        _crosshairsInCamera[i].gameObject.SetActive(true);
-                        _crosshairsInCamera[i].anchoredPosition = pos;
-
-                    }
-                    else
-                        _crosshairsInCamera[i].gameObject.SetActive(false);
-                }
-            }
+            //var buffer = _sl.infraredSpotBuffer;
+            //if (buffer != null)
+            //{
+            //    for (int i = 0; i < buffer.Length; i++)
+            //    {
+            //        if (buffer[i].CameraLocation != null)
+            //        {
+            //            //添加一个偏移量,使得最后输出的准心是指向正中心
+            //            Vector2 newPoint2 = _sl.GetOffsetCameraLocation(buffer[i].CameraLocation.Value);
+            //            // 检测到光点 
+            //            var pos = newPoint2.pixelToLocalPosition_AnchorCenter(_sl.mUVCCameraInfo.Size, _cameraRender.rectTransform.rect);
+            //            _crosshairsInCamera[i].gameObject.SetActive(true);
+            //            _crosshairsInCamera[i].anchoredPosition = pos;
+
+            //        }
+            //        else
+            //            _crosshairsInCamera[i].gameObject.SetActive(false);
+            //    }
+            //}
             //渲染固定摄像机分辨率
             SetCalibrationFixedText(_sl.mUVCCameraInfo.CurrentCalibrationResolution);
             //渲染摄像机大小
@@ -983,7 +979,31 @@ public class InfraredDemo : JCUnityLib.ViewBase
 
         }
     }
+    /// <summary>
+    /// 更新屏幕下的十字准心位置
+    /// </summary>
+    /// <param name="value"></param>
+    void ShowUICrosshairs(Vector2 newPoint2, int index)
+    {
+        ////获取一个偏移量,使得最后输出的准心是指向正中心
+        //Vector2 newPoint2 = value  - ICHelper.GetCenterOffset(value, "CameraLocation");
+        // 检测到光点 
+        var pos = newPoint2.pixelToLocalPosition_AnchorCenter(infraredCameraHelper.GetUVCCameraInfo().Size, _cameraRender.rectTransform.rect);
+        //红色为最大值则按顺序赋值,反之最小
+        int curIndex = index;
+        //if (bIdentifyRed)
+        //{
+        //    curIndex = index;
+        //}
+        //else
+        //{
+        //    curIndex = 1 - index;
+        //}
+        _crosshairsInCamera[curIndex].gameObject.SetActive(true);
+        _crosshairsInCamera[curIndex].anchoredPosition = pos;
+
 
+    }
     bool showPoints = false;
     public void SetLocatePointsToCameraRender(List<Vector2> points, float w, float h)
     {

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

@@ -881,9 +881,7 @@ public class BluetoothAim : MonoBehaviour
                 {
                     if (SceneManager.GetActiveScene().name == "InfraredGameDouble")
                     {
-                        //InfraredDemo._ins?.SetAdjustPointsOffset(PlayerType.SecondPlayer);
-                        //右边校准大点
-                        InfraredDemo._ins?.SetAdjustPointsOffset(PlayerType.FirstPlayer);
+                        InfraredDemo._ins?.SetAdjustPointsOffset(PlayerType.SecondPlayer);
                     }
                 };
             }

+ 1 - 3
Assets/BowArrow/Scripts/Expand/AutoResetView.cs

@@ -44,9 +44,7 @@ public class AutoResetView : MonoBehaviour
             {
                 if (SceneManager.GetActiveScene().name == "InfraredGameDouble")
                 {
-                    //InfraredDemo._ins?.SetAdjustPointsOffset(PlayerType.FirstPlayer);
-                    //左边校准小点
-                    InfraredDemo._ins?.SetAdjustPointsOffset(PlayerType.SecondPlayer);
+                    InfraredDemo._ins?.SetAdjustPointsOffset(PlayerType.FirstPlayer);
                 }
             };
         }

+ 1 - 1
Assets/InfraredProject/WebCamera/Script/ZIM/ScreenLocate.cs

@@ -61,7 +61,7 @@ public partial class ScreenLocate : o0InfraredCameraHandler
             return infraredSpotBuffer[0];
         }
     }
-    public InfraredSpot[] infraredSpotBuffer => infraredLocate.InfraredSpotBuffer;
+    public InfraredSpot[] infraredSpotBuffer => IsSinglePoint()?infraredLocate.InfraredSpotBuffer: infraredLocate.InfraredSpotBuffer.Reverse().ToArray();
 
     // 当前 应用/生效 的屏幕四边形数据(QuadrilateralInCamera类)
     public QuadrilateralInCamera CurrentScreenQuad => screenIdentification.Screen.QuadInCamera;