Browse Source

Implement pong prototype with z-axis controls

The z-axis determines where the paddles go for two plaxyers
Nick Steyer 1 year ago
parent
commit
6ab25b90a2

+ 6 - 0
.vsconfig

@@ -0,0 +1,6 @@
+{
+  "version": "1.0",
+  "components": [
+    "Microsoft.VisualStudio.Workload.ManagedGame"
+  ]
+}

+ 12 - 2
Assets/Ball.cs

@@ -1,5 +1,6 @@
 using System.Collections;
 using System.Collections.Generic;
+using System.Threading;
 using UnityEngine;
 
 public class Ball : MonoBehaviour
@@ -9,10 +10,19 @@ public class Ball : MonoBehaviour
     // Start is called before the first frame update
     void Start()
     {
+        //Thread.Sleep(5000);
         //float sx = Random.Range(0, 2) == 0 ? -1 : 1;
-        //float sy = Random.Range(0, 2) == 0 ? -1 : 1;
+        //float sz = Random.Range(0, 2) == 0 ? -1 : 1;
 
-        //GetComponent<Rigidbody>().velocity = new Vector3(speed * sx, speed * sy, 0f);
+        //GetComponent<Rigidbody>().velocity = new Vector3(speed * sx, 0f, speed * sz);
+    }
+
+    public void Init()
+    {
+        float sx = Random.Range(0, 2) == 0 ? -1 : 1;
+        float sz = Random.Range(0, 2) == 0 ? -1 : 1;
+
+        GetComponent<Rigidbody>().velocity = new Vector3(speed * sx, 0f, speed * sz);
     }
 
     // Update is called once per frame

+ 88 - 4
Assets/Scenes/BoundingBoxes.unity

@@ -489,7 +489,7 @@ Transform:
   m_GameObject: {fileID: 686810653}
   m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
   m_LocalPosition: {x: -9, y: 0, z: 0}
-  m_LocalScale: {x: 0.5, y: 3, z: 1}
+  m_LocalScale: {x: 0.5, y: 1, z: 3}
   m_ConstrainProportionsScale: 0
   m_Children: []
   m_Father: {fileID: 0}
@@ -585,7 +585,7 @@ Transform:
   m_PrefabAsset: {fileID: 0}
   m_GameObject: {fileID: 844576506}
   m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
-  m_LocalPosition: {x: 0, y: -6, z: 0}
+  m_LocalPosition: {x: 0, y: 0, z: -6}
   m_LocalScale: {x: 23, y: 1, z: 1}
   m_ConstrainProportionsScale: 0
   m_Children: []
@@ -826,7 +826,7 @@ Transform:
   m_GameObject: {fileID: 954312568}
   m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
   m_LocalPosition: {x: 9, y: 0, z: 0}
-  m_LocalScale: {x: 0.5, y: 3, z: 1}
+  m_LocalScale: {x: 0.5, y: 1, z: 3}
   m_ConstrainProportionsScale: 0
   m_Children: []
   m_Father: {fileID: 0}
@@ -922,10 +922,94 @@ Transform:
   m_PrefabAsset: {fileID: 0}
   m_GameObject: {fileID: 1310445729}
   m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
-  m_LocalPosition: {x: 0, y: 6, z: 0}
+  m_LocalPosition: {x: 0, y: 0, z: 6}
   m_LocalScale: {x: 23, y: 1, z: 1}
   m_ConstrainProportionsScale: 0
   m_Children: []
   m_Father: {fileID: 0}
   m_RootOrder: 7
   m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
