GetPalmNormal() 공개 메소드

public GetPalmNormal ( ) : Vector3
리턴 Vector3
예제 #1
0
    void updateLeftHandFacingUp()
    {
        Vector3 upCam      = mainCamera.transform.up;
        float   difference = Vector3.Angle(leftHandModel.GetPalmNormal(), upCam);

        leftHandFacingUp = difference < MAX_ANGLE_DIFFERENCE_FOR_INTERFACE && leftHand.activeSelf;
    }
예제 #2
0
    private void DrawDebugLines()
    {
        HandModel hand = GetComponent <HandModel>();

        Debug.DrawLine(hand.GetElbowPosition(), hand.GetWristPosition(), Color.red);
        Debug.DrawLine(hand.GetWristPosition(), hand.GetPalmPosition(), Color.white);
        Debug.DrawLine(hand.GetPalmPosition(),
                       hand.GetPalmPosition() + hand.GetPalmNormal(), Color.black);
        Debug.Log(Vector3.Dot(hand.GetPalmDirection(), hand.GetPalmNormal()));
    }
예제 #3
0
    protected void UpdateGraspPosition()
    {
        HandModel handModel = this.GetComponent <HandModel>();

        // our grasp center only depends on thumb and index finger for stability reasons
        this.CurrentGraspCenter = 0.5f * (handModel.fingers[0].GetTipPosition() +
                                          handModel.fingers[1].GetTipPosition());

        if (this.CurrentGraspState == GraspState.GRASPED && this.ActiveObject != null)
        {
            // not the best style, but this hardcoded rule creates a grasp center near the palm,
            // if you would rather use a pinch, than just take the centroid of the thumb (index 0)
            // and the index finger (index 1)

            /*this.CurrentGraspCenter = (
             *           handModel.fingers[0].GetTipPosition() * .2f +
             *           handModel.fingers[1].GetTipPosition() * .2f +
             *           handModel.GetPalmPosition() * .6f);*/
            /*this.CurrentGraspCenter = (
             *             (handModel.fingers[0].GetTipPosition() +
             *             handModel.fingers[1].GetTipPosition() +
             *             handModel.fingers[2].GetTipPosition() +
             *             handModel.fingers[3].GetTipPosition() +
             *             handModel.fingers[4].GetTipPosition() ) *.2f * .4f +
             *             handModel.GetPalmPosition() * .6f);*/

            this.CurrentGraspCenter = handModel.GetPalmPosition() + handModel.GetPalmNormal() * .025f;
        }

        Vector3 graspDelta = this.CurrentGraspCenter - this.SmoothedGraspPosition;

        this.SmoothedGraspPosition += (1.0f - this.PositionFiltering) * graspDelta;
    }
	Vector3 GetFireBallSpawnPosition(HandModel hand, float distance){

		Vector3 palmPos = hand.GetPalmPosition ();

		Vector3 palmDir = hand.GetPalmNormal ();

		return palmPos + Vector3.Scale(palmDir,new Vector3(distance,distance,distance));
	}
예제 #5
0
    IEnumerator Fire(HandModel currentHand)
    {
        canFire = false;
        //Debug.Log (canFire);

        GameObject justFired = Instantiate (ammo, currentHand.transform.position + currentHand.GetPalmNormal() * offset , currentHand.GetPalmRotation()) as GameObject;
        justFired.GetComponent<moveProjectile> ().target = target;
        //justFired.GetComponent<moveProjectile> ().force = Quaternion.LookRotation( handController.transform.forward, Vector3.down).eulerAngles;
        yield return new WaitForSeconds (delay);
            canFire = true;
    }
	public static bool IsPalmFacingDownwards(HandModel hand, float theta){
		Vector3 dir = hand.GetPalmNormal ();

		float angle = Vector3.Angle (dir, -1* hand.transform.up);

		if (Math.Abs (angle) <= theta)
			return true;

		return false;

	}
예제 #7
0
	public static float AngleBetweenPalmsNormals(HandModel leftHand, HandModel rightHand, Vector3 projectPlane){

		Vector3 leftPalmNorm = leftHand.GetPalmNormal ();
		Vector3 rightPalmNorm = rightHand.GetPalmNormal ();

		Vector3 leftPalmNormProj = Math3d.ProjectVectorOnPlane (projectPlane,leftPalmNorm).normalized;
		Vector3 rightPalmNormProj = Math3d.ProjectVectorOnPlane (projectPlane,rightPalmNorm).normalized;

		float angle = Math3d.SignedVectorAngle (leftPalmNorm, rightPalmNorm,projectPlane);

		return angle;

	}
