Ejemplo n.º 1
0
    /// <summary>
    /// Start this instance.
    /// </summary>
    private void Start()
    {
        manager = GameObject.FindObjectOfType(typeof(ZEDManager)) as ZEDManager;

        if (manager && manager.GetLeftCameraTransform())
        {
            LeftCamera = manager.GetLeftCameraTransform().gameObject.GetComponent <Camera>();
        }

        zedCam  = sl.ZEDCamera.GetInstance();
        isReady = false;

        //Create a holder for all the planes
        holder                    = new GameObject();
        holder.name               = "[ZED Planes]";
        holder.transform.parent   = this.transform;
        holder.transform.position = Vector3.zero;
        holder.transform.rotation = Quaternion.identity;
        StaticBatchingUtility.Combine(holder);

        //initialize Vertices/Triangles with enough length
        planeMeshVertices  = new Vector3[65000];
        planeMeshTriangles = new int[65000];

        floorPlaneGO   = new ZEDPlaneGameObject();
        hitPlaneGOList = new List <ZEDPlaneGameObject> ();

        SetPlaneRenderer();
    }
Ejemplo n.º 2
0
    /// <summary>
    /// Creates canvas(es) and canvas elements depending on whether the ZED rig is mono (ZED_Rig_Mono)
    /// or stereo (ZED_Rig_Stereo).
    /// </summary>
    private void Awake()
    {
        zedManager    = GetComponent <ZEDManager> ();
        oldInitStatus = sl.ERROR_CODE.ERROR_CODE_LAST;
        if (!zedManager.IsStereoRig)         //Without VR, we use a Screen Space - Overlay canvas.
        {
            //Instantiate the mono warning prefab and set basic settings for it.
            warningmono = Instantiate(Resources.Load("PrefabsUI/Warning") as GameObject, transform);
            warningmono.SetActive(true);
            warningmono.GetComponent <Canvas> ().renderMode  = RenderMode.ScreenSpaceCamera;
            warningmono.GetComponent <Canvas> ().worldCamera = zedManager.GetLeftCameraTransform().GetComponent <Camera>();

            textmono       = warningmono.GetComponentInChildren <UnityEngine.UI.Text>();
            textmono.color = Color.white;

            if (!sl.ZEDCamera.CheckPlugin())
            {
                textmono.text = ZEDLogMessage.Error2Str(ZEDLogMessage.ERROR.SDK_NOT_INSTALLED);
            }
            imagemono = warningmono.transform.GetChild(0).GetChild(1).gameObject;
            imagemono.transform.parent.gameObject.SetActive(true);
            ready = false;
        }
        else //In VR, we use two Screen Space - Camera canvases, one for each eye.
        {
            //Instantiate the left warning prefab and set basic settings for it.
            warningleft = Instantiate(Resources.Load("PrefabsUI/Warning_VR") as GameObject, zedManager.GetLeftCameraTransform());
            warningleft.SetActive(true);
            warningleft.GetComponent <Canvas>().worldCamera   = zedManager.GetLeftCameraTransform().GetComponent <Camera>();
            warningleft.GetComponent <Canvas>().planeDistance = 1;
            textleft       = warningleft.GetComponentInChildren <UnityEngine.UI.Text>();
            textleft.color = Color.white;
            imageleft      = warningleft.transform.GetChild(0).GetChild(1).gameObject;
            imageleft.transform.parent.gameObject.SetActive(true);

            //Instantiate the right warning prefab and set basic settings for it.
            warningright = Instantiate(Resources.Load("PrefabsUI/Warning_VR") as GameObject, zedManager.GetRightCameraTransform());
            warningright.SetActive(true);
            warningright.GetComponent <Canvas>().worldCamera   = zedManager.GetRightCameraTransform().GetComponent <Camera>();
            warningright.GetComponent <Canvas>().planeDistance = 1;
            textright       = warningright.GetComponentInChildren <UnityEngine.UI.Text>();
            textright.color = Color.white;
            imageright      = warningright.transform.GetChild(0).GetChild(1).gameObject;
            imageright.transform.parent.gameObject.SetActive(true);

            if (!sl.ZEDCamera.CheckPlugin()) //Warn the use there's no SDK installed.
            {
                textleft.text  = ZEDLogMessage.Error2Str(ZEDLogMessage.ERROR.SDK_NOT_INSTALLED);
                textright.text = ZEDLogMessage.Error2Str(ZEDLogMessage.ERROR.SDK_NOT_INSTALLED);
            }

            ready = false;
        }
    }
Ejemplo n.º 3
0
    /// <summary>
    /// Constructor that sets up this frame and spawns DetectedObject objects for each raw ObjectData object in the frame.
    /// </summary>
    /// <param name="oframe">Raw sl.ObjectsFrame object from the SDK, that this object is an abstraction of.</param>
    /// <param name="detectingmanager">ZEDManager that represents the camera that detected this frame.</param>
    public DetectionFrame(ObjectsFrameSDK oframe, ZEDManager detectingmanager)
    {
        objectsFrame        = oframe;
        detectingZEDManager = detectingmanager;
        frameDetected       = Time.frameCount;

        Vector3    campos = detectingmanager.GetLeftCameraTransform().position;
        Quaternion camrot = detectingmanager.GetLeftCameraTransform().rotation;

        for (int i = 0; i < oframe.numObject; i++)
        {
            DetectedObject dobj = new DetectedObject(oframe.objectData[i], detectingmanager, campos, camrot);
            detObjects.Add(dobj);
        }
    }
Ejemplo n.º 4
0
    // Start is called before the first frame update
    void Start()
    {
        ZEDManager manager = FindObjectOfType(typeof(ZEDManager)) as ZEDManager;

        LeftCamera = manager.GetLeftCameraTransform().gameObject.GetComponent <Camera>();
        surfacePlacementManager = FindObjectOfType(typeof(SurfacePlacementManager)) as SurfacePlacementManager;
    }
