Exemple #1
0
    public static Quaternion vrpnTrackerQuat(string address, int channel)
    {
        Quaternion quaternion = VRPN.vrpnTrackerQuat(address, channel);
        Vector3    euler      = quaternion.eulerAngles;

        return(Quaternion.Euler(euler.x, -euler.y, -euler.z));
    }
Exemple #2
0
    private IEnumerator Rotation()
    {
        while (true)
        {
            Quaternion rotation = VRPN.vrpnTrackerQuat(trackerAddress, channel);

            if (convertToLeft)
            {
                rotation.x  = Interlocked.Exchange(ref rotation.z, rotation.x);
                rotation.y *= -1;

                transform.localRotation = rotation * Quaternion.Euler(trackerRotationOffset);
            }

            else
            {
                Vector3 fixedRotation = new Vector3();
                fixedRotation.x = trackerRotationOffset.z;
                fixedRotation.y = trackerRotationOffset.y;
                fixedRotation.z = trackerRotationOffset.x;

                transform.localRotation = rotation * Quaternion.Euler(fixedRotation);
            }

            yield return(null);
        }
    }
Exemple #3
0
    public static Quaternion vrpnTrackerQuat(string address, int channel)
    {
        var quaternion = VRPN.vrpnTrackerQuat(address, channel);

        return(new Quaternion(-quaternion.x, -quaternion.z, -quaternion.y, quaternion.w));
        //Quaternion quaternion = VRPN.vrpnTrackerQuat(address, channel);

        //if (quaternion == new Quaternion(-505, -505, -505, -505))
        //    return Quaternion.identity;
        ////Vector3 euler = quaternion.eulerAngles;

        //quaternion = ConvertRightHandedToLeftHandedQuaternion(quaternion);
        //Vector3 euler = quaternion2Euler(quaternion, RotSeq.zyx);
        ////quaternion = ConvertToRightHand(euler);
        ////euler = new Vector3(euler.x, euler.y, euler.z);

        ////quaternion = Quaternion.Euler(euler);
        ////quaternion = ConvertRightHandedToLeftHandedQuaternion(quaternion);

        ////euler = Quaternion.ToEulerAngles(quaternion)*Mathf.Rad2Deg;
        ////euler = new Vector3(euler.x, euler.z, euler.y);
        ////quaternion = Quaternion.Euler(euler);

        //return Quaternion.Euler(-euler.x, -euler.y, -euler.z);


        //return quaternion;
        //return new Quaternion(-quaternion.x, -quaternion.z, -quaternion.y, quaternion.w);
    }
    private void OnAnimatorIK(int layerIndex)
    {
        transform.localPosition = new Vector3(controller.center.x, offset.y - 0.1f, controller.center.z);

        if (animator)
        {
            //Head movement
            animator.SetBoneLocalRotation(HumanBodyBones.Head, convertHeadRotation(headTransform.rotation));

            //Spine movement
            Quaternion spineRotation = VRPN.vrpnTrackerQuat("CC_FLAT_PUCK0@" + CC_CONFIG.innovatorIP, 0)
                                       * Quaternion.AngleAxis(-90, Vector3.up) * Quaternion.AngleAxis(90, Vector3.forward);
            spineRotation = Quaternion.Euler(90f + spineRotation.eulerAngles.y, spineRotation.eulerAngles.x,
                                             90f - spineRotation.eulerAngles.z);
            if (mirror)
            {
                spineRotation = Quaternion.Euler(spineRotation.eulerAngles.x,
                                                 -spineRotation.eulerAngles.y,
                                                 spineRotation.eulerAngles.z);
            }
            animator.SetBoneLocalRotation(HumanBodyBones.Spine, spineRotation);

            //Hip movement

            //Hand movement
            if (mirror)
            {
                handUpdate(AvatarIKGoal.LeftHand, rightMirrorGoal.localPosition, rightMirrorGoal.localRotation);
                handUpdate(AvatarIKGoal.RightHand, leftMirrorGoal.localPosition, leftMirrorGoal.localRotation);
            }
            else
            {
                //Left hand goal local tranformations
                leftHandGoal.transform.localPosition = leftHandTransform.localPosition;
                leftHandGoal.transform.localRotation = leftHandTransform.rotation * Quaternion.LookRotation(transform.forward);

                /*
                 * Quaternion temp = leftHandGoal.transform.rotation;
                 * if (reverseX) {
                 *  leftHandGoal.transform.rotation = new Quaternion(temp.x, temp.y, temp.z, -temp.w);
                 * }
                 * if (reverseZ) {
                 *  leftHandGoal.transform.rotation = new Quaternion(temp.x, temp.y, -temp.z, temp.w);
                 * }
                 */

                //Right hand goal local transformations
                rightHandGoal.transform.localPosition = rightHandTransform.localPosition;
                rightHandGoal.transform.localRotation = rightHandTransform.localRotation * Quaternion.LookRotation(transform.forward);
            }
            //Update hand transforms
            handUpdate(AvatarIKGoal.LeftHand,
                       leftHandGoal.transform.position,
                       leftHandGoal.transform.rotation);
            handUpdate(AvatarIKGoal.RightHand,
                       rightHandGoal.transform.position,
                       rightHandGoal.transform.rotation);
        }
    }
