Ejemplo n.º 1
0
        /// <summary> Setup and/or change the tracking variables of this hand. </summary>
        /// <param name="newTarget"></param>
        /// <param name="trackType"></param>
        /// <param name="trackMethod"></param>
        /// <param name="rightHand"></param>
        public virtual void SetTrackingMethod(TrackingMethod trackMethod)
        {
            this.trackingMethod = trackMethod;

            //Ignore collisions of the hand itself
            if (this.rigidBodyLayer != null)
            {
                if (this.physicsTrackingLayer != null)
                {
                    this.physicsTrackingLayer.SetIgnoreCollision(this.rigidBodyLayer, true);
                }
                if (this.feedbackScript != null)
                {
                    this.feedbackScript.SetIgnoreCollision(this.rigidBodyLayer, true);
                }
                if (this.grabScript != null)
                {
                    this.grabScript.SetIgnoreCollision(this.rigidBodyLayer, true);
                }
            }
            if (this.physicsTrackingLayer != null)
            {
                if (this.rigidBodyLayer != null)
                {
                    this.rigidBodyLayer.SetIgnoreCollision(this.physicsTrackingLayer, true);
                }
                if (this.feedbackScript != null)
                {
                    this.feedbackScript.SetIgnoreCollision(this.physicsTrackingLayer, true);
                }
                if (this.grabScript != null)
                {
                    this.grabScript.SetIgnoreCollision(this.physicsTrackingLayer, true);
                }
            }

            //Apply the appropriate RB method
            if (trackingMethod == TrackingMethod.PhysicsBased && physicsTrackingLayer != null)
            {
                physicsTrackingLayer.RemoveRigidBodies();
                this.handRB     = SG.Util.SG_Util.TryAddRB(this.gameObject, false, false);
                ignoreGrabables = true;
                if (physicsTrackingLayer != null)
                {
                    physicsTrackingLayer.gameObject.SetActive(true);
                }
            }
            else
            {
                ignoreGrabables = false;
                SG.Util.SG_Util.TryRemoveRB(this.gameObject); //should prevent calling OnCollisionEnter
                this.handRB = null;
                if (physicsTrackingLayer != null)
                {
                    physicsTrackingLayer.gameObject.SetActive(false);
                }
            }
        }
Ejemplo n.º 2
0
        public Tracker GetTracker(TrackingMethod method)
        {
            foreach (Tracker tracker in availableTrackers)
            {
                if (tracker.Description.method == method)
                {
                    return(tracker);
                }
            }

            return(null);
        }
Ejemplo n.º 3
0
    /// <summary> Setup and/or change the tracking variables of this hand. </summary>
    /// <param name="newTarget"></param>
    /// <param name="trackType"></param>
    /// <param name="trackMethod"></param>
    /// <param name="rightHand"></param>
    protected virtual void SetupTracking(Transform newTarget, TrackingHardware trackType, TrackingMethod trackMethod, bool rightHand)
    {
        this.trackedObject    = newTarget;
        this.trackingHardware = trackType;
        this.trackingMethod   = trackMethod;

        //Calculate appropriate offsets
        if (trackedObject != null)
        {
            if (trackingHardware != TrackingHardware.Custom)
            {
                int        LR      = rightHand ? 1 : -1;
                Vector3    posOffs = Vector3.zero;
                Quaternion rotOffs = Quaternion.identity;
                if (trackingHardware == TrackingHardware.ViveTracker)
                {
                    posOffs = new Vector3(0.01f * LR, 0.04f, -0.085f);
                    rotOffs = Quaternion.Euler(0, -90, -90);
                    Debug.Log("Setting up right hand for Vive Tracker");
                }
                this.positionOffset = posOffs;
                this.rotationOffset = rotOffs;
            }
            else
            {
                SG_Util.CalculateOffsets(this.transform, this.trackedObject, out this.positionOffset, out this.rotationOffset);
            }
        }

        //Ignore collisions of the hand itself
        if (this.rigidBodyLayer != null)
        {
            if (this.physicsTrackingLayer != null)
            {
                this.rigidBodyLayer.SetIgnoreCollision(this.physicsTrackingLayer, true);
            }
            if (this.feedbackScript != null)
            {
                this.feedbackScript.SetIgnoreCollision(this.rigidBodyLayer, true);
            }
        }
        if (this.feedbackScript != null && this.physicsTrackingLayer != null)
        {
            this.feedbackScript.SetIgnoreCollision(this.physicsTrackingLayer, true);
        }

        //Apply the appropriate RB method
        if (trackingMethod == TrackingMethod.PhysicsBased && physicsTrackingLayer != null)
        {
            physicsTrackingLayer.RemoveRigidBodies();
            this.handRB     = SG_Util.TryAddRB(this.gameObject, false, false);
            ignoreGrabables = true;
            if (physicsTrackingLayer != null)
            {
                physicsTrackingLayer.gameObject.SetActive(true);
            }
        }
        else
        {
            ignoreGrabables = false;
            SG_Util.TryRemoveRB(this.gameObject); //should prevent calling OnCollisionEnter
            this.handRB = null;
            if (physicsTrackingLayer != null)
            {
                physicsTrackingLayer.gameObject.SetActive(false);
            }
        }
    }