Ejemplo n.º 5
0
 private void Update()
 {
     if (textureOverlayLeft == null && manager != null)
     {
         textureOverlayLeft = manager.GetLeftCameraTransform().GetComponent <ZEDRenderingPlane>();
     }
 }
Ejemplo n.º 6
0
    // Use this for initialization
    void Awake()
    {
        ZedManager = FindObjectOfType <ZEDManager>();
        LeftCamera = ZedManager.GetLeftCameraTransform().gameObject.GetComponent <Camera>();

        Cursor.visible = true; //Make sure cursor is visible so we can click on the world accurately.
    }
Ejemplo n.º 7
0
    // Use this for initialization
    void Awake()
    {
        ZedManager = FindObjectOfType <ZEDManager>();
        LeftCamera = ZedManager.GetLeftCameraTransform().gameObject.GetComponent <Camera>();

        // Show cursor
        Cursor.visible = true;
    }
Ejemplo n.º 8
0
    // Use this for initialization
    void Awake()
    {
        //zedManager = gameObject.transform.parent.GetComponentInChildren<ZEDManager>();
        zedManager = ZEDManager.GetInstance(sl.ZED_CAMERA_ID.CAMERA_ID_01);
        LeftCamera = zedManager.GetLeftCameraTransform().gameObject.GetComponent <Camera>();

        Cursor.visible = true; //Make sure cursor is visible so we can click on the world accurately.
    }
Ejemplo n.º 9
0
 // Use this for initialization
 void Start()
 {
     zedManager = FindObjectOfType <ZEDManager> ();
     //Set the countdown Timer;
     respawncountdown = respawnTimer;
     //Get the ZED camera
     leftcamera = zedManager.GetLeftCameraTransform().GetComponent <Camera>();
 }
Ejemplo n.º 10
0
    /// <summary>
    /// Checks nearby for valid places for the drone to move.
    /// Valid places must be in front of the player, and not intersect any objects within a reasonable tolerance.
    /// Use radiusCheckRate and percentageThreshold to tweak what counts as a valid location.
    /// </summary>
    /// <param name="newpos"></param>
    /// <returns></returns>
    private bool FindNewMovePosition(out Vector3 newpos)
    {
        //We can't move if the ZED isn't initialized.
        if (!zedManager.IsZEDReady)
        {
            newpos = transform.position;
            return(false);
        }

        Vector3 randomPosition;

        // Look Around For a New Position
        //If the Drone is on the screen, search around a smaller radius.
        //Note that we only check the primary ZEDManager because we only want the drone to spawn in front of the player anyway.
        if (ZEDSupportFunctions.CheckScreenView(transform.position, zedManager.GetLeftCamera()))
        {
            randomPosition = UnityEngine.Random.onUnitSphere * UnityEngine.Random.Range(2f, 3f) + transform.position;
        }
        else //if the drone is outside, look around a bigger radius to find a position which is inside the screen.
        {
            randomPosition = UnityEngine.Random.onUnitSphere * UnityEngine.Random.Range(4f, 5f) + transform.position;
        }

        // Look For Any Collisions Through The ZED
        bool hit = ZEDSupportFunctions.HitTestAtPoint(zedManager.zedCamera, zedManager.GetLeftCamera(), randomPosition);

        if (!hit)
        {
            newpos = transform.position;
            return(false);
        }

        //If we spawn the drone at that world point, it'll spawn inside a wall. Bring it closer by a distance of ClearRadius.
        Quaternion directiontoDrone = Quaternion.LookRotation(zedManager.GetLeftCameraTransform().position - randomPosition, Vector3.up);
        Vector3    newPosition      = randomPosition + directiontoDrone * Vector3.forward * ClearRadius;

        //Check the new position isn't too close from the camera.
        float dist = Vector3.Distance(zedManager.GetLeftCamera().transform.position, randomPosition);

        if (dist < 1f)
        {
            newpos = transform.position;
            return(false);
        }

        //Also check nearby points in a sphere of radius to make sure the whole drone has a clear space.
        if (ZEDSupportFunctions.HitTestOnSphere(zedManager.zedCamera, zedManager.GetLeftCamera(), newPosition, 1f, radiusCheckRate, percentageThreshold))
        {
            newpos = transform.position;
            return(false);
        }

        //Return true if it's made it this far and out the location we chose.
        newpos = newPosition;
        return(true);
    }
Ejemplo n.º 11
0
    /// <summary>
    /// Gets the direction that the 3D bounding box is facing, relative to the world.
    /// This is simply the opposite of the direction the camera was facing on detection.
    /// </summary>
    /// <param name="boxesfacecamera">True to artificially rotate the boxes to face the camera.</param>
    public Quaternion Get3DWorldRotation(bool boxesfacecamera)
    {
        Vector3 normal;

        if (boxesfacecamera)
        {
            normal = Get3DWorldPosition() - detectingZEDManager.GetLeftCameraTransform().position; //This makes box face camera.
        }
        else
        {
            normal = camRotationAtDetection * Vector3.forward; //This is to face the inverse of the camera's Z direction.
        }

        normal.y = 0;
        return(Quaternion.LookRotation(normal, Vector3.up));
    }