예제 #8
0
 void HandleHandEvent(object sender, LMWidgets.EventArg <HandData> e)
 {
     if (e.CurrentValue.HasHand)
     {
         HandModel hand   = e.CurrentValue.HandModel;
         Vector3   pivot  = hand.GetPalmPosition();
         Vector3   normal = pivot + hand.GetPalmNormal();
         Vector3   axis   = upTarget.transform.position;
         FloatValue = Vector3.Dot((normal - pivot).normalized, (axis - pivot).normalized);
     }
     else
     {
         FloatValue = -1;
     }
 }
예제 #9
0
        // Ensure that the icon remains above the JoyBall surface
        private void SetIconRadius()
        {
            // REQUIRE: this.transform.parent is HandController
            if (handController == null)
            {
                return;
            }
            HandModel hand = GetHandFromFingerBone(target_.transform);

            if (hand == null)
            {
                return;
            }
            SphereCollider ball = GetComponent <SphereCollider>();

            if (ball == null)
            {
                return;
            }

            // MATH: The following derives the radius sufficient for the icon
            // to float above the surface of the sphere
            Vector3 ballLeapCenter = transform.TransformPoint(ball.center);
            Vector3 palmLeapTo     = hand.palm.position - ballLeapCenter;

            if (!(ball.radius * ball.radius > palmLeapTo.sqrMagnitude))
            {
                WristIconManager.IconOffsetDistance = 0.04f;
                return;
            }
            Vector3 palmLeapUp = -hand.GetPalmNormal();
            float   pCos       = Vector3.Dot(palmLeapTo, palmLeapUp);
            // RESULT: rSurfTo is the distance in the up direction to the sphere surface
            float rSurfTo = Mathf.Sqrt(ball.radius * ball.radius - (palmLeapTo.sqrMagnitude - pCos * pCos)) - pCos;
            // RESULT: planeAdd is the additional distance needed to ensure that
            // a plane perpendicular to palmWolrdUp does not intersect the sphere surface
            float planeAdd = ball.radius - pCos - rSurfTo;

            // Ensure that icon remains above ball surface
            if (rSurfTo + planeAdd > 0.04f)
            {
                WristIconManager.IconOffsetDistance = rSurfTo + planeAdd;
            }
            else
            {
                WristIconManager.IconOffsetDistance = 0.04f;
            }
        }
//	//Detect if index finger, middle finger, ring finger and little finger are straight (not bent).
//	public static bool FourFingersStraight(HandModel hand){
//
//		return !IsIndexFingerBent (hand, 3) && !IsMiddleFingerBent (hand, 3) && !IsRingFingerBent (hand, 3)
//			&& !IsLittleFingerBent (hand, 3);
//
//	}
//
	public static bool IsPalmFacingUpwards(HandModel hand, float theta ){

		Vector3 dir = hand.GetPalmNormal ();

		//Vector3 worldUp = hand.transform.TransformDirection(hand.transform.up);

		float angle = Vector3.Angle (dir, hand.transform.up);

		//Debug.Log (angle);

		if (Math.Abs (angle) <= theta)
			return true;

		return false;

	}
예제 #11
0
    // Update is called once per frame
    void Update()
    {
        hand = transform.GetComponent <HandModel> ();

        //Somente deve funcionar na mão escolhida, direita ou esquerda
        if (maoCerta)
        {
            for (int i = 0; i < 2; i++)
            {
                dedos [i]      = hand.fingers [i + 1].GetBoneCenter(3);
                distancias [i] = (dedos [i] - hand.GetPalmPosition()).magnitude;                        //distâncias dos dedos à palma da mão
            }

            //Verifica se a mão está fechada e próxima da base ou se o usuário quer ter que alcançar a seringa para pega-la
            if (pegando())
            {
                if ((hand.GetPalmPosition() - baseSeringaPosition).magnitude < distBaseSeringa || !GetComponentInParent <escolherMao> ().alcançarSeringa)
                {
                    pegou = true;
                }
            }

            //"Prende" a seringa à palma da mão, utilizando sua posição e rotação + ajustes
            if (pegou)
            {
                seringa.transform.position = hand.GetPalmPosition() + hand.GetPalmNormal() * distSeringa.x + Vector3.Cross(hand.GetPalmDirection(), hand.GetPalmNormal()).normalized *distSeringa.y + hand.GetPalmDirection() * distSeringa.z;
                seringa.transform.rotation = hand.GetPalmRotation() * rotSeringa;
                GetComponentInParent <escolherMao> ().Congelar();
            }

            //Solta a seringa de volta a base
            else
            {
                seringa.transform.position = baseSeringaPosition;
                seringa.transform.rotation = baseSeringaRotation;
            }

            //Verifica se a mão está aberta e próxima da base da seringa ou se o usuário quer soltar a seringa a qualquer momento
            if (soltando())
            {
                if ((hand.GetPalmPosition() - baseSeringaPosition).magnitude < distBaseSeringa || !GetComponentInParent <escolherMao> ().alcançarSeringa)
                {
                    pegou = false;
                }
            }
        }
    }