+--- !u!1 &1319309825
+GameObject:
+  m_ObjectHideFlags: 0
+  m_CorrespondingSourceObject: {fileID: 0}
+  m_PrefabInstance: {fileID: 0}
+  m_PrefabAsset: {fileID: 0}
+  serializedVersion: 6
+  m_Component:
+  - component: {fileID: 1319309828}
+  - component: {fileID: 1319309827}
+  - component: {fileID: 1319309826}
+  m_Layer: 0
+  m_Name: Camera
+  m_TagString: Untagged
+  m_Icon: {fileID: 0}
+  m_NavMeshLayer: 0
+  m_StaticEditorFlags: 0
+  m_IsActive: 1
+--- !u!81 &1319309826
+AudioListener:
+  m_ObjectHideFlags: 0
+  m_CorrespondingSourceObject: {fileID: 0}
+  m_PrefabInstance: {fileID: 0}
+  m_PrefabAsset: {fileID: 0}
+  m_GameObject: {fileID: 1319309825}
+  m_Enabled: 1
+--- !u!20 &1319309827
+Camera:
+  m_ObjectHideFlags: 0
+  m_CorrespondingSourceObject: {fileID: 0}
+  m_PrefabInstance: {fileID: 0}
+  m_PrefabAsset: {fileID: 0}
+  m_GameObject: {fileID: 1319309825}
+  m_Enabled: 1
+  serializedVersion: 2
+  m_ClearFlags: 1
+  m_BackGroundColor: {r: 0.19215687, g: 0.3019608, b: 0.4745098, a: 0}
+  m_projectionMatrixMode: 1
+  m_GateFitMode: 2
+  m_FOVAxisMode: 0
+  m_SensorSize: {x: 36, y: 24}
+  m_LensShift: {x: 0, y: 0}
+  m_FocalLength: 50
+  m_NormalizedViewPortRect:
+    serializedVersion: 2
+    x: 0
+    y: 0
+    width: 1
+    height: 1
+  near clip plane: 0.3
+  far clip plane: 1000
+  field of view: 60
+  orthographic: 1
+  orthographic size: 7
+  m_Depth: 1
+  m_CullingMask:
+    serializedVersion: 2
+    m_Bits: 4294967295
+  m_RenderingPath: -1
+  m_TargetTexture: {fileID: 0}
+  m_TargetDisplay: 0
+  m_TargetEye: 3
+  m_HDR: 1
+  m_AllowMSAA: 1
+  m_AllowDynamicResolution: 0
+  m_ForceIntoRT: 0
+  m_OcclusionCulling: 1
+  m_StereoConvergence: 10
+  m_StereoSeparation: 0.022
+--- !u!4 &1319309828
+Transform:
+  m_ObjectHideFlags: 0
+  m_CorrespondingSourceObject: {fileID: 0}
+  m_PrefabInstance: {fileID: 0}
+  m_PrefabAsset: {fileID: 0}
+  m_GameObject: {fileID: 1319309825}
+  m_LocalRotation: {x: 0.7071068, y: 0, z: 0, w: 0.7071068}
+  m_LocalPosition: {x: 0, y: 10, z: 0}
+  m_LocalScale: {x: 1, y: 1, z: 1}
+  m_ConstrainProportionsScale: 0
+  m_Children: []
+  m_Father: {fileID: 0}
+  m_RootOrder: 8
+  m_LocalEulerAnglesHint: {x: 90, y: 0, z: 0}

+ 11 - 1
Assets/ZED/Examples/Object Detection/Scripts/ZED3DObjectVisualizer.cs

@@ -160,6 +160,9 @@ public class ZED3DObjectVisualizer : MonoBehaviour
         {
             zedManager.StartObjectDetection();
         }
+
+        var ball = (Ball)GameObject.Find("Sphere").GetComponent<Ball>();
+        ball.Init();
     }
 
 
@@ -193,10 +196,17 @@ public class ZED3DObjectVisualizer : MonoBehaviour
                 //Move the box into position.
                 Vector3 obj_position = dobj.Get3DWorldPosition();
 
+                Debug.Log($"count: {count}; X: {obj_position.x}; Y: {obj_position.y}; Z: {obj_position.z};");
+
                 if (!ZEDSupportFunctions.IsVector3NaN(obj_position))
                 {
                     bbox.transform.position = obj_position;
-                    bump.transform.position = obj_position;
+                    if (obj_position.z > 3 && obj_position.z < 4)
+                    {
+                        var scale = obj_position.z - 3;
+                        var newZ = scale * 8 - 4;
+                        bump.transform.position = new Vector3(bump.transform.position.x, bump.transform.position.y, newZ);
+                    }
                     if (floorBBoxPosition)
                     {
                         bbox.transform.position = new Vector3(bbox.transform.position.x, 0, bbox.transform.position.z);