Ejemplo n.º 12
0
    private IEnumerator Start()
    {
        isMoving = false;
        //Find the left camera object if we didn't assign it at start.
        if (!LeftCamera)
        {
            zManager   = ZEDManager.Instance;
            LeftCamera = zManager.GetLeftCameraTransform().gameObject.GetComponent <Camera>();
        }

        //Finding the available VR controllers and assigning them to our List.
        yield return(new WaitForSeconds(1f));

        var trackers = FindObjectsOfType <ZEDControllerTracker>();

        foreach (ZEDControllerTracker tracker in trackers)
        {
            objectTrackers.Add(tracker);
        }

#if ZED_STEAM_VR
        if (objectTrackers.Count > 0)
        {
            for (int i = 0; i < objectTrackers.Count; i++)
            {
                if (objectTrackers[i].index >= 0)
                {
                    VRControls = true;
                }
            }
        }
#endif

#if ZED_OCULUS
        if (OVRManager.isHmdPresent)
        {
            if (OVRInput.GetConnectedControllers().ToString() == "Touch")
            {
                VRControls = true;
            }
        }
#endif
    }
Ejemplo n.º 13
0
    /// <summary>
    /// Spawns the drone.
    /// </summary>
    /// <returns>The drone.</returns>
    /// <param name="spawnPosition">Spawn position.</param>
    public Drone SpawnDrone(Vector3 spawnPosition)
    {
        //Spawn the drone
        GameObject dronego        = Instantiate(dronePrefab);
        Drone      dronecomponent = dronego.GetComponentInChildren <Drone>();

        if (!dronecomponent)
        {
            Debug.LogError("Drone prefab spawned by DroneSpawner does not contain the Drone.cs component.");
        }

        //Give the drone a reference to this object so it can clear its reference and set the timer properly when it dies
        dronecomponent.SetMySpawner(this);

        //Set the drone's transform values
        dronego.transform.position = newspawnposition;                                                                                  //Assign the random Pos generated in CheckRandomSpawnLocation();
        dronego.transform.rotation = Quaternion.LookRotation(zedManager.GetLeftCameraTransform().position - spawnPosition, Vector3.up); //Make it look at the player.

        return(dronecomponent);
    }
Ejemplo n.º 14
0
    void Awake()
    {
        if (!zedManager)
        {
            zedManager = FindObjectOfType <ZEDManager>();
        }

        //Find the left camera object if we didn't assign it at start.
        if (!leftcamera)
        {
            leftcamera = zedManager.GetLeftCameraTransform().gameObject.GetComponent <Camera>();
        }

        //Check if there is a Object Tracker on this object for VR controls.
        var tracker = GetComponent <ZEDControllerTracker>();

        if (tracker != null)
        {
            //Get the parent object of the baseball bat.
            if (transform.childCount > 1)
            {
                baseballBat = transform.GetChild(1).gameObject;
                baseballBat.SetActive(false); //Hide it by default. It'll get revealed once we place a bunny.
            }
        }
        //Instantiate the pointer prefab and assign it to our variables.
        if (pointerPrefab != null)
        {
            pointer     = Instantiate(pointerPrefab) as GameObject; //Get the Anchor/root of the pointerBead.
            placeholder = pointer.transform.GetChild(0).gameObject; //Get the laser's pointerBead.
        }
        //If we didn't set a transform for the pointer's origin position...
        if (rayOrigin == null)
        {
            rayOrigin = transform; //...then take our local position.
        }

        //Set the PlaneManager's reference to our placeholder.
        GetComponent <BunnyPlacement>().SetPlaceholder(placeholder.transform);
    }
Ejemplo n.º 15
0
    // Provides a visual indicator for the status of the camera's tracking
    // Displays the red borders if the tracking goes into a SEARCHING state (lost tracking)
    // Will reset the tracking if the camera's tracking has been lost for too long
    private void checkTracking()
    {
        if (manager.ZEDTrackingState == sl.TRACKING_STATE.TRACKING_SEARCH)
        {
            // Enable the red borders, increase bad time counter
            GetGameObjectByName("UI - Borders").SetActive(true);

            trackingInstabilityTime += Time.deltaTime;

            // If it's been in a SEARCHING state for too long, reset tracking
            if (trackingInstabilityTime >= trackingFailTime)
            {
                // Update UI element visibility
                GameObject.Find("UI - Text").transform.Find("Crosshair").gameObject.GetComponent <Text>().enabled         = false;
                GameObject.Find("UI - Text").transform.Find("Updating Tracking").gameObject.GetComponent <Text>().enabled = true;

                if (resetWithOffset)
                {
                    // Readjust the tracking to the last known position where the tracking was OK
                    zedCamera.ResetTrackingWithOffset(manager.OriginRotation, manager.OriginPosition, LeftCameraTransform.rotation, LeftCameraTransform.position);
                }
                else
                {
                    // Reset tracking to origin
                    zedCamera.ResetTracking(manager.OriginRotation, manager.OriginPosition);
                }
                trackingInstabilityTime = 0f;
            }
        }
        else if (manager.ZEDTrackingState == sl.TRACKING_STATE.TRACKING_OK)
        {
            GetGameObjectByName("UI - Borders").SetActive(false);
            GameObject.Find("UI - Text").transform.Find("Updating Tracking").gameObject.GetComponent <Text>().enabled = false;
            GameObject.Find("UI - Text").transform.Find("Crosshair").gameObject.GetComponent <Text>().enabled         = true;

            // Record last known good position to use if tracking goes bad again
            LeftCameraTransform = manager.GetLeftCameraTransform();
        }
    }
Ejemplo n.º 16
0
 /// <summary>
 /// Set the plane renderer to the cameras. Is necessary to see the planes
 /// </summary>
 public void SetPlaneRenderer()
 {
     if (manager != null)
     {
         Transform left = manager.GetLeftCameraTransform();
         if (left != null)
         {
             meshRenderer[0] = left.gameObject.GetComponent <ZEDPlaneRenderer>();
             if (!meshRenderer[0])
             {
                 meshRenderer[0] = left.gameObject.AddComponent <ZEDPlaneRenderer>();
             }
         }
         Transform right = manager.GetRightCameraTransform();
         if (right != null)
         {
             meshRenderer[1] = right.gameObject.GetComponent <ZEDPlaneRenderer>();
             if (!meshRenderer[1])
             {
                 meshRenderer[1] = right.gameObject.AddComponent <ZEDPlaneRenderer>();
             }
         }
     }
 }