예제 #12
0
    public void Update()
    {
        // if (handModel == null) return;

        RaycastHit hit;

        if (brushActive)
        {
            paintBrush.SetActive(true);
            palmPos     = handModel.GetPalmPosition();
            fwd         = handModel.GetPalmNormal();
            headPos     = new Vector3(Camera.main.transform.position.x + headOffset, Camera.main.transform.position.y, Camera.main.transform.position.z);
            destination = tracker.position - headPos;

            Debug.Log("BRUSH IS ACTIVE!");
            if (Physics.Raycast(Camera.main.transform.position, destination, out hit, Mathf.Infinity, lm))
            {
                Debug.DrawRay(Camera.main.transform.position, destination, Color.red);

                filter = hit.collider.GetComponent <MeshFilter>();
                if (filter)
                {
                    selectedTransform = hit.collider.transform;
                    Debug.Log("Current object: " + selectedTransform.gameObject.name);

                    if (filter != unappliedMesh)
                    {
                        ApplyMeshCollider();
                        unappliedMesh = filter;
                        //historyFilters.Add(filter);
                    }


                    Vector3 relativePoint = filter.transform.InverseTransformPoint(hit.point);
                    DeformMesh(filter.mesh, relativePoint, pull * Time.deltaTime, radius);

                    paintBrush.transform.position = hit.point;
                }
            }
        }
        else
        {
            paintBrush.SetActive(false);
            ApplyMeshCollider();
            return;
        }
    }
예제 #13
0
    protected void UpdateGraspPosition()
    {
        HandModel handModel = this.GetComponent <HandModel>();

        // our grasp center only depends on thumb and index finger for stability reasons
        this.CurrentGraspCenter = 0.5f * (handModel.fingers[0].GetTipPosition() +
                                          handModel.fingers[1].GetTipPosition());

        if (this.CurrentGraspState == GraspState.GRASPED && this.ActiveObject != null)
        {
            this.CurrentGraspCenter = handModel.GetPalmPosition() + handModel.GetPalmNormal() * .025f;
        }

        Vector3 graspDelta = this.CurrentGraspCenter - this.SmoothedGraspPosition;

        this.SmoothedGraspPosition += (1.0f - this.PositionFiltering) * graspDelta;
    }
예제 #14
0
    void Update()
    {
        if (handModel == null)
        {
            return;
        }
        Vector3 palmPos = handModel.GetPalmPosition();

        if (!pickedUp)
        {
            Debug.Log("Picked up !");
            RaycastHit hit;


            Vector3 fwd         = handModel.GetPalmNormal();
            Vector3 destination = tracker.position - palmPos;

            if (Physics.Raycast(palmPos, destination, out hit, Mathf.Infinity))
            {
                float distanceToGround = hit.distance;
                Debug.Log("Hitting " + hit);
                Debug.DrawRay(palmPos, destination, Color.red);

                deformer = hit.collider.GetComponent <MeshDeformer>();
                if (deformer)
                {
                    tracker.SetParent(null);


                    deformPoint  = hit.point;
                    deformPoint += hit.normal * forceOffset;
                    pickedUp     = true;
                    inTransport  = true;
                }
            }
        }

        if (inTransport)
        {
            deformer.AddDeformingForce(deformPoint, force * Vector3.Distance(tracker.transform.position, palmPos));
        }
    }
