コード例 #1
0
    // Update is called once per frame
    void Update()
    {
        if (controller.IsConnected)
        {                                     //controller is a Controller object
            Frame frame = controller.Frame(); //The latest frame
            foreach (Hand hand in frame.Hands)
            {
                if (hand.IsRight)
                {
                    // For Orion, can use leapService and LeapProvider class for quicker operations.
                    //transform.position = hand.PalmPosition.ToVector3() +
                    //hand.PalmNormal.ToVector3() *
                    //(transform.localScale.y * .5f + .02f);
                    //transform.rotation = hand.Basis.Rotation();

                    Leap.Vector position      = hand.PalmPosition;
                    Vector3     unityPosition = position.ToUnityScaled(false);
                    // print(unityPosition);
                    Vector3 worldPosition = hc.transform.TransformPoint(unityPosition);
                    //print(worldPosition);
                    Leap.Vector norm      = hand.PalmNormal;
                    Vector3     unityNorm = norm.ToUnityScaled(false);
                    followTarget.transform.position = worldPosition + unityNorm * (followTarget.transform.localScale.y * .5f + .02f);
                    followTarget.transform.rotation = hand.Basis.Rotation();
                }
            }
        }
    }
コード例 #2
0
ファイル: DaoTools.cs プロジェクト: daqians/UnityCluster
    //将Leap Motion中获取到的坐标信息转化为Unity的世界坐标
    public static Vector3 leapVectorToUnityVector3(HandController hc, Leap.Vector leapVector)
    {
        Vector3 unityPosition_now = leapVector.ToUnityScaled(false);
        Vector3 worldPosition_now = hc.transform.TransformPoint(unityPosition_now);

        return(worldPosition_now);
    }
コード例 #3
0
    // Update is called once per frame
    void Update()
    {
        this.currentFrame = hc.GetFrame();



        foreach (var h in hc.GetFrame().Hands)
        {
            if (h.IsRight)
            {
                righthandPos = h.PalmPosition.ToUnity();

                razorObj.transform.position = new Vector3(righthandPos.x, righthandPos.y, righthandPos.z);



                righthandRotation = new Vector3(h.Direction.Pitch, h.Direction.Yaw, h.Direction.Roll);


                //   this.lblRightHandPosition.text = string.Format("Right Hand Position: {0}", h.PalmPosition.ToUnity());
                // this.lblRightHandRotation.text = string.Format("Right Hand Rotation: <{0},{1},{2}>", h.Direction.Pitch, h.Direction.Yaw, h.Direction.Roll);

                if (this.razorObj != null)
                {
                    this.razorObj.transform.rotation = Quaternion.EulerRotation(-h.Direction.Pitch, -h.Direction.Yaw, h.PalmNormal.Roll);
                }

                foreach (var f in h.Fingers)
                {
                    if (f.Type == Finger.FingerType.TYPE_THUMB)
                    {
                        // this code converts the tip position from leap motion to unity world position
                        Leap.Vector position      = f.TipPosition;
                        Vector3     unityPosition = position.ToUnityScaled();
                        Vector3     worldPosition = hc.transform.TransformPoint(unityPosition);

                        //  this.razorObj.transform.rotation = Quaternion.Euler(f.Direction.Pitch, f.Direction.Yaw, f.Direction.Roll);
                        //worldPosition = f.TipPosition.ToUnity();
                        //razorObj.transform.position = new Vector3(worldPosition.x, worldPosition.y, worldPosition.z);

                        //string msg = string.Format("Finger ID:{0} Finger Type: {1} Tip Position: {2}", f.Id, f.Type(), worldPosition);
                        //Debug.Log(msg);
                    }
                }
            }
            if (h.IsLeft)
            {
                //this.lblLeftHandPosition.text = string.Format("Left Hand Position: {0}", h.PalmPosition.ToUnity());
                //this.lblLeftHandRotation.text = string.Format("Left Hand Rotation: <{0},{1},{2}>", h.Direction.Pitch, h.Direction.Yaw, h.Direction.Roll);

                if (this.razorObj != null)
                {
                    this.razorObj.transform.rotation = Quaternion.EulerRotation(h.Direction.Pitch, h.Direction.Yaw, h.Direction.Roll);
                }
            }
        }
    }
コード例 #4
0
        //multified
        void HandDistinguisher(Leap.Hand _curHand)
        {
            Leap.Vector objPos   = _curHand.PalmPosition;
            Vector3     unityPos = objPos.ToUnityScaled();
            Vector3     worldPos = this.transform.TransformPoint(unityPos);

            if (!_curHand.IsLeft)
            {
                RightHandPos = worldPos;
            }
            else
            {
                LeftHandPos = worldPos;
            }
        }
