示例#1
0
        /// <summary>
        /// Rotates the object around the y-axis via a Drag gesture.
        /// </summary>
        /// <param name="gesture">The current drag gesture.</param>
        protected override void OnContinueManipulation(DragGesture gesture)
        {
            float      sign    = -1.0f;
            Vector3    forward = Camera.main.transform.TransformPoint(Vector3.forward);
            Quaternion WorldToVerticalOrientedDevice =
                Quaternion.Inverse(Quaternion.LookRotation(forward, Vector3.up));
            Quaternion DeviceToWorld = Camera.main.transform.rotation;
            Vector3    rotatedDelta  = WorldToVerticalOrientedDevice * DeviceToWorld * gesture.Delta;

            float rotationAmount = sign * (rotatedDelta.x / Screen.dpi) * k_RotationRateDegreesDrag;

            transform.Rotate(0.0f, rotationAmount, 0.0f);
        }
示例#2
0
        /// <summary>
        /// Returns true if the manipulation can be started for the given Drag gesture.
        /// </summary>
        /// <param name="gesture">The current gesture.</param>
        /// <returns>True if the manipulation can be started.</returns>
        protected override bool CanStartManipulationForGesture(DragGesture gesture)
        {
            if (!IsSelected())
            {
                return(false);
            }

            if (gesture.TargetObject != null)
            {
                return(false);
            }

            return(true);
        }
示例#3
0
        private void OnGestureStarted(DragGesture gesture)
        {
            if (m_IsManipulating)
            {
                return;
            }

            if (CanStartManipulationForGesture(gesture))
            {
                m_IsManipulating    = true;
                gesture.onUpdated  += OnUpdated;
                gesture.onFinished += OnFinished;
                OnStartManipulation(gesture);
            }
        }
示例#4
0
        private void OnUpdated(DragGesture gesture)
        {
            if (!m_IsManipulating)
            {
                return;
            }

            // Can only transform selected Items.
            if (ManipulationSystem.Instance.SelectedObject != gameObject)
            {
                m_IsManipulating = false;
                OnEndManipulation(gesture);
                return;
            }

            OnContinueManipulation(gesture);
        }
        /// <summary>
        /// Returns true if the manipulation can be started for the given gesture.
        /// </summary>
        /// <param name="gesture">The current gesture.</param>
        /// <returns>True if the manipulation can be started.</returns>
        protected override bool CanStartManipulationForGesture(DragGesture gesture)
        {
            if (gesture.TargetObject == null)
            {
                return(false);
            }

            // If the gesture isn't targeting this item, don't start manipulating.
            if (gesture.TargetObject != gameObject)
            {
                return(false);
            }

            // Select it.
            Select();

            return(true);
        }
        /// <summary>
        /// Continues the translation.
        /// </summary>
        /// <param name="gesture">The current gesture.</param>
        protected override void OnContinueManipulation(DragGesture gesture)
        {
            m_IsActive = true;

            TransformationUtility.Placement desiredPlacement =
                TransformationUtility.GetBestPlacementPosition(
                    transform.parent.position, gesture.Position, m_GroundingPlaneHeight, 0.03f,
                    MaxTranslationDistance, ObjectTranslationMode);

            if (desiredPlacement.HoveringPosition.HasValue &&
                desiredPlacement.PlacementPosition.HasValue)
            {
                // If desired position is lower than current position, don't drop it until it's
                // finished.
                m_DesiredLocalPosition = transform.parent.InverseTransformPoint(
                    desiredPlacement.HoveringPosition.Value);

                m_DesiredAnchorPosition = desiredPlacement.PlacementPosition.Value;

                m_GroundingPlaneHeight = desiredPlacement.UpdatedGroundingPlaneHeight;

                if (desiredPlacement.PlacementRotation.HasValue)
                {
                    // Rotate if the plane direction has changed.
                    if (((desiredPlacement.PlacementRotation.Value * Vector3.up) - transform.up)
                        .magnitude > k_DiffThreshold)
                    {
                        m_DesiredRotation = desiredPlacement.PlacementRotation.Value;
                    }
                    else
                    {
                        m_DesiredRotation = transform.rotation;
                    }
                }

                if (desiredPlacement.PlacementPlane.HasValue)
                {
                    m_LastHit = desiredPlacement.PlacementPlane.Value;
                }
            }
        }
        /// <summary>
        /// Finishes the translation.
        /// </summary>
        /// <param name="gesture">The current gesture.</param>
        protected override void OnEndManipulation(DragGesture gesture)
        {
            GameObject oldAnchor = transform.parent.gameObject;

            Pose desiredPose = new Pose(m_DesiredAnchorPosition, m_LastHit.Pose.rotation);

            Vector3 desiredLocalPosition =
                transform.parent.InverseTransformPoint(desiredPose.position);

            if (desiredLocalPosition.magnitude > MaxTranslationDistance)
            {
                desiredLocalPosition = desiredLocalPosition.normalized * MaxTranslationDistance;
            }

            desiredPose.position = transform.parent.TransformPoint(desiredLocalPosition);

            Anchor newAnchor = m_LastHit.Trackable.CreateAnchor(desiredPose);

            transform.parent = newAnchor.transform;

            Destroy(oldAnchor);

            m_DesiredLocalPosition = Vector3.zero;

            // Rotate if the plane direction has changed.
            if (((desiredPose.rotation * Vector3.up) - transform.up).magnitude > k_DiffThreshold)
            {
                m_DesiredRotation = desiredPose.rotation;
            }
            else
            {
                m_DesiredRotation = transform.rotation;
            }

            // Make sure position is updated one last time.
            m_IsActive = true;
        }
示例#8
0
 /// <summary>
 /// Returns true if the manipulation can be started for the given gesture.
 /// </summary>
 /// <param name="gesture">The current gesture.</param>
 /// <returns>True if the manipulation can be started.</returns>
 protected virtual bool CanStartManipulationForGesture(DragGesture gesture)
 {
     return(false);
 }
示例#9
0
 private void OnFinished(DragGesture gesture)
 {
     m_IsManipulating = false;
     OnEndManipulation(gesture);
 }
示例#10
0
 /// <summary>
 /// Function called when the manipulation is ended.
 /// </summary>
 /// <param name="gesture">The current gesture.</param>
 protected virtual void OnEndManipulation(DragGesture gesture)
 {
     // Optional override.
 }
 /// <summary>
 /// Function called when the manipulation is started.
 /// </summary>
 /// <param name="gesture">The current gesture.</param>
 protected override void OnStartManipulation(DragGesture gesture)
 {
     m_GroundingPlaneHeight = transform.parent.position.y;
 }