Ejemplo n.º 17
0
 // Update is called once per frame
 void Update()
 {
     if (leftCamera == null)
     {
         if (manager)
         {
             leftCamera = manager.GetLeftCameraTransform().GetComponent <Camera>();
         }
     }
     if (rightCamera == null && ZEDManager.IsStereoRig)
     {
         if (manager)
         {
             rightCamera = manager.GetRightCameraTransform().GetComponent <Camera>();
         }
     }
     //Update positions and draw asteroids of type 1
     UpdatePosition(listPositionsOrigin, listPositions);
     Graphics.DrawMeshInstanced(asteroidsType1.GetComponent <MeshFilter>().sharedMesh,
                                0, asteroidsType1.GetComponent <MeshRenderer>().sharedMaterial,
                                listPositions,
                                listPositions.Length,
                                null,
                                UnityEngine.Rendering.ShadowCastingMode.Off,
                                false,
                                8,
                                leftCamera);
     if (ZEDManager.IsStereoRig)
     {
         Graphics.DrawMeshInstanced(asteroidsType1.GetComponent <MeshFilter>().sharedMesh,
                                    0,
                                    asteroidsType1.GetComponent <MeshRenderer>().sharedMaterial,
                                    listPositions,
                                    listPositions.Length,
                                    null,
                                    UnityEngine.Rendering.ShadowCastingMode.Off,
                                    false,
                                    10,
                                    rightCamera);
     }
     //Update positions and draw asteroids of type 2
     UpdatePosition(listPositionsOrigin2, listPositions2);
     Graphics.DrawMeshInstanced(asteroidsType2.GetComponent <MeshFilter>().sharedMesh,
                                0,
                                asteroidsType2.GetComponent <MeshRenderer>().sharedMaterial,
                                listPositions2,
                                listPositions2.Length,
                                null,
                                UnityEngine.Rendering.ShadowCastingMode.Off,
                                false,
                                8,
                                leftCamera);
     if (ZEDManager.IsStereoRig)
     {
         Graphics.DrawMeshInstanced(asteroidsType2.GetComponent <MeshFilter>().sharedMesh,
                                    0,
                                    asteroidsType2.GetComponent <MeshRenderer>().sharedMaterial,
                                    listPositions2,
                                    listPositions2.Length,
                                    null,
                                    UnityEngine.Rendering.ShadowCastingMode.Off,
                                    false,
                                    10,
                                    rightCamera);
     }
 }
Ejemplo n.º 18
0
 void Awake()
 {
     manager    = FindObjectOfType(typeof(ZEDManager)) as ZEDManager;
     LeftCamera = manager.GetLeftCameraTransform().gameObject.GetComponent <Camera>();
 }
