protected virtual void UpdateObject(  SixenseInput.Controller controller )
    {
        if ( controller.GetButtonDown( SixenseButtons.START ) )
        {
            // enable position and orientation control
            m_enabled = !m_enabled;

            // delta controller position is relative to this point
            m_baseControllerPosition = new Vector3( controller.Position.x * Sensitivity.x,
                                                    controller.Position.y * Sensitivity.y,
                                                    controller.Position.z * Sensitivity.z );

            // this is the new start position
            m_initialPosition = this.gameObject.transform.localPosition;
        }

        if ( m_enabled )
        {
            UpdatePosition( controller );
            UpdateRotation( controller );
        }
    }
    protected override void UpdateObject(SixenseInput.Controller controller)
    {
        if (m_animator == null)
            return;

        GameObject CameraBase = GameObject.Find("OVRCameraController");
        if ( CameraBase == null)
            return;

        HydraDeckCamera DeckCamera = CameraBase.GetComponentInChildren<HydraDeckCamera>();
        if (DeckCamera == null)
            return;

        if (controller.Enabled)
        {
            // Animation update
            UpdateAnimationInput(controller);
        }

        if (!m_enabled && DeckCamera.State == HydraDeckCamera.CameraState.Enabled)
        {
            // enable position and orientation control
            m_enabled = !m_enabled;
        }

        if (m_enabled)
        {
            if (controller.GetButtonDown(SixenseButtons.TRIGGER)){
                LookAtCue = true;
            }
            if (controller.GetButtonUp(SixenseButtons.TRIGGER)){
                LookAtCue = false;
            }
            if (controller.GetButtonDown(SixenseButtons.BUMPER)){
                Application.LoadLevel(0);
            }
            UpdatePosition(controller, DeckCamera);
            UpdateRotation(controller);
        }
    }
Esempio n. 3
0
    void UpdateHydraCamera(SixenseInput.Controller LeftController, SixenseInput.Controller RightController)
    {
        #region Movement
        float movementMultiplier = movementSpeed * Time.deltaTime * (RightController.GetButtonDown(SixenseButtons.TRIGGER) ? sprintMultiplier : 1.0f);

        Quaternion FullBodyRotation = StartCameraOffset * LeftController.Rotation * LeftRotationOffset;

        //lol, why doesn't Unity have a Quaternion.Normalize function?
        Quaternion rotationToFaceForward = FullBodyRotation;
        rotationToFaceForward.x = 0;
        rotationToFaceForward.z = 0;
        rotationToFaceForward = Quaternion.Lerp(rotationToFaceForward, rotationToFaceForward, 1);

        float forwardBackwardTranslation = RightController.JoystickY * movementMultiplier;
        float leftRightTranslation = RightController.JoystickX * movementMultiplier;

        Vector3 movementVector = new Vector3(leftRightTranslation, 0, forwardBackwardTranslation);
        if( movementVector != Vector3.zero )
        {
            movementVector = rotationToFaceForward * movementVector;
            movementVector.y = 0;
            targetPosition += movementVector;
        }

        Vector3 currentPosition = BodyPosition;
        if( !Approximately(currentPosition, targetPosition) )
        {
            currentPosition = Vector3.SmoothDamp(currentPosition, targetPosition, ref currentVelocity, movementSmoothingFactor, float.PositiveInfinity, Time.deltaTime);
            BodyPosition = currentPosition;
        }

        //Get the position of the left controller, and subtract the floor height
        Vector3 HydraLocation = new Vector3(LeftController.Position.x,
                                            LeftController.Position.y - HydraFloorY,
                                            LeftController.Position.z);

        //Orientate it to our scene
        HydraLocation = StartCameraOffset * HydraLocation;

        //Add the rotated offset from left hyrda to neck
        Vector3 ChestToNeckLocal = FullBodyRotation * ChestToNeckOffset;
        HydraLocation += ChestToNeckLocal;

        //Apply the scaling from Hydra units to World units
        HydraLocation.Scale(HydraToWorldScale);

        //Add in the eye offset, rotated by the body's yaw
        OVRCameraController CameraController = GetComponentInChildren<OVRCameraController>();
        Vector3 NeckToEyes = new Vector3( CameraController.EyeCenterPosition.x, CameraController.EyeCenterPosition.y, CameraController.EyeCenterPosition.z );
        NeckToEyes.y = 0; // not sure why, but changing height gives me wrong results?
        Vector3 NeckToEyesLocal = rotationToFaceForward * NeckToEyes;

        transform.position = BodyPosition + HydraLocation + NeckToEyesLocal;

        #endregion
    }
    /// <summary>
    /// Updates the position of the razer controller on the scene.
    /// </summary>
    /// <param name="controller">razer hydra.</param>
    void UpdatePosition(SixenseInput.Controller controller)
    {
        Vector3 controllerPosition = new Vector3(controller.Position.x * _sensitivity.x, controller.Position.y * _sensitivity.y, controller.Position.z * _sensitivity.z);

        if (controller.GetButtonDown (SixenseButtons.TRIGGER)) {
            GetInitialPositionAvatar();
            _tmpPosition = m_initialPosition - controllerPosition;
        }
        this.gameObject.transform.localPosition = _tmpPosition + controllerPosition;
    }