Exemple #5
0
 private IEnumerator Rotation()
 {
     while (true)
     {
         transform.localRotation = VRPN.vrpnTrackerQuat(trackerAddress, channel);
         yield return(null);
     }
 }
Exemple #6
0
 // Update is called once per frame
 void Update()
 {
     if (trackPosition)
     {
         transform.position = VRPN.vrpnTrackerPos(obj + "@" + host, channel);
     }
     if (trackRotation)
     {
         transform.rotation = VRPN.vrpnTrackerQuat(obj + "@" + host, channel);
     }
 }
    // Use this for initialization
    void Start()
    {
        //Initial calls to VRPN for puck 0, 1, 2 entries
        for (int i = 0; i < 3; i++)
        {
            VRPN.vrpnTrackerPos("CC_FLAT_PUCK" + i + "@" + CC_CONFIG.innovatorIP, 0);
            VRPN.vrpnTrackerQuat("CC_FLAT_PUCK" + i + "@" + CC_CONFIG.innovatorIP, 0);
        }

        headReference      = transform.GetChild(0).gameObject.transform;
        leftWandReference  = transform.GetChild(1).gameObject.transform;
        rightWandReference = transform.GetChild(2).gameObject.transform;
        waistReference     = transform.GetChild(3).gameObject.transform;
        leftFootReference  = transform.GetChild(4).gameObject.transform;
        rightFootReference = transform.GetChild(5).gameObject.transform;
    }
 void Update()
 {
     foreach (VRPNConnection vrpnC in _connectionList.Values)
     {
         if (vrpnC._VRPNObject != null)
         {
             Vector3    tmpPos  = VRPN.vrpnTrackerPos(vrpnC._VRPNObject, 0);
             Quaternion tmpQuat = VRPN.vrpnTrackerQuat(vrpnC._VRPNObject, 0);
             Vector3    pos     = new Vector3(-tmpPos.x, tmpPos.z, -tmpPos.y);
             Quaternion quat    = new Quaternion(tmpQuat.x, -tmpQuat.z, tmpQuat.y, tmpQuat.w);
             vrpnC._pos  = pos;
             vrpnC._quat = quat;
             //NetworkServer.SendToAll (MESSAGE_DATA, new VRPNMessage (pos, quat));
             NetworkServer.SendToClient(vrpnC._connectionID, MESSAGE_DATA, new VRPNMessage(pos, quat));
         }
     }
 }
    // 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();
            }
        }
    }
 private Quaternion convertPuckRotation(int puckNum)
 {
     return(convertRotation(
                convertToLeftHandRotation(VRPN.vrpnTrackerQuat("CC_FLAT_PUCK" + puckNum + "@" + CC_CONFIG.innovatorIP, 0) * Quaternion.AngleAxis(90, Vector3.left) * Quaternion.AngleAxis(180, Vector3.up))
                ));
 }
    public static Quaternion vrpnTrackerQuat(string address, int channel)
    {
        var quaternion = VRPN.vrpnTrackerQuat(address, channel);

        return(new Quaternion(quaternion.x, quaternion.z, quaternion.y, -quaternion.w));
    }
 private void GetTrackerData(string name, int sensor)
 {
     QuatVRPN = VRPN.vrpnTrackerQuat(name, sensor);
 }