/// <summary>
    /// Inputs for head movements in simulator mode.
    /// </summary>
    /// <param name="mouseX">Mouse x-position.</param>
    /// <param name="mouseY">Mouse y-position.</param>
    private void headSimulation(float mouseX, float mouseY)
    {
        float same;

        //Turn head.
        if (Input.GetKey(KeyCode.Q) && CC_CANOE.keyboardControls)
        {
            headRotation = Quaternion.AngleAxis(mouseX * headSpan - (headSpan / 2), Vector3.up) * Quaternion.AngleAxis(-(mouseY * headSpan / 2 - (headSpan / 4)), Vector3.right);
        }

        //Move the head left/right and forward/backward.
        if (Input.GetKey(KeyCode.Z) && CC_CANOE.keyboardControls)
        {
            same         = headPosition.z;
            headPosition = new Vector3(mouseX * headXSpan - (headXSpan / 2), mouseY * headYSpan / 2 + shoulderHeight, same);
            //Moving the Character Controller with the head movement
            same = CC_CANOE.CanoeCharacterController().center.y;
            CC_CANOE.CanoeCharacterController().center = new Vector3(headPosition.x, same, headPosition.z);
        }

        //Move the head left/right and up/down.
        if (Input.GetKey(KeyCode.C) && CC_CANOE.keyboardControls)
        {
            same         = headPosition.y;
            headPosition = new Vector3(mouseX * headXSpan - (headXSpan / 2), same, mouseY * headZSpan / 2);
            //Moving the Character Controller with the head movement
            same = CC_CANOE.CanoeCharacterController().center.y;
            CC_CANOE.CanoeCharacterController().center = new Vector3(headPosition.x, same, headPosition.z);
        }

        //Roll the head
        if (Input.GetKey(KeyCode.E) && CC_CANOE.keyboardControls)
        {
            if (twistHeadStarted == 0)
            {
                twistHeadStarted = 1;
                saveHeadRotation = headRotation;
            }
            else
            {
                headRotation = saveHeadRotation * Quaternion.AngleAxis(-(mouseX * 180 - 90), Vector3.forward);
            }
        }
        else
        {
            twistHeadStarted = 0;
        }
    }
    // Use this for initialization
    void Start()
    {
        animator = GetComponent <Animator>();

        controller = CC_CANOE.CanoeCharacterController();

        parentTransform    = transform.GetComponentInParent <Transform>();
        headTransform      = CC_CANOE.HeadGameObject().gameObject.transform;
        leftHandTransform  = CC_CANOE.WandGameObject(Wand.Left).gameObject.transform;
        rightHandTransform = CC_CANOE.WandGameObject(Wand.Right).gameObject.transform;

        //Initial call to chest puck
        VRPN.vrpnTrackerQuat("CC_FLAT_PUCK0@" + CC_CONFIG.innovatorIP, 0);

        //Brings model out of ground
        offset = new Vector3(0, 2f * transform.GetChild(0).GetComponent <SkinnedMeshRenderer>().bounds.extents.x, 0);
        transform.localPosition = offset;

        leftMirrorGoal  = transform.parent.GetChild(1).transform;
        rightMirrorGoal = transform.parent.GetChild(2).transform;
    }
    /// <summary>
    /// Obtain tracker information.
    /// </summary>
    private void getTrackerInformation()
    {
        if (CC_CONFIG.IsDestiny())
        {
            Vector3    position = new Vector3(0, 0, 0);
            Quaternion rotation = Quaternion.identity;

            if (canoe.isVive())
            {
                //Update head ClusterInput entry
                position = ClusterInput.GetTrackerPosition("head");
                rotation = ClusterInput.GetTrackerRotation("head");
                //Angle puck so flat section is bottom
                //Change "Camera Forward Tilt" in editor to change tilt if hat/helmet is angled
                rotation *= Quaternion.AngleAxis(90 - canoe.cameraForwardTilt, Vector3.left);
                rotation *= Quaternion.AngleAxis(180, Vector3.up);
                convertHeadTracking(position, rotation);

                //Update left controller ClusterInput entries
                position = ClusterInput.GetTrackerPosition("leftWand");
                rotation = ClusterInput.GetTrackerRotation("leftWand");
                convertWandTracking(Wand.Left, position, rotation);

                //Update right controller ClusterInput entries
                position = ClusterInput.GetTrackerPosition("rightWand");
                rotation = ClusterInput.GetTrackerRotation("rightWand");
                convertWandTracking(Wand.Right, position, rotation);

                //Moving the Character Controller with the head movement
                float same = CC_CANOE.CanoeCharacterController().center.y;
                CC_CANOE.CanoeCharacterController().center = new Vector3(headPosition.x, same, headPosition.z);
            }
            else if (canoe.isOptiTrack())
            {
                //Head position and rotation
                position = ClusterInput.GetTrackerPosition("head");
                //position = new Vector3(position.x, position.y, -position.z);
                rotation = ClusterInput.GetTrackerRotation("head");
                convertHeadTracking(position, rotation);

                //Left wand position and rotation
                position = ClusterInput.GetTrackerPosition("leftWand");
                rotation = ClusterInput.GetTrackerRotation("leftWand");
                convertWandTracking(Wand.Left, position, rotation);

                //Right wand position and rotation
                position = ClusterInput.GetTrackerPosition("rightWand");
                rotation = ClusterInput.GetTrackerRotation("rightWand");
                convertWandTracking(Wand.Right, position, rotation);

                //Moving the Character Controller with the head movement
                float same = CC_CANOE.CanoeCharacterController().center.y;

                CC_CANOE.CanoeCharacterController().center = new Vector3(headPosition.x, same, headPosition.z);
            }
        }
        else
        {
            if (CC_CONFIG.IsInnovator())
            {
                //if (checkInnovatorTracking()) {
                headPosition = convertToLeftHandPosition(VRPN.vrpnTrackerPos("CC_FLAT_HEAD@" + CC_CONFIG.innovatorIP, 0));
                headRotation = convertToLeftHandRotation(VRPN.vrpnTrackerQuat("CC_FLAT_HEAD@" + CC_CONFIG.innovatorIP, 0) * Quaternion.AngleAxis(90 - canoe.cameraForwardTilt, Vector3.left) * Quaternion.AngleAxis(180, Vector3.up));

                //Moving the Character Controller with the head movement
                float same = CC_CANOE.CanoeCharacterController().center.y;
                CC_CANOE.CanoeCharacterController().center = new Vector3(headPosition.x, same, headPosition.z);

                //Wands rotation and position.
                wandPosition[0] = convertToLeftHandPosition(VRPN.vrpnTrackerPos("CC_FLAT_WAND0@" + CC_CONFIG.innovatorIP, 0));
                wandPosition[1] = convertToLeftHandPosition(VRPN.vrpnTrackerPos("CC_FLAT_WAND1@" + CC_CONFIG.innovatorIP, 0));
                wandRotation[0] = convertToLeftHandRotation(VRPN.vrpnTrackerQuat("CC_FLAT_WAND0@" + CC_CONFIG.innovatorIP, 0));
                wandRotation[1] = convertToLeftHandRotation(VRPN.vrpnTrackerQuat("CC_FLAT_WAND1@" + CC_CONFIG.innovatorIP, 0));
            }
            else
            {
                setDefaultPositions();
            }
        }
    }
 void Start()
 {
     //Get the character controller from CC_CANOE.
     charCont = CC_CANOE.CanoeCharacterController();
 }