예제 #15
0
	public static bool IsFingerBentWithinAngle(HandModel hand, int fingerIndex, int boneIndex, float minAngle, float maxAngle){

		FingerModel finger = hand.fingers [fingerIndex];
		
		Vector3 fingerDir = finger.GetBoneDirection (boneIndex);
		
		Vector3 palmNormal = hand.GetPalmNormal ();
		
		Vector3 palmDir = hand.GetPalmDirection ();
		
		if (fingerIndex == 0) {
			
			float angle = Math3d.SignedVectorAngle (palmDir, fingerDir, palmNormal);
			
			//Debug.Log ("Finger: " + finger.fingerType + ", bone: " + boneIndex + ", angle to palm direction: " + angle);
			
			if (angle >= minAngle && angle <= maxAngle)
				return true;
				
			
		} else if (fingerIndex > 0) {
			
			Vector3 projPlane = Vector3.Cross(palmNormal, palmDir).normalized;
			Vector3 projVector = Math3d.ProjectVectorOnPlane(projPlane,fingerDir).normalized;
			
			
			float angle = Math3d.SignedVectorAngle(palmNormal,projVector,projPlane);
			
			//Debug.Log ("Finger: " + finger.fingerType + ", bone: " + boneIndex + ", angle to palm direction: " + angle);
			
			if (angle >= minAngle && angle <= maxAngle)
				return true;
		}
		
		
		return false;

	}
	public static float AngleBetweenFingerAndPalmDirection(HandModel hand, int fingerIndex, int boneIndex){

		Vector3 palmVector = hand.GetPalmDirection ();
		Vector3 palmNormal = hand.GetPalmNormal ();
		Vector3 crossVect = Vector3.Cross (palmVector, palmNormal).normalized;
		//Debug.Log (crossVect.normalized);

		float angle =  AngleBetweenFingerAndVector (hand, fingerIndex, boneIndex, palmVector, crossVect);

		return angle;
//		if (fingerIndex == 0) {
//			
//			if (hand.GetLeapHand ().IsRight) {
//				return angle;
//			} else {
//				return -angle;
//			}
//
//		} else {
//			
//			return -angle;
//		}
//			
	}
	public static float AngleBetweenFingerTipsHorizontal(HandModel hand, int fingerIndexOne, int fingerIndexTwo){


		float angle = AngleBetweenFingerTips(hand,fingerIndexOne, fingerIndexTwo,hand.GetPalmNormal());

		if (hand.GetLeapHand ().IsRight)
			return -angle;

		return angle;

	}
	public static float AngleBetweenFingerTipsVertical(HandModel hand, int fingerIndexOne, int fingerIndexTwo){
		Vector3 palmVector = hand.GetPalmDirection ();
		Vector3 palmNormal = hand.GetPalmNormal ();
		Vector3 crossVect = Vector3.Cross (palmVector, palmNormal).normalized;
		return AngleBetweenFingerTips (hand, fingerIndexOne, fingerIndexTwo, crossVect);

	}