Ejemplo n.º 19
0
    private void Update()
    {
        Vector3 moveAxis      = Vector3.zero; //Translation. Used by keyboard only.
        float   inputRotation = 0f;           //Applied rotation, between -1 and 1. Cumulative between keyboard and controllers.
        float   inputScale    = 0f;           //Applied scale change, either -1, 0 or 1. Cumulative between keyboard and controllers.

        //Keyboard inputs.
        if (Input.GetKey(KeyCode.LeftArrow) || Input.GetKey(KeyCode.Q))
        {
            inputRotation = -1 * (rotationSpeed * 360) * Time.deltaTime;
        }
        if (Input.GetKey(KeyCode.RightArrow) || Input.GetKey(KeyCode.E))
        {
            inputRotation = 1 * (rotationSpeed * 360) * Time.deltaTime;
        }
        if (Input.GetKey(KeyCode.UpArrow) || Input.GetKey(KeyCode.W))
        {
            moveAxis = Vector3.forward * movementSpeed * Time.deltaTime;
        }
        if (Input.GetKey(KeyCode.DownArrow) || Input.GetKey(KeyCode.S))
        {
            moveAxis = Vector3.back * movementSpeed * Time.deltaTime;
        }
        if (Input.GetKey(KeyCode.A))
        {
            moveAxis = Vector3.left * movementSpeed * Time.deltaTime;
        }
        if (Input.GetKey(KeyCode.D))
        {
            moveAxis = Vector3.right * movementSpeed * Time.deltaTime;
        }
        if (Input.GetKey(KeyCode.R))
        {
            moveAxis = Vector3.up * movementSpeed * Time.deltaTime;
        }
        if (Input.GetKey(KeyCode.F))
        {
            moveAxis = Vector3.down * movementSpeed * Time.deltaTime;
        }

        Quaternion gravity = Quaternion.identity;


        if (moveAxis != Vector3.zero)
        {
            isMoving = true;
            if (motion == RelativeMotion.Itself)
            {
                transform.Translate(moveAxis.x, moveAxis.y, moveAxis.z);
            }
            else if (motion == RelativeMotion.Camera)
            {
                gravity = Quaternion.FromToRotation(zedManager.GetZedRootTansform().up, Vector3.up);
                transform.localPosition += zedManager.GetLeftCameraTransform().right *moveAxis.x;
                transform.localPosition += zedManager.GetLeftCameraTransform().forward *moveAxis.z;
                transform.localPosition += gravity * zedManager.GetLeftCameraTransform().up *moveAxis.y;
            }
        }
        else
        {
            isMoving = false;
        }

        if (Input.GetKey(KeyCode.Mouse0))
        {
            inputScale = 1f;
        }
        else if (Input.GetKey(KeyCode.Mouse1))
        {
            inputScale = -1f;
        }

        if (zedManager)
        {
#if ZED_OCULUS
            if (UnityEngine.VR.VRSettings.loadedDeviceName == "Oculus")
            {
                if (OVRInput.GetConnectedControllers().ToString() == "Touch")
                {
                    Vector3 moveaxisoculus = new Vector3(); //Position change by controller. Added to keyboard version if both are applied.

                    if (objectTrackers.Count > 0)
                    {
                        moveaxisoculus = OVRInput.Get(OVRInput.Axis2D.PrimaryThumbstick, OVRInput.Controller.RTouch);
                        inputRotation += moveaxisoculus.x * rotationSpeed * 360 * Time.deltaTime;


                        gravity = Quaternion.FromToRotation(zedManager.GetZedRootTansform().up, Vector3.up);
                        transform.localPosition += gravity * zedManager.GetLeftCameraTransform().up *moveaxisoculus.y *movementSpeed *Time.deltaTime;

                        if (OVRInput.Get(OVRInput.Axis1D.PrimaryIndexTrigger, OVRInput.Controller.RTouch) > 0.75f)
                        {
                            inputScale = 1f;
                        }
                    }

                    if (objectTrackers.Count > 1)
                    {
                        moveaxisoculus = OVRInput.Get(OVRInput.Axis2D.PrimaryThumbstick, OVRInput.Controller.LTouch);
                        if (moveaxisoculus.x != 0 || moveaxisoculus.y != 0)
                        {
                            isMoving = true;
                            gravity  = Quaternion.FromToRotation(zedManager.GetZedRootTansform().up, Vector3.up);
                            transform.localPosition += zedManager.GetLeftCameraTransform().right *moveaxisoculus.x *movementSpeed *Time.deltaTime;
                            transform.localPosition += gravity * zedManager.GetLeftCameraTransform().forward *moveaxisoculus.y *movementSpeed *Time.deltaTime;
                        }
                        else
                        {
                            isMoving = false;
                        }

                        if (OVRInput.Get(OVRInput.Axis1D.PrimaryIndexTrigger, OVRInput.Controller.LTouch) > 0.75f)
                        {
                            inputScale = -1f;
                        }
                    }
                }

                OVRInput.Update();
            }
#endif
#if ZED_STEAM_VR
            if (UnityEngine.XR.XRSettings.loadedDeviceName == "OpenVR")
            {
                Vector3 moveaxissteamvr = new Vector3(); //Position change by controller. Added to keyboard version if both are applied.

                //Looks for any input from this controller through SteamVR.
                if (objectTrackers.Count > 0 && objectTrackers[0].index >= 0)
                {
                    //moveaxissteamvr = SteamVR_Controller.Input((int)objectTrackers[0].index).GetAxis(Valve.VR.EVRButtonId.k_EButton_Axis0);
                    moveaxissteamvr = objectTrackers[0].GetAxis(Valve.VR.EVRButtonId.k_EButton_Axis0);

                    inputRotation += moveaxissteamvr.x * rotationSpeed * 360f * Time.deltaTime;

                    gravity = Quaternion.FromToRotation(zedManager.GetZedRootTansform().up, Vector3.up);
                    transform.localPosition += gravity * zedManager.GetLeftCameraTransform().up *moveaxissteamvr.y *movementSpeed *Time.deltaTime;

                    //if (objectTrackers[0].index > 0 && SteamVR_Controller.Input((int)objectTrackers[0].index).GetHairTrigger())
                    if (objectTrackers[0].index > 0 && objectTrackers[0].GetAxis(Valve.VR.EVRButtonId.k_EButton_SteamVR_Trigger).x > 0.1f)
                    {
                        inputScale = 1f;
                    }
                }

                if (objectTrackers.Count > 1 && objectTrackers[1].index >= 0)
                {
                    //moveaxissteamvr = SteamVR_Controller.Input((int)objectTrackers[1].index).GetAxis(Valve.VR.EVRButtonId.k_EButton_Axis0);
                    moveaxissteamvr = objectTrackers[1].GetAxis(Valve.VR.EVRButtonId.k_EButton_Axis0);

                    if (moveaxissteamvr.x != 0 || moveaxissteamvr.y != 0)
                    {
                        isMoving = true;
                        gravity  = Quaternion.FromToRotation(zedManager.GetZedRootTansform().up, Vector3.up);
                        transform.localPosition += zedManager.GetLeftCameraTransform().right *moveaxissteamvr.x *movementSpeed *Time.deltaTime;
                        transform.localPosition += gravity * zedManager.GetLeftCameraTransform().forward *moveaxissteamvr.y *movementSpeed *Time.deltaTime;
                    }
                    else
                    {
                        isMoving = false;
                    }

                    //if (objectTrackers[1].index > 0 && SteamVR_Controller.Input((int)objectTrackers[1].index).GetHairTrigger())
                    if (objectTrackers[1].index > 0 && objectTrackers[1].GetAxis(Valve.VR.EVRButtonId.k_EButton_SteamVR_Trigger).x > 0.1f)
                    {
                        inputScale = -1f;
                    }
                }
            }
#endif
        }

        //Rotation
        float h = inputRotation;

        if (invertRotation)
        {
            transform.Rotate(0, h, 0);
        }
        else
        {
            transform.Rotate(0, -h, 0);
        }

        //Scale
        float s = scaleSpeed * (inputScale * Time.deltaTime);

        transform.localScale = new Vector3(transform.localScale.x + s,
                                           transform.localScale.y + s,
                                           transform.localScale.z + s);

        if (transform.localScale.x > maxScale)
        {
            transform.localScale = new Vector3(maxScale, maxScale, maxScale);
        }
        else if (transform.localScale.x < minScale)
        {
            transform.localScale = new Vector3(minScale, minScale, minScale);
        }

        //Enable/disable light if moving.
        if (spotLight != null)
        {
            SetMovementLight();
        }
    }
