Exemple #1
0
    // Update is called once per frame
    void Update()
    {
        //Frame frame = controller.Frame(); // controller is a Controller object
        //if (frame.Hands.Count > 0)
        //{

        //List<Hand> hands = frame.Hands;
        //Hand firstHand = hands[0];

        //print(firstHand.Fingers[1].TipPosition.ToVector3());
        //if (initHand == false)
        //{
        //    hand_model = GetComponent("HandModels") as HandModel;
        //    print(hand_model);
        //    //right_leap_hand = hand_model.GetLeapHand();
        //    //if (right_leap_hand == null) Debug.LogError("No right_leap_hand founded");
        //    //initHand = true;

        //}

        //if (initHand == true)
        //{

        //    for (int i = 0; i < HandModel.NUM_FINGERS; i++)
        //    {
        //        FingerModel finger = hand_model.fingers[i];
        //        // draw ray from finger tips (enable Gizmos in Game window to see)
        //        Debug.DrawRay(finger.GetTipPosition(), finger.GetRay().direction, Color.red);
        //    }
        //}
        //}


        //LeapRightHand.localRotation = Quaternion.Euler(new Vector3(0, 0, 0));

        //readObject();

        Frame frame = controller.Frame(); // controller is a Controller object

        if (frame.Hands.Count > 0)
        {
            //if (initHand == true)
            //{
            //print(frame.Hands.Count);
            List <Hand> hands = frame.Hands;
            right_leap_hand = hands[0];
            if (right_leap_hand.IsRight)
            {
                //Leap.Unity.Pose pose = new Leap.Unity.Pose(right_leap_hand.PalmPosition.ToVector3(), right_leap_hand.Rotation.ToQuaternion());
                LeapTransform leapMatrix = transform.GetLeapMatrix();
                //palmPossition[0] = right_leap_hand.PalmPosition.ToVector3();
                //palmPossition[1] = pose.position;

                //Vector3 handPosition = pose.position;
                //print(palmPossition[0]);
                //float handYBasis = right_leap_hand.PalmNormal.Roll;

                //float pitch = right_leap_hand.Direction.Pitch;
                //float yaw = right_leap_hand.Direction.Yaw;
                //float x = right_leap_hand.PalmNormal.Pitch;

                //float roll = right_leap_hand.PalmNormal.Roll;
                ////Vector normalPalm = new Vector(pitch, yaw, roll);
                //LeapQuaternion handRotation = right_leap_hand.Basis.rotation;

                //handRotation.z = roll;
                //handRotation.y = yaw;
                //handRotation.x = pitch;

                //Vector handZBasis = -right_leap_hand.Direction;
                Vector handOrigin = right_leap_hand.PalmPosition;
                Vector normalPalm = right_leap_hand.PalmNormal;
                //print(normalPalm);
                // print(handOrigin.Normalized);

                //print(xBasis);
                //print(Matrix4x4.TRS(handOrigin,
                //     Quaternion.identity,
                //     new Vector3(transform.lossyScale.x, transform.lossyScale.x, transform.lossyScale.z)));
                //print(rayStart.transform.worldToLocalMatrix);
                //Matrix handTransform = new Matrix(handXBasis, handYBasis, handZBasis, handOrigin);
                //handTransform = handTransform.RigidInverse();
                //Vector transformedPosition = handTransform.TransformPoint(right_leap_hand.PalmPosition);
                //float locationPart = normalPalm.x
                Vector3 normalPalmUnity  = leapMatrix.TransformDirection(normalPalm).ToVector3();
                Vector3 leapHandPosition = leapMatrix.TransformPoint(handOrigin).ToVector3();
                //Quaternion leapHandDirection = leapMatrix.translation
                //Quaternion leapHandDirection = handRotation.ToQuaternion();

                leapHandPosition.y       -= 1.8f;
                leapHandPosition.x       -= 0.7f;
                LeapRightHandRay.position = leapHandPosition;


                //print(leapHandDirection);
                //Vector3 rotationToHand = new Vector3(leapHandDirection.eulerAngles.x, leapHandDirection.eulerAngles.y, leapHandDirection.eulerAngles.z);
                rayStart = Instantiate(emptyObj, LeapRightHandRay.position, Quaternion.identity, LeapRightHandRay);

                //print(leapHandDirection.eulerAngles);
                LeapRightHandRay.forward = normalPalmUnity;
                //LeapRightHandRay.localRotation = Quaternion.Euler(rotationToHand);
                //LeapRightHandRay.localRotation = Quaternion.FromToRotation(LeapRightHandRay.forward, normalPalmUnity);
                //print(LeapRightHandRay.forward);
                //float step = speed / 4 * Time.deltaTime;
                //readObject();

                //print(printMessage.isActivated);
                //cubeRubick.transform.position = Vector3.MoveTowards(cubeRubick.transform.position, LeapRightHandRay.position, step);

                //Finger leapFinger = firstHand.Fingers[1];
                //Vector transformedPosition = handTransform.TransformPoint(leapFinger.TipPosition);
                //Vector transformedDirection = handTransform.TransformDirection(leapFinger.Direction);
                //print(transformedPosition);
                // Do something with the transformed fingers


                //Leap.Vector palmPosition = firstHand.PalmPosition;
                //Leap.Vector palmDirection = firstHand.PalmNormal;
                //Vector3 vectpalmPosition = new Vector3(palmPosition.x,
                //                                        palmPosition.y,
                //                                        palmPosition.z);

                //print(vectpalmPosition);

                ////print("Trasform ray:");
                ////print(LeapRightHand.position);
                ////print("Trasform hand pos:");
                ////print(vectpalmPosition);

                //initHand = false;


                //GameObject rayStart = Instantiate(emptyObj, vectpalmPosition, Quaternion.identity, parentHand);


                ////Vector3 unityPosition = ToPositionVector3(palmDirection);

                ////LeapRightHand.localRotation = Quaternion.Euler(new Vector3(0, 0, 0));

                //Vector3 ray = rayStart.transform.position;
                //RaycastHit hit;
                ////print(ray);
                ////Intersecteaza raza vreun obiect in layerMask ?
                //if (Physics.Raycast(ray, LeapRightHand.forward, out hit, Mathf.Infinity, layerMask))
                //{
                //    Debug.DrawRay(ray, LeapRightHand.forward * hit.distance, Color.yellow);
                //    print(hit.collider.gameObject);
                //    //print(hit.collider.gameObject.name);
                //}
                //else
                //{
                //    Debug.DrawRay(ray, LeapRightHand.forward * 1000, Color.green);
                //}

                //print(firstHand.PalmNormal);

                // }
                //}
                //}
            }
        }
    }