예제 #19
0
    void updateLeftHand()
    {
        Vector3 upCam      = mainCamera.transform.up;
        float   difference = Vector3.Angle(leftHandModel.GetPalmNormal(), upCam);

        if (difference < MAX_ANGLE_DIFFERENCE_FOR_INTERFACE && leftHand.activeSelf)
        {
            if (leftHandInterfaceActive)
            {
                //Update the position, rotation, and color
                if (hue && hue.activeSelf)
                {
                    hue.transform.position = leftHandModel.GetPalmPosition() + leftHandModel.GetPalmNormal() * 0.15f;
                    hue.transform.rotation = leftHandModel.GetPalmRotation();
                }
                if (alpha && alpha.activeSelf)
                {
                    alpha.transform.position = leftHandModel.GetPalmPosition() + leftHandModel.GetPalmNormal() * 0.15f;
                    alpha.transform.rotation = leftHandModel.GetPalmRotation();
                }
                if (saturation && saturation.activeSelf)
                {
                    saturation.transform.position = leftHandModel.GetPalmPosition() + leftHandModel.GetPalmNormal() * 0.15f;
                    saturation.transform.rotation = leftHandModel.GetPalmRotation();
                }
            }
            else
            {
                //Spawn in the light, 3 selectors, and sphere.
                //update each position, rotation, and color
                if (hue)
                {
                    hue.transform.position = leftHandModel.GetPalmPosition() + leftHandModel.GetPalmNormal() * 0.15f;
                    hue.transform.rotation = leftHandModel.GetPalmRotation();
                    hue.SetActive(true);
                }

                else if (huePrefab)
                {
                    hue = (GameObject)Instantiate(huePrefab,
                                                  leftHandModel.GetPalmPosition() + leftHandModel.GetPalmNormal() * 0.15f,
                                                  leftHandModel.GetPalmRotation());
                    hueSliderHeightPercentage = 0.5f;
                    updateColorSelected();
                }

                if (alpha)
                {
                    alpha.SetActive(true);
                }

                else if (alphaPrefab)
                {
                    alpha = (GameObject)Instantiate(alphaPrefab,
                                                    leftHandModel.GetPalmPosition() + leftHandModel.GetPalmNormal() * 0.15f,
                                                    leftHandModel.GetPalmRotation());
                }

                if (saturation)
                {
                    saturation.SetActive(true);
                }

                else if (saturationPrefab)
                {
                    saturation = (GameObject)Instantiate(saturationPrefab,
                                                         leftHandModel.GetPalmPosition() + leftHandModel.GetPalmNormal() * 0.15f,
                                                         leftHandModel.GetPalmRotation());
                }
                leftHandInterfaceActive = true;
            }
        }
        else
        {
            if (leftHandInterfaceActive)
            {
                if (!leftHand.activeSelf || difference >= MAX_ANGLE_DIFFERENCE_FOR_INTERFACE)
                {
                    if (hue)
                    {
                        hue.SetActive(false);
                    }
                    if (saturation)
                    {
                        saturation.SetActive(false);
                    }
                    if (alpha)
                    {
                        alpha.SetActive(false);
                    }
                    leftHandInterfaceActive = false;
                }
            }
        }
    }
예제 #20
0
    protected void StartGrasp()
    {
        // Only grasp if we're hovering over an object.
        if (this.ActiveObject == null)
        {
            return;
        }

        HandModel       handModel = this.GetComponent <HandModel>();
        GraspableObject graspable = this.ActiveObject.GetComponent <GraspableObject>();

        Leap.Utils.IgnoreCollisions(this.gameObject, this.ActiveObject.gameObject, true);

        // Setup initial position and rotation conditions.
        this.PalmRotation = handModel.GetPalmRotation();
        this.GraspOffset  = Vector3.zero;

        // If we don't center the object, find the closest point in the collider for our grab point.
        if (graspable == null || !graspable.CenterGraspedObject)
        {
            Vector3 deltaPosition = ActiveObject.transform.position - this.CurrentGraspCenter;

            Ray        graspRay = new Ray(this.CurrentGraspCenter, deltaPosition);
            RaycastHit graspHit;

            // If the raycast hits the object, we are outside the collider so grab the hit point.
            // If not, we are inside the collider so just use the grasp position.
            if (ActiveObject.Raycast(graspRay, out graspHit, GraspObjectDistance))
            {
                this.GraspOffset = this.ActiveObject.transform.position - graspHit.point;
            }
            else
            {
                this.GraspOffset = this.ActiveObject.transform.position - CurrentGraspCenter;
            }
        }

        this.SmoothedGraspPosition = this.ActiveObject.transform.position - this.GraspOffset;
        this.GraspOffset           = Quaternion.Inverse(this.ActiveObject.transform.rotation) * GraspOffset;
        this.RotationFromPalm      = Quaternion.Inverse(this.PalmRotation) * this.ActiveObject.transform.rotation;

        // If we can rotate the object quickly, increase max angular velocity for now.
        if (graspable == null || graspable.RotateQuickly)
        {
            this.ObjectMaxAngularVelocity = this.ActiveObject.GetComponent <Rigidbody>().maxAngularVelocity;
            this.ActiveObject.GetComponent <Rigidbody>().maxAngularVelocity = Mathf.Infinity;
        }

        if (graspable != null)
        {
            // Notify grabbable object that it was grabbed.
            if (graspable.GetResponseTime() < 0L)
            {
                if (handModel != null)
                {
                    Vector3 normal     = handModel.GetPalmNormal();
                    float   angleLeft  = Vector3.Angle(normal, Vector3.left);
                    float   angleRight = Vector3.Angle(normal, Vector3.right);
                    if (GraspController.Verbose)
                    {
                        Debug.LogWarning("hand normal: " + normal + ", to right: " + angleRight + ", to left: " + angleLeft);
                    }
                    if (angleLeft < angleRight)
                    {
                        graspable.setGraspDirection(GraspableObject.GraspDirection.UPRIGHT);
                    }
                    else
                    {
                        graspable.setGraspDirection(GraspableObject.GraspDirection.ROTATED);
                    }
                }
                else
                {
                    if (GraspController.Verbose)
                    {
                        Debug.LogWarning("no hand found...");
                    }
                }
            }
            graspable.OnGrasp(this.gameObject);

            if (graspable.UseAxisAlignment)
            {
                // If this option is enabled we only want to align the object axis with the palm axis,
                // hence we cancel out any rotation about the aligned axis.
                Vector3 palmVector = graspable.RightHandAxis;
                if (handModel.GetLeapHand().IsLeft)
                {
                    palmVector = Vector3.Scale(palmVector, new Vector3(-1, 1, 1));
                }
                Vector3    axisInPalm     = this.RotationFromPalm * graspable.ObjectAxis;
                Quaternion axisCorrection = Quaternion.FromToRotation(axisInPalm, palmVector);
                if (Vector3.Dot(axisInPalm, palmVector) < 0)
                {
                    axisCorrection = Quaternion.FromToRotation(axisInPalm, -palmVector);
                }
                this.RotationFromPalm = axisCorrection * this.RotationFromPalm;
            }
        }
    }