Ejemplo n.º 20
0
 void Start()
 {
     manager             = FindObjectOfType(typeof(ZEDManager)) as ZEDManager;
     zedCamera           = manager.zedCamera;
     LeftCameraTransform = manager.GetLeftCameraTransform();
 }
Ejemplo n.º 21
0
    private void Update()
    {
        Vector3 moveAxis      = Vector3.zero; //Translation. Used by keyboard only.
        float   inputRotation = 0f;           //Applied rotation, between -1 and 1. Cumulative between keyboard and controllers.
        float   inputScale    = 0f;           //Applied scale change, either -1, 0 or 1. Cumulative between keyboard and controllers.

        //Keyboard inputs.
        if (Input.GetKey(KeyCode.LeftArrow) || Input.GetKey(KeyCode.Q))
        {
            inputRotation = -1 * (rotationSpeed * 360) * Time.deltaTime;
        }
        if (Input.GetKey(KeyCode.RightArrow) || Input.GetKey(KeyCode.E))
        {
            inputRotation = 1 * (rotationSpeed * 360) * Time.deltaTime;
        }
        if (Input.GetKey(KeyCode.UpArrow) || Input.GetKey(KeyCode.W))
        {
            moveAxis = Vector3.forward * movementSpeed * Time.deltaTime;
        }
        if (Input.GetKey(KeyCode.DownArrow) || Input.GetKey(KeyCode.S))
        {
            moveAxis = Vector3.back * movementSpeed * Time.deltaTime;
        }
        if (Input.GetKey(KeyCode.A))
        {
            moveAxis = Vector3.left * movementSpeed * Time.deltaTime;
        }
        if (Input.GetKey(KeyCode.D))
        {
            moveAxis = Vector3.right * movementSpeed * Time.deltaTime;
        }
        if (Input.GetKey(KeyCode.R))
        {
            moveAxis = Vector3.up * movementSpeed * Time.deltaTime;
        }
        if (Input.GetKey(KeyCode.F))
        {
            moveAxis = Vector3.down * movementSpeed * Time.deltaTime;
        }

        Quaternion gravity = Quaternion.identity;


        if (moveAxis != Vector3.zero)
        {
            isMoving = true;
            if (motion == RelativeMotion.Itself)
            {
                transform.Translate(moveAxis.x, moveAxis.y, moveAxis.z);
            }
            else if (motion == RelativeMotion.Camera)
            {
                gravity = Quaternion.FromToRotation(zedManager.GetZedRootTansform().up, Vector3.up);
                transform.localPosition += zedManager.GetLeftCameraTransform().right *moveAxis.x;
                transform.localPosition += zedManager.GetLeftCameraTransform().forward *moveAxis.z;
                transform.localPosition += gravity * zedManager.GetLeftCameraTransform().up *moveAxis.y;
            }
        }
        else
        {
            isMoving = false;
        }

        if (Input.GetKey(KeyCode.Mouse0))
        {
            inputScale = 1f;
        }
        else if (Input.GetKey(KeyCode.Mouse1))
        {
            inputScale = -1f;
        }

        if (zedManager)
        {
            Vector3 moveaxis = new Vector3(); //Position change by controller. Added to keyboard version if both are applied.

            //Looks for any input from this controller through SteamVR.
            //Left controller controls rotation and increasing scale.
            if (objectTrackers.Count > 0)
            {
                moveaxis = objectTrackers[0].CheckNavigateUIAxis();
                if (Mathf.Abs(moveaxis.x) < 0.1f)
                {
                    moveaxis.x = 0;                               //Add slight deadzone.
                }
                if (Mathf.Abs(moveaxis.y) < 0.1f)
                {
                    moveaxis.y = 0;
                }
                inputRotation += moveaxis.x * rotationSpeed * 360f * Time.deltaTime;

                gravity = Quaternion.FromToRotation(zedManager.GetZedRootTansform().up, Vector3.up);
                transform.localPosition += gravity * zedManager.GetLeftCameraTransform().up *moveaxis.y *movementSpeed *Time.deltaTime;

                if (objectTrackers[0].CheckClickButton(ControllerButtonState.Held))
                {
                    inputScale = 1f;
                }
            }
            //Right controller controls translation and lowering scale.
            if (objectTrackers.Count > 1)
            {
                moveaxis = objectTrackers[1].CheckNavigateUIAxis();
                if (Mathf.Abs(moveaxis.x) < 0.1f)
                {
                    moveaxis.x = 0;                               //Add slight deadzone.
                }
                if (Mathf.Abs(moveaxis.y) < 0.1f)
                {
                    moveaxis.y = 0;
                }
                if (moveaxis.x != 0 || moveaxis.y != 0)
                {
                    isMoving = true;
                    gravity  = Quaternion.FromToRotation(zedManager.GetZedRootTansform().up, Vector3.up);
                    transform.localPosition += zedManager.GetLeftCameraTransform().right *moveaxis.x *movementSpeed *Time.deltaTime;
                    transform.localPosition += gravity * zedManager.GetLeftCameraTransform().forward *moveaxis.y *movementSpeed *Time.deltaTime;
                }
                else
                {
                    isMoving = false;
                }

                if (objectTrackers[1].CheckClickButton(ControllerButtonState.Held))
                {
                    inputScale = -1f;
                }
            }
        }

        //Rotation
        float h = inputRotation;

        if (invertRotation)
        {
            transform.Rotate(0, h, 0);
        }
        else
        {
            transform.Rotate(0, -h, 0);
        }

        //Scale
        float s = scaleSpeed * (inputScale * Time.deltaTime);

        transform.localScale = new Vector3(transform.localScale.x + s,
                                           transform.localScale.y + s,
                                           transform.localScale.z + s);

        if (transform.localScale.x > maxScale)
        {
            transform.localScale = new Vector3(maxScale, maxScale, maxScale);
        }
        else if (transform.localScale.x < minScale)
        {
            transform.localScale = new Vector3(minScale, minScale, minScale);
        }

        //Enable/disable light if moving.
        if (spotLight != null)
        {
            SetMovementLight();
        }
    }
