Exemplo n.º 1
0
        /// <summary>
        /// Release the instance that was previous grabbed
        /// </summary>
        private void ReleaseInstance(ref GrabbedInstanceInfo grabbedInstanceInfo)
        {
            grabbedInstanceInfo.grabbedInstance.IsGrabbed      = false;
            grabbedInstanceInfo.grabbedInstance.ExpandedBounds = CalculateExpandedBounds(grabbedInstanceInfo.grabbedInstance.Instance);

            // If object is being tracked update new calibration pose at the current location
            if (grabbedInstanceInfo.grabbedInstance.IsCalibrated)
            {
                TrackedObjectBehavior.Calibrate(grabbedInstanceInfo.grabbedInstance);
            }

            StageDressing.Logger.Info($"Released! {grabbedInstanceInfo.grabbedInstance.Instance.name}");

            grabbedInstanceInfo = null;
        }
Exemplo n.º 2
0
        //private void DrawBounds(Bounds b)
        //{

        //    var vectorArray = new Vector3[]
        //    {
        //        new Vector3(b.min.x, b.min.y, b.min.z),
        //        new Vector3(b.max.x, b.min.y, b.min.z),
        //        new Vector3(b.max.x, b.min.y, b.max.z),
        //        new Vector3(b.min.x, b.min.y, b.max.z),
        //        new Vector3(b.min.x, b.max.y, b.min.z),
        //        new Vector3(b.max.x, b.max.y, b.min.z),
        //        new Vector3(b.max.x, b.max.y, b.max.z),
        //        new Vector3(b.min.x, b.max.y, b.max.z)
        //    };

        //    this.lines.positionCount = 8;
        //    this.lines.SetPositions(vectorArray);
        //}

        private void Update()
        {
            // If there is nothing to grab anywhere, do nothing
            if (!this.grabbableInstances.Any())
            {
                return;
            }

            // Check for trigger clicks first as it's debounced and will override simply having the trigger down
            if (InputManager.instance.GetRightTriggerClicked())
            {
                this.rightGrabbed = this.GrabInstance(InputManager.instance.RightController);
                return;
            }

            if (InputManager.instance.GetLeftTriggerClicked())
            {
                this.leftGrabbed = this.GrabInstance(InputManager.instance.LeftController);
                return;
            }

            // If there is no grabbed instance or grabbed device then we are done
            if (this.leftGrabbed == null && this.rightGrabbed == null)
            {
                return;
            }

            // Check for trigger being held down on the device
            if (this.rightGrabbed != null)
            {
                if (InputManager.instance.GetRightTriggerDown())
                {
                    // Trigger held so track instance position with the device
                    Pose?grabbedPose = TrackedDeviceManager.GetDevicePose(rightGrabbed.grabbedDevice);
                    if (grabbedPose == null)
                    {
                        return;
                    }
                    this.rightGrabbed.grabbedInstance.Pose = TrackedDeviceManager.GetTrackedObjectPose(rightGrabbed.grabbedStartPose, rightGrabbed.grabbedDevicePose, grabbedPose.Value);
                    this.rightGrabbed.grabbedInstance.Instance.transform.position = this.rightGrabbed.grabbedInstance.Pose.position;
                    this.rightGrabbed.grabbedInstance.Instance.transform.rotation = this.rightGrabbed.grabbedInstance.Pose.rotation;

                    this.rightGrabbed.grabbedInstance.ExpandedBounds = CalculateExpandedBounds(this.rightGrabbed.grabbedInstance.Instance);
                    //DrawBounds(this.rightGrabbed.grabbedInstance.ExpandedBounds);
                }
                else
                {
                    ReleaseInstance(ref this.rightGrabbed);
                }
            }

            if (this.leftGrabbed != null)
            {
                if (InputManager.instance.GetLeftTriggerDown())
                {
                    // Trigger held so track instance position with the device
                    Pose?grabbedPose = TrackedDeviceManager.GetDevicePose(leftGrabbed.grabbedDevice);
                    if (grabbedPose == null)
                    {
                        return;
                    }
                    this.leftGrabbed.grabbedInstance.Pose = TrackedDeviceManager.GetTrackedObjectPose(leftGrabbed.grabbedStartPose, leftGrabbed.grabbedDevicePose, grabbedPose.Value);
                    this.leftGrabbed.grabbedInstance.Instance.transform.position = this.leftGrabbed.grabbedInstance.Pose.position;
                    this.leftGrabbed.grabbedInstance.Instance.transform.rotation = this.leftGrabbed.grabbedInstance.Pose.rotation;

                    this.leftGrabbed.grabbedInstance.ExpandedBounds = CalculateExpandedBounds(this.leftGrabbed.grabbedInstance.Instance);
                    //DrawBounds(this.leftGrabbed.grabbedInstance.ExpandedBounds);
                }
                else
                {
                    ReleaseInstance(ref this.leftGrabbed);
                }
            }
        }