Forráskód Böngészése

Show coordinates above person

Nick Steyer 1 éve
szülő
commit
8214f0e340

+ 29 - 9
Assets/ZED/Examples/Object Detection/Scripts/BBox3DHandler.cs

@@ -102,6 +102,10 @@ public class BBox3DHandler : MonoBehaviour
     /// </summary>
     private float currentDistance = -1f;
 
+    private float currentX;
+    private float currentY;
+    private float currentZ;
+
     /// <summary>
     /// MeshRenderer attached to this bounding box. 
     /// </summary>
@@ -167,7 +171,7 @@ public class BBox3DHandler : MonoBehaviour
     public void SetID(string id)
     {
         currentID = id;
-        UpdateText(currentID, currentDistance);
+        UpdateText(currentID, currentDistance, currentX, currentY, currentZ);
     }
 
     /// <summary>
@@ -178,7 +182,25 @@ public class BBox3DHandler : MonoBehaviour
     public void SetDistance(float dist)
     {
         currentDistance = dist;
-        UpdateText(currentID, currentDistance);
+        UpdateText(currentID, currentDistance, currentX, currentY, currentZ);
+    }
+
+    public void SetX(float x)
+    {
+        currentX = x;
+        UpdateText(currentID, currentDistance, currentX, currentY, currentZ);
+    }
+
+    public void SetY(float y)
+    {
+        currentY = y;
+        UpdateText(currentID, currentDistance, currentX, currentY, currentZ);
+    }
+
+    public void SetZ(float z)
+    {
+        currentZ = z;
+        UpdateText(currentID, currentDistance, currentX, currentY, currentZ);
     }
 
     /// <summary>
@@ -260,14 +282,12 @@ public class BBox3DHandler : MonoBehaviour
     /// <summary>
     /// Updates the text in the label based on the given ID and distance values. 
     /// </summary>
-    private void UpdateText(string id, float dist)
+    private void UpdateText(string id, float dist, float x, float y, float z)
     {
-        string newtext = "";
-        if (showID) newtext += "ID: " + id.ToString();
-        if (showID && showDistance) newtext += "\r\n";
-        if (showDistance) newtext += dist.ToString("F2") + "m";
-
-        if (text2D) text2D.text = newtext;
+        if (text2D)
+        {
+            text2D.text = $"ID: {id}\r\nDistance: {dist:0.00}\r\nX: {x:0.00}\r\nY: {y:0.00}\r\nZ: {z:0.00}";
+        }
     }
 
     /// <summary>

+ 13 - 0
Assets/ZED/Examples/Object Detection/Scripts/ZED3DObjectVisualizer.cs

@@ -314,6 +314,19 @@ public class ZED3DObjectVisualizer : MonoBehaviour
                     ReturnBoxToPool(id, liveBBoxes[id]);
                 }
 
+            //Now that we've adjusted position, tell the handler on the prefab to adjust distance display..
+            BBox3DHandler boxhandler = bbox.GetComponent<BBox3DHandler>();
+            if (boxhandler)
+            {
+                var position = dobj.Get3DWorldPosition();
+                float disttobox = Vector3.Distance(dobj.detectingZEDManager.GetLeftCameraTransform().position, position);
+                boxhandler.SetDistance(disttobox);
+                boxhandler.SetX(position.x);
+                boxhandler.SetY(position.y);
+                boxhandler.SetZ(position.z);
+
+                boxhandler.UpdateBoxUVScales();
+                boxhandler.UpdateLabelScaleAndPosition();
                 count++;
             }
         }