Exemple #1
0
        public static Vector3 ClampedToRect(this Vector3 worldPosition, Pose rectCenterPose,
                                            float rectWidth, float rectHeight)
        {
            bool unused;

            return(worldPosition.ClampedToRect(rectCenterPose, rectWidth, rectHeight, out unused));
        }
    private void moveTarget(Pose oldPose, Pose newPose)
    {
        if (moveTransform == null)
        {
            return;
        }

        // Translate on all three axes.
        var translation = newPose.position - oldPose.position;

        // Rotate only around world up.
        var rotation = Quaternion.AngleAxis(
            maxAbs( // Take the max of two in case angle is degenerate for one.
                Vector3.SignedAngle(
                    oldPose.rotation * Vector3.forward,
                    newPose.rotation * Vector3.forward,
                    Vector3.up
                    ),
                Vector3.SignedAngle(
                    oldPose.rotation * Vector3.up,
                    newPose.rotation * Vector3.up,
                    Vector3.up
                    )
                ) * rotationMult,
            Vector3.up
            );

        var origPose  = moveTransform.ToPose();
        var movedPose = origPose + new Pose(translation, rotation);

        moveTransform.position = movedPose.position;
        moveTransform.rotation = movedPose.rotation;
    }
Exemple #3
0
    public void MoveSelfToPanel()
    {
        var panelPose = new Pose(panelTransform.position, panelTransform.rotation);

        this.transform.SetWorldPose(panelPose);
        panelTransform.SetWorldPose(panelPose);
    }
Exemple #4
0
    public void MoveSelfToBall()
    {
        var ballPose = new Pose(ballTransform.position, ballTransform.rotation);

        this.transform.SetWorldPose(ballPose);
        ballTransform.SetWorldPose(ballPose);
    }
Exemple #5
0
    public void MoveTo(Transform t)
    {
        Pose followingPose = t.ToWorldPose();

        this.transform.SetWorldPose(followingPose);

        t.SetWorldPose(followingPose);
    }
Exemple #6
0
        public static Vector3 ClampedToPlane(this Vector3 worldPosition, Pose planePose)
        {
            var localSpacePoint = worldPosition.From(planePose).position;

            var localSpaceOnPlane = new Vector3(localSpacePoint.x,
                                                localSpacePoint.y, 0f);

            return((planePose * localSpaceOnPlane).position);
        }
Exemple #7
0
        public static Pose Integrated(this Pose thisPose, Movement movement, float deltaTime)
        {
            thisPose.position = movement.velocity * deltaTime + thisPose.position;

            if (movement.angularVelocity.sqrMagnitude > 0.00001f)
            {
                var angVelMag = movement.angularVelocity.magnitude;
                thisPose.rotation = Quaternion.AngleAxis(angVelMag * deltaTime,
                                                         movement.angularVelocity / angVelMag)
                                    * thisPose.rotation;
            }

            return(thisPose);
        }
Exemple #8
0
        public static Vector3 ClampedToRect(this Vector3 worldPosition, Pose rectCenterPose,
                                            float rectWidth, float rectHeight,
                                            out bool isProjectionWithinRect)
        {
            var localSpacePoint = worldPosition.From(rectCenterPose).position;

            var localSpaceOnPlane = new Vector3(Mathf.Clamp(localSpacePoint.x, -rectWidth, rectWidth),
                                                Mathf.Clamp(localSpacePoint.y, -rectHeight, rectHeight), 0f);

            isProjectionWithinRect  = Mathf.Abs(localSpacePoint.x) <= rectWidth;
            isProjectionWithinRect &= Mathf.Abs(localSpacePoint.y) <= rectHeight;

            return((rectCenterPose * localSpaceOnPlane).position);
        }
Exemple #9
0
        public static Vector3 ClampedToRect(this Vector3 worldPosition, Pose rectCenterPose,
                                            float rectWidth, float rectHeight,
                                            out float sqrDistToRect,
                                            out bool isProjectionInRect)
        {
            var localSpacePoint = worldPosition.From(rectCenterPose).position;

            isProjectionInRect  = Mathf.Abs(localSpacePoint.x) <= rectWidth / 2f;
            isProjectionInRect &= Mathf.Abs(localSpacePoint.y) <= rectHeight / 2f;

            var localSpaceOnPlane = new Vector3(Mathf.Clamp(localSpacePoint.x, -rectWidth / 2f, rectWidth / 2f),
                                                Mathf.Clamp(localSpacePoint.y, -rectHeight / 2f, rectHeight / 2f), 0f);

            var positionOnRect = (rectCenterPose * localSpaceOnPlane).position;

            sqrDistToRect = (positionOnRect - worldPosition).sqrMagnitude;

            return(positionOnRect);
        }
Exemple #10
0
        public static void DrawPose(this RuntimeGizmoDrawer drawer,
                                    Pose pose, float radius = 0.10f,
                                    bool drawCube           = false)
        {
            drawer.PushMatrix();

            drawer.matrix = Matrix4x4.TRS(pose.position, pose.rotation, Vector3.one);

            var origColor = drawer.color;

            //drawer.DrawWireSphere(Vector3.zero, radius);
            if (drawCube)
            {
                drawer.DrawCube(Vector3.zero, Vector3.one * radius * 0.3f);
            }
            drawer.DrawPosition(Vector3.zero, radius * 2);

            drawer.color = origColor;

            drawer.PopMatrix();
        }