Ejemplo n.º 22
0
    // Update is called once per frame
    void Update()
    {
        string[] names       = Input.GetJoystickNames();
        bool     hasJoystick = false;

        if (names.Length > 0)
        {
            hasJoystick = names[0].Length > 0;
        }


        /// Adjust Planetarium X/Y/Z position
        float axisH = Input.GetAxis("Horizontal");
        float axisV = Input.GetAxis("Vertical");

        Quaternion gravity = Quaternion.identity;

        gravity = Quaternion.FromToRotation(manager.GetZedRootTansform().up, Vector3.up);
        planetarium.transform.localPosition += manager.GetLeftCameraTransform().right *axisH *speedMove *Time.deltaTime;
        planetarium.transform.localPosition += gravity * manager.GetLeftCameraTransform().forward *axisV *speedMove *Time.deltaTime;

        /// Adjust Scale of Virtual objects,lights, sounds
        bool ScaleUpButton   = Input.GetButton("Fire1") || Input.GetKey(KeyCode.JoystickButton5) || (Input.GetAxis("Fire1") >= 1);
        bool ScaleDownButton = Input.GetButton("Fire2") || (Input.GetAxis("Fire2") >= 1);

        currentscale += System.Convert.ToInt32(ScaleUpButton) * speedGrowth * Time.deltaTime / scaler;
        currentscale -= System.Convert.ToInt32(ScaleDownButton) * speedGrowth * Time.deltaTime / scaler;
        if (currentscale < MIN_LIMIT_SCALE)
        {
            currentscale = MIN_LIMIT_SCALE;
        }
        if (currentscale > MAX_LIMIT_SCALE)
        {
            currentscale = MAX_LIMIT_SCALE;
        }
        planetarium.transform.localScale = new Vector3(currentscale, currentscale, currentscale);
        sunlight.range     = currentlightrange * currentscale;
        spotLightSun.range = currentlightrangesunspot * currentscale;
        halolightsun.range = currentlightrangesunhalo * currentscale;

#if __ENABLE__SOUND__
        jupiterSound.maxDistance = currentMaxSoundDistanceJupiter * currentScale;
        sunSound.maxDistance     = currentMaxSoundDistanceSun * currentScale;
#endif

        /// Adjust Rotation of Planetarium
        if (CheckAxes("DPad X") && hasJoystick)
        {
            float axisX = Input.GetAxis("DPad X"); //multiply by 10 since sensibility is at 0.1 by default
            planetarium.transform.Rotate(gravity * manager.GetLeftCameraTransform().up *axisX *speedRotation, Space.World);
        }
        else
        {
            float axisX = System.Convert.ToInt32(Input.GetKey(KeyCode.R));
            planetarium.transform.Rotate(gravity * manager.GetLeftCameraTransform().up *axisX *speedRotation, Space.World);
        }


        //adjust Height of Planetarium
        if (CheckAxes("DPad Y") && hasJoystick)
        {
            float axisY = Input.GetAxis("DPad Y");
            planetarium.transform.localPosition += gravity * manager.GetLeftCameraTransform().up *axisY *speedMove *Time.deltaTime;
        }
        else
        {
            float axisY = System.Convert.ToInt32(Input.GetKey(KeyCode.PageUp)) - System.Convert.ToInt32(Input.GetKey(KeyCode.PageDown));
            planetarium.transform.localPosition += gravity * manager.GetLeftCameraTransform().up *axisY *speedMove *Time.deltaTime;
        }
    }