예제 #21
0
    void selector()
    {
        Debug.Log(hand.palm.localEulerAngles);
        float difference = Vector3.Angle(hand.palm.localEulerAngles, FACING_CAMERA);

        if (difference < 8.0f && leftHand.activeSelf)
        {
            if (selectorsMade)
            {
                //Update the position, rotation, and color
                if (hue)
                {
                    hue.transform.position = hand.GetPalmPosition() + hand.GetPalmNormal() * 0.15f;
                    hue.transform.rotation = hand.GetPalmRotation();
                }
                if (alpha)
                {
                    alpha.transform.position = hand.GetPalmPosition() + hand.GetPalmNormal() * 0.15f;
                    alpha.transform.rotation = hand.GetPalmRotation();
                }
                if (saturation)
                {
                    saturation.transform.position = hand.GetPalmPosition() + hand.GetPalmNormal() * 0.15f;
                    saturation.transform.rotation = hand.GetPalmRotation();
                }
            }
            else
            {
                //Spawn in the light, 3 selectors, and sphere.
                //update each position, rotation, and color
                if (huePrefab)
                {
                    hue = (GameObject)Instantiate(huePrefab, hand.GetPalmPosition() + hand.GetPalmNormal() * 0.15f, hand.GetPalmRotation());
                }
                if (alphaPrefab)
                {
                    alpha = (GameObject)Instantiate(alphaPrefab);
                }
                if (saturationPrefab)
                {
                    saturation = (GameObject)Instantiate(saturationPrefab);
                }
                selectorsMade = true;
                lhc.BroadcastMessage("setInterface", true);
            }
        }
        else
        {
            if (selectorsMade)
            {
                if (!leftHand.activeSelf || difference >= 8.0f)
                {
                    if (hue)
                    {
                        Destroy(hue);
                    }
                    if (saturation)
                    {
                        Destroy(saturation);
                    }
                    if (alpha)
                    {
                        Destroy(alpha);
                    }
                    selectorsMade = false;
                }
                lhc.BroadcastMessage("setInterface", false);
            }
        }
    }
    void Update()
    {
        Frame        frame             = provider.CurrentFrame;
        List <Hand>  hands             = frame.Hands;
        HandModel    hml               = FindObjectOfType <HandModel> ();
        StateMachine StateMachineFlags = StateMachine.GetComponent <StateMachine>();


        if (hands.Count == 1)
        {
            for (int h = 0; h < hands.Count; h++)
            {
                Hand hand = hands [h];

                //---------------------------------------------------------------------------------------------
                if (hand.IsLeft)
                {
                    l_strength = hand.GrabStrength;
                    l_palmPos  = hml.GetPalmPosition();

                    //Raycast
                    if (!l_ObjectHeld && (StateMachineFlags.TrainFlag == 1))
                    {
                        l_ObjectDetected = false;
                        RaycastHit l_hit;
                        bool       hitornot = Physics.Raycast(l_palmPos, hml.GetPalmNormal(), out l_hit, 20);
                        if (hitornot)
                        {
                            l_pickup         = l_hit.transform.gameObject;
                            l_ObjectDetected = true;
                        }
                        // ATTACH TO HAND
                        if ((l_ObjectDetected) && (l_strength > l_curr_strength / 100))
                        {
                            l_ObjectHeld = true;
                            l_pickup_pos = l_hit.transform.position;
                        }
                    }
                    //KEEP TO Hand
                    if (l_ObjectHeld && l_strength > l_curr_strength / 100)
                    {
                        l_pickup.transform.position = l_palmPos + (hml.GetPalmNormal()) / 8;
                    }
                    else if (l_strength < l_curr_strength / 100)
                    {
                        if (l_ObjectHeld)
                        {
                            l_pickup_release_pos = l_palmPos;
                        }
                        l_ObjectHeld = false;
                    }
                }
                //--------------------------------------------------------------------------------------
                if (hand.IsRight)
                {
                    r_strength = hand.GrabStrength;
                    r_palmPos  = hml.GetPalmPosition();

                    //Apply Raycast only if object not held
                    if (!r_ObjectHeld && (StateMachineFlags.TrainFlag == 1))
                    {
                        r_ObjectDetected = false;
                        RaycastHit r_hit;
                        if (Physics.Raycast(r_palmPos, hml.GetPalmNormal(), out r_hit, 20))
                        {
                            r_pickup         = r_hit.transform.gameObject;
                            r_ObjectDetected = true;
                        }
                        // ATTACH TO HAND
                        if ((r_ObjectDetected) && (r_strength > r_curr_strength / 100))
                        {
                            r_ObjectHeld = true;
                            r_pickup_pos = r_hit.transform.position;
                            //Debug.Log ("Right Pick Up"+r_pickup_pos);
                            //Debug.Log ("Right Pick Up tag"+	r_pickup.tag);
                        }
                    }

                    //KEEP IN Hand
                    if (r_ObjectHeld && r_strength > r_curr_strength / 100)
                    {
                        r_pickup.transform.position = r_palmPos + (hml.GetPalmNormal()) / 8;
                    }
                    else if (r_strength < r_curr_strength / 100)
                    {
                        if (r_ObjectHeld)
                        {
                            r_pickup_release_pos = r_palmPos;
                        }

                        r_ObjectHeld = false;
                    }
                }

                HapticFeedback HapticFlags = Haptics.GetComponent <HapticFeedback>();

                if (l_ObjectHeld || r_ObjectHeld)
                {
                    HapticFlags.HapticPalmFeedback = 1;
                }

                if (l_ObjectHeld == false && r_ObjectHeld == false && HapticFlags.HapticPalmFeedback == 1)
                {
                    HapticFlags.HapticPalmFeedback = 0;
                }

                //----------------------------------------------------------------------------------------
            }
        } //end of if
    }     //End of update
    }     // END OF AVERAGE VELOCITY

    string HasSwipedX()
    {
        // Left Hand
        if (stateL == "Active")
        {
            // Current Palm Position
            palmCurrL = transform.InverseTransformPoint(leftPalm.transform.position).x;

            float distL = palmCurrL - palmStartL;

            // Palm Distance Travelled
            if (distL >= handSwipeDistance)
            {
                float avgVelL = AverageVelocity(palmCurrL, palmPrevL, avgVelTotal, countVel);

                // Palm Average Velocity
                if (avgVelL >= handSwipeVelocity)
                {
                    //Debug.Log(Vector3.Dot(leftHand.GetPalmNormal(), transform.forward));
                    if (Vector3.Dot(leftHand.GetPalmNormal(), transform.right) > 0.9 || Vector3.Dot(leftHand.GetPalmNormal(), transform.right) < -0.9)
                    {
                        // Previous Palm Position
                        palmPrevL = transform.InverseTransformPoint(leftPalm.transform.position).x;

                        return("right");
                    }
                }

                // Previous Palm Position
                palmPrevL = transform.InverseTransformPoint(leftPalm.transform.position).x;
            }
            else if (distL <= -handSwipeDistance)
            {
                float avgVelL = AverageVelocity(palmCurrL, palmPrevL, avgVelTotal, countVel);

                // Palm Average Velocity
                if (avgVelL <= -handSwipeVelocity)
                {
                    if (Vector3.Dot(leftHand.GetPalmNormal(), transform.right) < -0.9 || Vector3.Dot(leftHand.GetPalmNormal(), transform.right) > 0.9)
                    {
                        // Previous Palm Position
                        palmPrevL = transform.InverseTransformPoint(leftPalm.transform.position).x;

                        return("left");
                    }
                }

                // Previous Palm Position
                palmPrevL = transform.InverseTransformPoint(leftPalm.transform.position).x;
            }
        }
        // Right Hand
        else if (stateR == "Active")
        {
            // Current Palm Position
            palmCurrR = transform.InverseTransformPoint(rightPalm.transform.position).x;

            float distR = palmCurrR - palmStartR;

            // Palm Distance Travelled
            if (distR <= -handSwipeDistance)
            {
                float avgVelR = AverageVelocity(palmCurrR, palmPrevR, avgVelTotal, countVel);

                // Palm Average Velocity
                if (avgVelR <= -handSwipeVelocity)
                {
                    if (Vector3.Dot(rightHand.GetPalmNormal(), transform.right) > 0.9 || Vector3.Dot(rightHand.GetPalmNormal(), transform.right) < -0.9)
                    {
                        // Previous Palm Position
                        palmPrevR = transform.InverseTransformPoint(rightPalm.transform.position).x;

                        return("left");
                    }
                }

                // Previous Palm Position
                palmPrevR = transform.InverseTransformPoint(rightPalm.transform.position).x;
            }
            else if (distR >= handSwipeDistance)
            {
                float avgVelR = AverageVelocity(palmCurrR, palmPrevR, avgVelTotal, countVel);

                // Palm Average Velocity
                if (avgVelR >= handSwipeVelocity)
                {
                    if (Vector3.Dot(rightHand.GetPalmNormal(), transform.right) > 0.9 || Vector3.Dot(rightHand.GetPalmNormal(), transform.right) < -0.9)
                    {
                        // Previous Palm Position
                        palmPrevR = transform.InverseTransformPoint(rightPalm.transform.position).x;

                        return("right");
                    }

                    // Previous Palm Position
                    palmPrevR = transform.InverseTransformPoint(rightPalm.transform.position).x;
                }
            }
        }

        return(null);
    }     // END OF HAND SWIPED X