Exemplo n.º 5
0
 void Start()
 {
     charCont   = CC_CANOE.CanoeCharacterController();
     resetAngle = Quaternion.Euler(resetRotation);
     canoe      = gameObject.GetComponent <CC_CANOE>();
 }
    void Update()
    {
        //Set grab setting
        grab = false;
        if (enableGrabbing)
        {
            if (grabWithTrigger)
            {
                if (CC_INPUT.GetAxis(wand, WandAxis.Trigger) > 0.0f)
                {
                    grab = true;
                }
                else
                {
                    grab = false;
                }
            }
            else
            {
                grab = CC_INPUT.GetButtonPress(wand, grabButton);
            }
        }

        if (grab)
        {
            if (grabbedObject == null)
            {
                if (currentObject != null)
                {
                    grabbedObject = currentObject;
                    // If object had a rigidbody, grabbed save the rigidbody's kinematic state
                    // so it can be restored on release of the object
                    Rigidbody body = null;
                    body = grabbedObject.GetComponent <Rigidbody>();
                    if (body != null)
                    {
                        wasKinematic     = body.isKinematic;
                        body.isKinematic = true;
                    }

                    // Save away to original parentage of the grabbed object
                    grabbedObjectParent = grabbedObject.transform.parent;

                    // Make the grabbed object a child of the wand
                    grabbedObject.transform.parent = CC_CANOE.WandGameObject(wand).transform;
                    currentObject = null;

                    // Disable collision between yourself and the grabbed object so that the grabbed object
                    // does not apply its physics to you and push you off the world
                    Physics.IgnoreCollision(CC_CANOE.CanoeCharacterController(), grabbedObject.GetComponent <Collider>(), true);
                }
            }
        }
        else
        {
            if (grabbedObject != null)
            {
                // Restore the original parentage of the grabbed object
                grabbedObject.transform.parent = grabbedObjectParent;

                // If object had a rigidbody, restore its kinematic state
                Rigidbody body = null;
                body = grabbedObject.GetComponent <Rigidbody>();
                if (body != null)
                {
                    body.isKinematic = wasKinematic;
                }

                //Re-enstate collision between self and object
                Physics.IgnoreCollision(CC_CANOE.CanoeCharacterController(), grabbedObject.GetComponent <Collider>(), false);

                grabbedObject = null;
                currentObject = null;
            }
        }
    }
Exemplo n.º 7
0
 // Use this for initialization
 void Start()
 {
     controller  = CC_CANOE.CanoeCharacterController();
     originalPos = transform.position;
 }