Browse Source

Set Ball to human position

Nick Steyer 2 years ago
parent
commit
edb5f74b80
2 changed files with 55 additions and 52 deletions
  1. 3 3
      Assets/Ball.cs
  2. 52 49
      Assets/ZED/Examples/Object Detection/Scripts/ZED3DObjectVisualizer.cs

+ 3 - 3
Assets/Ball.cs

@@ -9,10 +9,10 @@ public class Ball : MonoBehaviour
     // Start is called before the first frame update
     void Start()
     {
-        float sx = Random.Range(0, 2) == 0 ? -1 : 1;
-        float sy = Random.Range(0, 2) == 0 ? -1 : 1;
+        //float sx = Random.Range(0, 2) == 0 ? -1 : 1;
+        //float sy = Random.Range(0, 2) == 0 ? -1 : 1;
 
-        GetComponent<Rigidbody>().velocity = new Vector3(speed * sx, speed * sy, 0f);
+        //GetComponent<Rigidbody>().velocity = new Vector3(speed * sx, speed * sy, 0f);
     }
 
     // Update is called once per frame

+ 52 - 49
Assets/ZED/Examples/Object Detection/Scripts/ZED3DObjectVisualizer.cs

@@ -175,73 +175,76 @@ public class ZED3DObjectVisualizer : MonoBehaviour
         List<int> activeids = liveBBoxes.Keys.ToList();
 
         List<DetectedObject> newobjects = dframe.GetFilteredObjectList(showONTracked, showSEARCHINGTracked, showOFFTracked);
-        foreach (DetectedObject dobj in newobjects)
+        var dobj = newobjects.FirstOrDefault();
+        if (dobj != null)
         {
             Bounds objbounds = dobj.Get3DWorldBounds();
             //Make sure the object is big enough to count. We filter out very small boxes.
-            if (objbounds.size.x < minimumWidthToDisplay || objbounds.size == Vector3.zero) continue;
-
-            //Remove the ID from the list we'll use to clear no-longer-visible boxes.
-            if (activeids.Contains(dobj.id)) activeids.Remove(dobj.id);
+            if (objbounds.size.x < minimumWidthToDisplay || objbounds.size == Vector3.zero) { }
+            {
 
-            //Get the box and update its distance value.
-            GameObject bbox = GetBBoxForObject(dobj);
+                //Remove the ID from the list we'll use to clear no-longer-visible boxes.
+                if (activeids.Contains(dobj.id)) activeids.Remove(dobj.id);
 
-            //Move the box into position.
-            Vector3 obj_position = dobj.Get3DWorldPosition();
+                //Get the box and update its distance value.
+                GameObject bbox = GetBBoxForObject(dobj);
+                GameObject ball = GameObject.Find("Sphere");
+                //Move the box into position.
+                Vector3 obj_position = dobj.Get3DWorldPosition();
 
-            if (!ZEDSupportFunctions.IsVector3NaN(obj_position))
-            {
-                bbox.transform.position = obj_position;
-                if (floorBBoxPosition)
+                if (!ZEDSupportFunctions.IsVector3NaN(obj_position))
                 {
-                    bbox.transform.position = new Vector3(bbox.transform.position.x, 0, bbox.transform.position.z);
+                    bbox.transform.position = obj_position;
+                    ball.transform.position = obj_position;
+                    if (floorBBoxPosition)
+                    {
+                        bbox.transform.position = new Vector3(bbox.transform.position.x, 0, bbox.transform.position.z);
+                    }
+
+                    bbox.transform.rotation = dobj.Get3DWorldRotation(boxesFaceCamera); //Rotate them.
                 }
 
-                bbox.transform.rotation = dobj.Get3DWorldRotation(boxesFaceCamera); //Rotate them.
-            }
-
-            //Transform the box if desired.
-            if (transformBoxScale)
-            {
-                //We'll scale the object assuming that it's mesh is the default Unity cube, or something sized equally.
-                if (transformBoxToTouchFloor)
+                //Transform the box if desired.
+                if (transformBoxScale)
                 {
-                    Vector3 startscale = objbounds.size;
-                    float distfromfloor = bbox.transform.position.y - (objbounds.size.y / 2f);
-                    bbox.transform.localScale = new Vector3(objbounds.size.x, objbounds.size.y + distfromfloor, objbounds.size.z);
-                    Vector3 newpos = bbox.transform.position;
-                    newpos.y -= (distfromfloor / 2f);
-
-                    bbox.transform.position = newpos;
-
+                    //We'll scale the object assuming that it's mesh is the default Unity cube, or something sized equally.
+                    if (transformBoxToTouchFloor)
+                    {
+                        Vector3 startscale = objbounds.size;
+                        float distfromfloor = bbox.transform.position.y - (objbounds.size.y / 2f);
+                        bbox.transform.localScale = new Vector3(objbounds.size.x, objbounds.size.y + distfromfloor, objbounds.size.z);
+                        Vector3 newpos = bbox.transform.position;
+                        newpos.y -= (distfromfloor / 2f);
+
+                        bbox.transform.position = newpos;
+
+                    }
+                    else
+                    {
+                        bbox.transform.localScale = objbounds.size;
+                    }
                 }
-                else
+
+                //Now that we've adjusted position, tell the handler on the prefab to adjust distance display..
+                BBox3DHandler boxhandler = bbox.GetComponent<BBox3DHandler>();
+                if (boxhandler)
                 {
-                    bbox.transform.localScale = objbounds.size;
+                    float disttobox = Vector3.Distance(dobj.detectingZEDManager.GetLeftCameraTransform().position, dobj.Get3DWorldPosition());
+                    boxhandler.SetDistance(disttobox);
+
+                    boxhandler.UpdateBoxUVScales();
+                    boxhandler.UpdateLabelScaleAndPosition();
                 }
+
+                //DrawDebugBox(dobj);
             }
 
-            //Now that we've adjusted position, tell the handler on the prefab to adjust distance display..
-            BBox3DHandler boxhandler = bbox.GetComponent<BBox3DHandler>();
-            if (boxhandler)
+            //Remove boxes for objects that the ZED can no longer see.
+            foreach (int id in activeids)
             {
-                float disttobox = Vector3.Distance(dobj.detectingZEDManager.GetLeftCameraTransform().position, dobj.Get3DWorldPosition());
-                boxhandler.SetDistance(disttobox);
-
-                boxhandler.UpdateBoxUVScales();
-                boxhandler.UpdateLabelScaleAndPosition();
+                ReturnBoxToPool(id, liveBBoxes[id]);
             }
-
-            //DrawDebugBox(dobj);
         }
-
-        //Remove boxes for objects that the ZED can no longer see.
-        foreach (int id in activeids)
-        {
-            ReturnBoxToPool(id, liveBBoxes[id]);
-        }
-
     }
 
     /// <summary>