예제 #24
0
    // Update is called once per frame
    void Update()
    {
        Frame       frame       = controller.Frame();
        GestureList gesturelist = frame.Gestures();

        palmnormal = m_HandModel.GetPalmNormal();

        for (int i = 0; i < gesturelist.Count; i++)
        {
            Gesture gesture = gesturelist [i];
            change = 0;
            if (m_HandModel.GetLeapHand().IsRight)
            {
                if (indxextend = m_HandModel.fingers [1].GetLeapFinger().IsExtended)
                {
                    if (palmnormal.y < 0)                                               //when palmnormal.y > 0, it means the palm is facing up.
                    {
                        Debug.Log("The hand is facing down");
                        if (gesture.Type == Gesture.GestureType.TYPESWIPE)
                        {
                            SwipeGesture Swipe          = new SwipeGesture(gesture);
                            Vector       swipeDirection = Swipe.Direction;
                            if (swipeDirection.y < 0)
                            {
                                Debug.Log("Tempo Down");
                                change += 2f;
                                ch      = 1;
                                if (audio.pitch > 0)
                                {
                                    audio.pitch -= Time.deltaTime * change / timeToDecrease;
                                }
                                else
                                {
                                    Debug.Log("The pitch is below zero. Exitting application.");
                                }
                            }
                        }
                    }
                    else if (palmnormal.y > 0)                                                  // when palmnormal.y < 0, it means the palm is facing down.
                    {
                        Debug.Log("The hand is facing up");
                        if (gesture.Type == Gesture.GestureType.TYPESWIPE)
                        {
                            SwipeGesture Swipe          = new SwipeGesture(gesture);
                            Vector       swipeDirection = Swipe.Direction;
                            if (swipeDirection.y > 0)
                            {
                                Debug.Log("Tempo Up");
                                change -= 2f;
                                ch      = 0;
                                if (audio.pitch > 0)
                                {
                                    audio.pitch -= Time.deltaTime * change / timeToDecrease;
                                }
                                else
                                {
                                    Debug.Log("The pitch is below zero. Exitting application.");
                                }
                            }
                        }
                    }
                }
            }
        }
    }