コード例 #5
0
ファイル: Aim.cs プロジェクト: Liljan/Handgun
    // Update is called once per frame
    void Update()
    {
        if (!GLOBAL.IS_PAUSED)
        {
            if (USE_MOUSE)
            {
                // MOUSE CODE, code to move crosshair
                pos = new Vector3(Input.mousePosition.x, Input.mousePosition.y, zDistance);
                pos = Camera.main.ScreenToWorldPoint(pos);
                transform.position = pos;
            }
            else
            {
                // LEAP MOTION, code to move crosshair
                FingerList fl = hc.GetFrame().Hands[currentHand].Fingers.FingerType(Finger.FingerType.TYPE_INDEX);
                Finger indexfinger = fl[0];
                fingerpos = indexfinger.StabilizedTipPosition;

                Vector3 indexPostion = fingerpos.ToUnityScaled(false);

                transform.position = hc.transform.TransformPoint(indexPostion.x, indexPostion.y, 1f);
            }
        }
    }
コード例 #6
0
ファイル: Aim.cs プロジェクト: Liljan/Handgun
    // Update is called once per frame
    void Update()
    {
        if (!GLOBAL.IS_PAUSED)
        {
            if (USE_MOUSE)
            {
                // MOUSE CODE, code to move crosshair
                pos = new Vector3(Input.mousePosition.x, Input.mousePosition.y, zDistance);
                pos = Camera.main.ScreenToWorldPoint(pos);
                transform.position = pos;
            }
            else
            {
                // LEAP MOTION, code to move crosshair
                FingerList fl          = hc.GetFrame().Hands[currentHand].Fingers.FingerType(Finger.FingerType.TYPE_INDEX);
                Finger     indexfinger = fl[0];
                fingerpos = indexfinger.StabilizedTipPosition;

                Vector3 indexPostion = fingerpos.ToUnityScaled(false);

                transform.position = hc.transform.TransformPoint(indexPostion.x, indexPostion.y, 1f);
            }
        }
    }
コード例 #7
0
ファイル: GrabMyCube.cs プロジェクト: ZhouDavid/FlyingCar
    void Update()
    {
        this.currentFrame = hc.GetFrame();
        GestureList gestures = this.currentFrame.Gestures();

        foreach (Gesture g in gestures)
        {
            Debug.Log(g.Type);

            if (g.Type == Gesture.GestureType.TYPECIRCLE)
            {
                // create the cube ...
                if (this.cube == null)
                {
                    this.cube = GameObject.Instantiate(this.cubePrefab,
                                                       this.cubePrefab.transform.position,
                                                       this.cubePrefab.transform.rotation) as GameObject;
                }
                //this.cube.transform.position =
            }
            if (g.Type == Gesture.GestureType.TYPESWIPE)
            {
                if (this.cube != null)
                {
                    Destroy(this.cube);
                    this.cube = null;
                }
            }
        }

        foreach (var h in hc.GetFrame().Hands)
        {
            if (h.IsRight)
            {
                //this.lblRightHandPosition.text = string.Format("Right Hand Position: {0}", h.PalmPosition.ToUnity());
                //this.lblRightHandRotation.text = string.Format("Right Hand Rotation: ", h.Direction.Pitch, h.Direction.Yaw, h.Direction.Roll);

                if (this.cube != null)
                {
                    this.cube.transform.rotation = Quaternion.EulerRotation(h.Direction.Pitch, h.Direction.Yaw, h.Direction.Roll);
                }

                foreach (var f in h.Fingers)
                {
                    if (f.Type == Finger.FingerType.TYPE_INDEX)
                    {
                        // this code converts the tip position from leap motion to unity world position
                        Leap.Vector position      = f.TipPosition;
                        Vector3     unityPosition = position.ToUnityScaled(false);
                        Vector3     worldPosition = hc.transform.TransformPoint(unityPosition);

                        //string msg = string.Format("Finger ID:{0} Finger Type: {1} Tip Position: {2}", f.Id, f.Type(), worldPosition);
                        //Debug.Log(msg);
                    }
                }
            }
            if (h.IsLeft)
            {
                //this.lblLeftHandPosition.text = string.Format("Left Hand Position: {0}", h.PalmPosition.ToUnity());
                //this.lblLeftHandRotation.text = string.Format("Left Hand Rotation: ", h.Direction.Pitch, h.Direction.Yaw, h.Direction.Roll);

                if (this.cube != null)
                {
                    this.cube.transform.rotation = Quaternion.EulerRotation(h.Direction.Pitch, h.Direction.Yaw, h.Direction.Roll);
                }
            }
        }
    }