Exemple #2
0
    // Update is called once per frame
    void Update()
    {
        Frame frame = controller.Frame();

        if (frame.Hands.Count > 1)
        {
            List <Hand> hands = frame.Hands;
            nrOfHit  = 0;
            leapHand = hands[1];
            LeapTransform             leapMatrix = transform.GetLeapMatrix();
            List <List <GameObject> > cubeSides  = new List <List <GameObject> >()
            {
                cubeState.up,
                cubeState.down,
                cubeState.left,
                cubeState.right,
                cubeState.front,
                cubeState.back
            };
            if (leapHand.IsLeft)
            {
                for (int f = 0; f < leapHand.Fingers.Count; f++)
                {
                    Finger  leapFinger           = leapHand.Fingers[f];
                    Vector  transformedPosition  = leapMatrix.TransformPoint(leapFinger.TipPosition);
                    Vector3 transformedDirection = leapMatrix.TransformDirection(leapFinger.Direction).ToVector3();
                    Vector3 fingerPos            = transformedPosition.ToVector3();
                    fingerPos.x        += correctionX;
                    fingerPos.y        += correctionY;
                    fingers[f].position = fingerPos;

                    fingers[f].forward = transformedDirection;
                    RaycastHit hit;
                    if (Physics.Raycast(fingerPos, fingers[f].forward, out hit, 1, layerMask))
                    {
                        Debug.DrawRay(fingerPos, fingers[f].forward * hit.distance, Color.yellow);
                        //print(hit.collider.gameObject);
                        foreach (List <GameObject> cubeSide in cubeSides)
                        {
                            print(cubeSide);
                            if (cubeSide.Contains(hit.collider.gameObject))
                            {
                                //make it childrens to the side
                                //cubeState.PickUp(cubeSide);
                                //start the side rotation logic
                                //cubeSide[4].transform.parent.GetComponent<PivitRotation>().Rotate(cubeSide);
                                //hitCountFaces[hit.collider.gameObject.name]++;
                                hitCountFaces[hit.collider.gameObject.name]++;
                                string colFace = hit.collider.gameObject.name;
                                print(colFace);
                            }
                        }
                        //objectFaces.Add(hit.collider.gameObject);
                    }
                    else
                    {
                        Debug.DrawRay(fingerPos, fingers[f].forward * 1, Color.green);
                        nrOfHit++;
                    }
                }

                string faceHitDeb = getHitFace();
                print(faceHitDeb);
                Quaternion handRotation = leapMatrix.TransformQuaternion(leapHand.Rotation).ToQuaternion();
                rotationFace = Quaternion.Inverse((previosRotation * Quaternion.Inverse(handRotation)));
            }

            previosRotation = leapMatrix.TransformQuaternion(leapHand.Rotation).ToQuaternion();
        }
    }