public void LinkScripts() { if (senseGloveHand == null) { senseGloveHand = this.gameObject.GetComponent <SG_TrackedHand>(); } }
/// <summary> Swap the tracking targets between this hand an another one. </summary> /// <param name="otherHand"></param> public virtual void SwapTracking(SG_TrackedHand otherHand) { if (otherHand != null) { Transform myTrackedObject = this.trackedObject; this.trackedObject = otherHand.trackedObject; otherHand.trackedObject = myTrackedObject; } }
/// <summary> Try to get a SG_TrackedHand that this script is attached to. </summary> /// <param name="obj"></param> /// <param name="handScript"></param> public static SG_TrackedHand CheckForTrackedHand(Transform obj) { SG_TrackedHand handScript = obj.gameObject.GetComponent <SG_TrackedHand>(); if (handScript == null) { handScript = obj.GetComponentInParent <SG_TrackedHand>(); } return(handScript); }
public static bool CheckHandOpen(SG_TrackedHand hand) { float[] flexions; if (hand.gloveHardware.GetNormalizedFlexion(out flexions)) { bool res = flexions.Length > 3 && flexions[0] < tOpen && flexions[1] < iOpen && flexions[2] < mOpen; //Debug.Log(((int)flexions[0]).ToString() + " / " + tOpen.ToString() // + "\t" // + ((int)flexions[1]).ToString() + " / " + iOpen.ToString() // + "\t" // + ((int)flexions[2]).ToString() + " / " + mOpen.ToString() // + "\t" + res // ); return(res); } return(true); }
// Update is called once per frame void Update() { if (activeHand == null) { if (leftHand.gloveHardware.IsConnected || rightHand.gloveHardware.IsConnected) { activeHand = rightHand.gloveHardware.IsConnected ? rightHand : leftHand; activeHand.handModel.gameObject.SetActive(true); activeHand.handAnimation.updateWrist = true; activeHand.handAnimation.CalibrateWrist(); activeHand.handAnimation.UpdateWrist(activeHand.GetIMURotation()); activeHand.handAnimation.UpdateHand(SG_HandPose.Idle(activeHand.TracksRightHand)); activeHand.feedbackScript.DebugEnabled = true; activeHand.grabScript.DebugEnabled = true; activeHand.rigidBodyLayer.DebugEnabled = true; activeHand.physicsTrackingLayer.DebugEnabled = true; calibrateWristBtn.gameObject.SetActive(true); if (this.showing != ShowingLayer.PhysicsLayer) { activeHand.physicsTrackingLayer.gameObject.SetActive(false); } gestureUI.gestureLayer = activeHand.gestureLayer; if (gestureUI.gestureLayer != null) { gestureUI.gestureToCheck = activeHand.gestureLayer.gestures.Length > 0 ? activeHand.gestureLayer.gestures[0] : null; } } } else { if (Input.GetKeyDown(nextKey)) { NextStep(); } else if (Input.GetKeyDown(prevKey)) { PreviousStep(); } if (Input.GetKeyDown(wristKey)) { CalibrateWrist(); } } }
protected void SetRelevantScripts(SG_TrackedHand hand, bool active) { if (hand != null) { if (hand.handAnimation != null) { hand.handAnimation.gameObject.SetActive(active); } if (hand.handModel != null) { hand.handModel.gameObject.SetActive(active); } if (hand.feedbackScript != null) { hand.feedbackScript.gameObject.SetActive(active); } } }
void ConnectObjects(SG_TrackedHand hand) { for (int i = 0; i < ffbObjects.Length; i++) { ffbObjects[i].SetActive(true); SG_SimpleTracking trackingScript = ffbObjects[i].GetComponent <SG_SimpleTracking>(); if (trackingScript == null) { trackingScript = ffbObjects[i].AddComponent <SG_SimpleTracking>(); } if (trackingScript != null) { trackingScript.SetTrackingTarget(hand.handModel.wristTransform, true); } ffbObjects[i].SetActive(false); } }
// Update is called once per frame void Update() { if (activeHand == null) { if (leftHand.hardware.GloveReady || rightHand.hardware.GloveReady) { activeHand = rightHand.hardware.GloveReady ? rightHand : leftHand; activeHand.handModel.gameObject.SetActive(true); activeHand.handAnimation.updateWrist = true; activeHand.handAnimation.CalibrateWrist(); activeHand.handAnimation.UpdateWrist(activeHand.hardware.GloveData); activeHand.handAnimation.UpdateHand(activeHand.hardware.GloveData); activeHand.feedbackScript.DebugEnabled = true; activeHand.grabScript.DebugEnabled = true; activeHand.rigidBodyLayer.DebugEnabled = true; activeHand.physicsTrackingLayer.DebugEnabled = true; calibrateWristBtn.gameObject.SetActive(true); if (this.showing != ShowingLayer.PhysicsLayer) { activeHand.physicsTrackingLayer.gameObject.SetActive(false); } } } else { if (Input.GetKeyDown(nextKey)) { NextStep(); } else if (Input.GetKeyDown(prevKey)) { PreviousStep(); } if (Input.GetKeyDown(wristKey)) { CalibrateWrist(); } } }
// Update is called once per frame void Update() { if (activeHand == null) { if (rightHand.gloveHardware.IsConnected || leftHand.gloveHardware.IsConnected) { activeHand = rightHand.gloveHardware.IsConnected ? rightHand : leftHand; SetRelevantScripts(activeHand, true); ConnectObjects(activeHand); ButtonsActive = true; } } else { if (Input.GetKeyDown(calibrateKey)) { this.ResetCalibration(); } bool handOpen = this.objIndex > -1 ? !activeHand.feedbackScript.TouchingMaterial() : CheckHandOpen(this.activeHand); if (handOpen) { openedTimer += Time.deltaTime; if (openedTimer >= openTime) { allowedSwap = true; } } else { openedTimer = 0; allowedSwap = false; } if (ButtonsInteractable != allowedSwap) { ButtonsInteractable = allowedSwap; } if (allowedSwap) { if (Input.GetKeyDown(prevObjKey)) { PreviousObject(); } else if (Input.GetKeyDown(nextObjKey)) { NextObject(); } } if (objIndex > -1 && breakables[objIndex] != null && breakables[objIndex].IsBroken()) //we're dealing with a breakable { bool canRespawn = CheckHandOpen(this.activeHand); if (canRespawn) { this.breakableTimer += Time.deltaTime; if (this.breakableTimer >= breakableResetTime) { this.breakableTimer = 0; breakables[objIndex].UnBreak(); } } } } }
public static bool CheckHandOpen(SG_TrackedHand hand) { float[] flexions = hand.hardware.GloveData.GetFlexions(); return(flexions.Length > 3 && flexions[0] > -45 && flexions[1] > -45 && flexions[2] > -45); }