Ejemplo n.º 23
0
    private void Update()
    {
        //Reposition the screen in front our the Camera when its ready
        if (ZEDManager.Instance.IsZEDReady && reposition == false)
        {
            transform.position = ZEDManager.Instance.OriginPosition + ZEDManager.Instance.OriginRotation * (Vector3.forward);
            Quaternion newRot = Quaternion.LookRotation(ZEDManager.Instance.OriginPosition - transform.position, Vector3.up);
            transform.eulerAngles = new Vector3(0, newRot.eulerAngles.y + 180, 0);
            reposition            = true;
        }

        Vector3 moveAxis = Vector3.zero;

        if (Input.GetKey(KeyCode.LeftArrow) || Input.GetKey(KeyCode.Q))
        {
            inputRotation = -1 * (RotationSpeed * 50) * Time.deltaTime;
        }
        if (Input.GetKey(KeyCode.RightArrow) || Input.GetKey(KeyCode.E))
        {
            inputRotation = 1 * (RotationSpeed * 50) * Time.deltaTime;
        }
        if (Input.GetKey(KeyCode.UpArrow) || Input.GetKey(KeyCode.W))
        {
            moveAxis = Vector3.forward * MovementSpeed * Time.deltaTime;
        }
        if (Input.GetKey(KeyCode.DownArrow) || Input.GetKey(KeyCode.S))
        {
            moveAxis = Vector3.back * MovementSpeed * Time.deltaTime;
        }
        if (Input.GetKey(KeyCode.A))
        {
            moveAxis = Vector3.left * MovementSpeed * Time.deltaTime;
        }
        if (Input.GetKey(KeyCode.D))
        {
            moveAxis = Vector3.right * MovementSpeed * Time.deltaTime;
        }
        if (Input.GetKey(KeyCode.R))
        {
            moveAxis = Vector3.up * MovementSpeed * Time.deltaTime;
        }
        if (Input.GetKey(KeyCode.F))
        {
            moveAxis = Vector3.down * MovementSpeed * Time.deltaTime;
        }

        Quaternion gravity = Quaternion.identity;

        if (!VRControls)
        {
            if (moveAxis != Vector3.zero)
            {
                isMoving = true;
                if (motion == relativeMotion.Itself)
                {
                    transform.Translate(moveAxis.x, moveAxis.y, moveAxis.z);
                }
                else if (motion == relativeMotion.Camera)
                {
                    gravity = Quaternion.FromToRotation(zManager.GetZedRootTansform().up, Vector3.up);
                    transform.localPosition += zManager.GetLeftCameraTransform().right *moveAxis.x;
                    transform.localPosition += zManager.GetLeftCameraTransform().forward *moveAxis.z;
                    transform.localPosition += gravity * zManager.GetLeftCameraTransform().up *moveAxis.y;
                }
            }
            else
            {
                isMoving = false;
            }

            if (Input.GetKey(KeyCode.Mouse0))
            {
                inputScale = 1f;
            }
            else if (Input.GetKey(KeyCode.Mouse1))
            {
                inputScale = -1f;
            }
        }
        else
        {
            if (zManager)
            {
#if ZED_OCULUS
                if (UnityEngine.VR.VRSettings.loadedDeviceName == "Oculus")
                {
                    if (OVRInput.GetConnectedControllers().ToString() == "Touch")
                    {
                        if (objectTrackers.Count > 0)
                        {
                            moveAxis      = OVRInput.Get(OVRInput.Axis2D.PrimaryThumbstick, OVRInput.Controller.RTouch);
                            inputRotation = moveAxis.x * RotationSpeed;

                            gravity = Quaternion.FromToRotation(zManager.GetZedRootTansform().up, Vector3.up);
                            transform.localPosition += gravity * zManager.GetLeftCameraTransform().up *moveAxis.y *MovementSpeed *Time.deltaTime;

                            if (OVRInput.Get(OVRInput.Axis1D.PrimaryIndexTrigger, OVRInput.Controller.RTouch) > 0.75f)
                            {
                                inputScale = 1f;
                            }
                        }

                        if (objectTrackers.Count > 1)
                        {
                            moveAxis = OVRInput.Get(OVRInput.Axis2D.PrimaryThumbstick, OVRInput.Controller.LTouch);
                            if (moveAxis.x != 0 || moveAxis.y != 0)
                            {
                                isMoving = true;
                                gravity  = Quaternion.FromToRotation(zManager.GetZedRootTansform().up, Vector3.up);
                                transform.localPosition += zManager.GetLeftCameraTransform().right *moveAxis.x *MovementSpeed *Time.deltaTime;
                                transform.localPosition += gravity * zManager.GetLeftCameraTransform().forward *moveAxis.y *MovementSpeed *Time.deltaTime;
                            }
                            else
                            {
                                isMoving = false;
                            }

                            if (OVRInput.Get(OVRInput.Axis1D.PrimaryIndexTrigger, OVRInput.Controller.LTouch) > 0.75f)
                            {
                                inputScale = -1f;
                            }
                        }
                    }

                    OVRInput.Update();
                }
#endif
#if ZED_STEAM_VR
                if (UnityEngine.VR.VRSettings.loadedDeviceName == "OpenVR")
                {
                    //Looks for any input from this controller through SteamVR
                    if (objectTrackers.Count > 0 && objectTrackers[0].index >= 0)
                    {
                        moveAxis      = SteamVR_Controller.Input((int)objectTrackers[0].index).GetAxis(Valve.VR.EVRButtonId.k_EButton_Axis0);
                        inputRotation = moveAxis.x * RotationSpeed;

                        gravity = Quaternion.FromToRotation(zManager.GetZedRootTansform().up, Vector3.up);
                        transform.localPosition += gravity * zManager.GetLeftCameraTransform().up *moveAxis.y *MovementSpeed *Time.deltaTime;

                        if (objectTrackers[0].index > 0 && SteamVR_Controller.Input((int)objectTrackers[0].index).GetHairTrigger())
                        {
                            inputScale = 1f;
                        }
                    }

                    if (objectTrackers.Count > 1 && objectTrackers[1].index >= 0)
                    {
                        moveAxis = SteamVR_Controller.Input((int)objectTrackers[1].index).GetAxis(Valve.VR.EVRButtonId.k_EButton_Axis0);

                        if (moveAxis.x != 0 || moveAxis.y != 0)
                        {
                            isMoving = true;
                            gravity  = Quaternion.FromToRotation(zManager.GetZedRootTansform().up, Vector3.up);
                            transform.localPosition += zManager.GetLeftCameraTransform().right *moveAxis.x *MovementSpeed *Time.deltaTime;
                            transform.localPosition += gravity * zManager.GetLeftCameraTransform().forward *moveAxis.y *MovementSpeed *Time.deltaTime;
                        }
                        else
                        {
                            isMoving = false;
                        }

                        if (objectTrackers[1].index > 0 && SteamVR_Controller.Input((int)objectTrackers[1].index).GetHairTrigger())
                        {
                            inputScale = -1f;
                        }
                    }
                }
#endif
            }
        }

        //Rotation
        float h = inputRotation;

        if (invertRotation)
        {
            transform.Rotate(0, h, 0);
        }
        else
        {
            transform.Rotate(0, -h, 0);
        }

        //Reset Rotation for next frame
        inputRotation = 0f;

        //Scale
        float s = ScaleSpeed * (inputScale * Time.deltaTime);

        //Reset scale for next frame
        inputScale = 0f;

        transform.localScale = new Vector3(transform.localScale.x + s,
                                           transform.localScale.y + s,
                                           transform.localScale.z + s);

        if (transform.localScale.x > maxScale)
        {
            transform.localScale = new Vector3(maxScale, maxScale, maxScale);
        }
        else if (transform.localScale.x < minScale)
        {
            transform.localScale = new Vector3(minScale, minScale, minScale);
        }

        //Enable/Disable light
        if (spotLight != null)
        {
            EnableLights();
        }
    }