Exemple #11
0
 /// <summary>
 /// Calls body.MovePosition() and body.MoveRotation() using the argument Pose.
 /// </summary>
 public static void MovePose(this Rigidbody body, Pose pose)
 {
     body.MovePosition(pose.position);
     body.MoveRotation(pose.rotation);
 }
Exemple #12
0
 /// <summary>
 /// Sets body.position and body.rotation using the argument Pose.
 /// </summary>
 public static void SetPose(this Rigidbody body, Pose pose)
 {
     body.position = pose.position;
     body.rotation = pose.rotation;
 }
Exemple #13
0
        public static Vector3 GetLocalPlanePosition(this Vector3 worldPosition, Pose planePose)
        {
            var localSpacePoint = worldPosition.From(planePose).position;

            return(localSpacePoint);
        }
Exemple #14
0
        /// <inheritdoc />
        public override void Enable()
        {
            base.Enable();

            if (leapControllerOrientation == LeapControllerOrientation.Headset)
            {
                // If the leap controller is mounted on a headset then add the LeapXRServiceProvider to the scene
                // The LeapXRServiceProvider can only be attached to a camera
                LeapMotionServiceProvider = CameraCache.Main.gameObject.AddComponent <LeapXRServiceProvider>();
                //If northstar driver is installed, we need to get the LeapOffset values from the .vrsettings file
                //LeapMotionServiceProvider.GetComponent<LeapXRServiceProvider>().deviceOffsetMode = Leap.Unity.LeapXRServiceProvider.DeviceOffsetMode.Transform;
                //private Transform LeapOrigin = GetLeapOffset();
                //LeapMotionServiceProvider.GetComponent<LeapXRServiceProvider>().deviceOrigin = LeapOrigin
                //private Transform LeapOrigin = 0;
                //C:\Program Files (x86)\Steam\steamapps\common\SteamVR\drivers\northstar\resources\settings\default.vrsettings
                string path = @"c:\Program Files (x86)\Steam\steamapps\common\SteamVR\drivers\northstar\resources\settings\default.vrsettings";
                //path = "";

                if (System.IO.File.Exists(path))
                {
                    //Check if we have a valid calibration to read
                    Debug.Log(path + "exists");
                    //Create game object to apply sensor offset
                    GameObject leapProvider = new GameObject("LeapProvider");
                    //Read in data from calibration file
                    string headsetsettings = System.IO.File.ReadAllText(path);
                    Debug.Log(headsetsettings);
                    //Parse data

                    Calibration headset = JsonUtility.FromJson <Calibration>(headsetsettings);

                    Leaptrackerodometryorigin leapoffset = headset.leapTrackerOdometryOrigin;

                    Debug.Log("headset : --" + headset.leapTrackerOdometryOrigin);

                    Vector3    leapposition = new Vector3(leapoffset.position_x, leapoffset.position_y, leapoffset.position_z);
                    Quaternion leaprotation = new Quaternion(leapoffset.rotation_x, leapoffset.rotation_y, leapoffset.rotation_z, leapoffset.rotation_w);
                    //Apply leap offset
                    Leap.Unity.Pose pose = new Leap.Unity.Pose(leapposition, leaprotation);
                    leapProvider.transform.SetLocalPose(pose);

                    LeapMotionServiceProvider.GetComponent <LeapXRServiceProvider>().deviceOrigin     = leapProvider.transform;
                    LeapMotionServiceProvider.GetComponent <LeapXRServiceProvider>().deviceOffsetMode = Leap.Unity.LeapXRServiceProvider.DeviceOffsetMode.Transform;
                    Debug.Log("Applied Leap Offset from North Star vrsettings");
                }
                else
                {
                    Debug.Log(path + " not found, setting default Leap Offset");
                    LeapMotionServiceProvider = CameraCache.Main.gameObject.AddComponent <LeapXRServiceProvider>();
                }
            }

            if (leapControllerOrientation == LeapControllerOrientation.Desk)
            {
                // Create a separate gameobject if the leap controller is on the desk
                GameObject leapProvider = new GameObject("LeapProvider");

                // The LeapServiceProvider does not need to be attached to a camera, but the location of this gameobject is the anchor for the desk hands
                LeapMotionServiceProvider = leapProvider.AddComponent <LeapServiceProvider>();

                // Follow the transform of the main camera by adding the service provider as a child of the main camera
                leapProvider.transform.parent = CameraCache.Main.transform;

                // Apply hand position offset, an offset is required to render the hands in view and in front of the camera
                LeapMotionServiceProvider.transform.position += leapHandsOffset;
            }

            // Add the attachment hands to the scene for the purpose of getting the tracking state of each hand and joint positions
            GameObject leapAttachmentHandsGameObject = new GameObject("LeapAttachmentHands");

            leapAttachmentHands = leapAttachmentHandsGameObject.AddComponent <AttachmentHands>();

            // The first hand in attachmentHands.attachmentHands is always left
            leftAttachmentHand = leapAttachmentHands.attachmentHands[0];

            // The second hand in attachmentHands.attachmentHands is always right
            rightAttachmentHand = leapAttachmentHands.attachmentHands[1];

            // Enable all attachment point flags in the leap hand. By default, only the wrist and the palm are enabled.
            foreach (TrackedHandJoint joint in Enum.GetValues(typeof(TrackedHandJoint)))
            {
                leapAttachmentHands.attachmentPoints |= LeapMotionArticulatedHand.ConvertMRTKJointToLeapJoint(joint);
            }
        }
Exemple #15
0
 public static void SetWorldPose(this Transform t, Pose worldPose)
 {
     t.SetPose(worldPose);
 }