/// <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(); m_ManipulatedObject = gesture.TargetObject; if (!ParentCollisionDetector.UseColliderProxy) { if (ParentCollisionDetector.UseBoundingBox) { m_SelectedVerticesList = Utilities.GetBoundingBoxVertices(m_ManipulatedObject); } else { m_SelectedVerticesList = GetVerticesInChildren(m_ManipulatedObject); } } else { m_SelectedVerticesList = GetVerticesInChildren(m_ColliderProxy); } return(true); }
/// <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 = m_LastHit.Pose; 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; } }
/// <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, s_ObjectVerticalPlacementOffset, MaxTranslationDistanceInMeters, ObjectTranslationMode); // Discards invalid position. if (!desiredPlacement.HoveringPosition.HasValue || !desiredPlacement.PlacementPosition.HasValue) { return; } m_ManipulatedObject = gesture.TargetObject; // Drops the value when collision occurs. if (TestCollision(desiredPlacement.PlacementPosition.Value)) { m_CollisionEvent.Trigger(m_ManipulatedObject); return; } if (desiredPlacement.PlacementRotation.HasValue) { // Rotates if the plane direction has changed. if (((desiredPlacement.PlacementRotation.Value * Vector3.up) - transform.up) .sqrMagnitude > k_MinimumSquaredDistance) { m_CollisionEvent.Trigger(m_ManipulatedObject); return; } else { m_DesiredRotation = transform.rotation; } } // If desired position is lower than the 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.PlacementPlane.HasValue) { m_LastHit = desiredPlacement.PlacementPlane.Value; } }
/// <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) * _rotationRateDegreesDrag; transform.Rotate(0.0f, rotationAmount, 0.0f); }
/// <summary> /// Finishes the translation. /// </summary> /// <param name="gesture">The current gesture.</param> protected override void OnEndManipulation(DragGesture gesture) { if (m_CollisionEvent.IsTriggering()) { return; } 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 > MaxTranslationDistanceInMeters) { desiredLocalPosition = desiredLocalPosition.normalized * MaxTranslationDistanceInMeters; } desiredPose.position = transform.parent.TransformPoint(desiredLocalPosition); Anchor newAnchor = m_LastHit.Trackable.CreateAnchor(desiredPose); if (TestCollision(newAnchor.transform.position)) { m_CollisionEvent.Trigger(gesture.TargetObject); return; } var rotationDifference = (desiredPose.rotation * Vector3.up) - newAnchor.transform.up; if (rotationDifference.sqrMagnitude > k_MinimumSquaredDistance) { m_CollisionEvent.Trigger(gesture.TargetObject); return; } // Translates the model. transform.parent = newAnchor.transform; m_DesiredLocalPosition = Vector3.zero; // Discards if the plane direction has changed. m_DesiredRotation = newAnchor.transform.rotation; Destroy(oldAnchor); // Makes sure position is updated one last time. m_IsActive = true; }
/// <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); } gameObject.GetComponent <PhotonView>().RequestOwnership(); return(true); }
/// <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 (checkRotationToggle() == false) { return(false); } return(true); }
/// <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; }
private void OnGestureStarted(DragGesture gesture) { if (m_IsManipulating) { return; } if (CanStartManipulationForGesture(gesture)) { m_IsManipulating = true; gesture.onUpdated += OnUpdated; gesture.onFinished += OnFinished; OnStartManipulation(gesture); } }
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> /// 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); } gameObject.GetComponent <PhotonView>().RequestOwnership(); // 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); _ShowAndroidToastMessage("after best " + desiredPlacement.UpdatedGroundingPlaneHeight.ToString()); 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_DesiredLocalPosition.y = m_GroundingPlaneHeight; 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> /// Continues the translation. /// </summary> /// <param name="gesture">The current gesture.</param> protected override void OnContinueManipulation(DragGesture gesture) { m_IsActive = true; TrackableHit hit; if (Frame.Raycast(gesture.Position.x, gesture.Position.y, TrackableHitFlags.PlaneWithinBounds, out hit)) { if (hit.Trackable is DetectedPlane) { DetectedPlane plane = hit.Trackable as DetectedPlane; if (IsPlaneTypeAllowed(plane.PlaneType)) { Vector3 desiredPosition = hit.Pose.position; m_DesiredLocalPosition = transform.parent.InverseTransformPoint(desiredPosition); // Rotate if the plane direction has changed. if (((hit.Pose.rotation * Vector3.up) - transform.up).magnitude > k_DiffThreshold) { m_DesiredRotation = hit.Pose.rotation; } else { m_DesiredRotation = transform.rotation; } // If desired position is lower than current position, don't drop it until it's finished. if (m_DesiredLocalPosition.y < transform.localPosition.y) { m_DesiredLocalPosition.y = transform.localPosition.y; } if (m_DesiredLocalPosition.magnitude > MaxTranslationDistance) { m_DesiredLocalPosition = m_DesiredLocalPosition.normalized * MaxTranslationDistance; } m_LastHit = hit; } } } }
/// <summary> /// Continues the translation. /// </summary> /// <param name="gesture">The current gesture.</param> protected override void OnContinueManipulation(DragGesture gesture) { _isActive = true; TransformationUtility.Placement desiredPlacement = TransformationUtility.GetBestPlacementPosition( transform.parent.position, gesture.Position, _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. _desiredLocalPosition = transform.parent.InverseTransformPoint( desiredPlacement.HoveringPosition.Value); _desiredAnchorPosition = desiredPlacement.PlacementPosition.Value; _groundingPlaneHeight = desiredPlacement.UpdatedGroundingPlaneHeight; if (desiredPlacement.PlacementRotation.HasValue) { // Rotate if the plane direction has changed. if (((desiredPlacement.PlacementRotation.Value * Vector3.up) - transform.up) .magnitude > _diffThreshold) { _desiredRotation = desiredPlacement.PlacementRotation.Value; } else { _desiredRotation = transform.rotation; } } if (desiredPlacement.PlacementPlane.HasValue) { _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(_desiredAnchorPosition, _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 = _lastHit.Trackable.CreateAnchor(desiredPose); transform.parent = newAnchor.transform; Destroy(oldAnchor); _desiredLocalPosition = Vector3.zero; // Rotate if the plane direction has changed. if (((desiredPose.rotation * Vector3.up) - transform.up).magnitude > _diffThreshold) { _desiredRotation = desiredPose.rotation; } else { _desiredRotation = transform.rotation; } // Make sure position is updated one last time. _isActive = true; }
/// <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; _ShowAndroidToastMessage("final at " + transform.parent.position.y.ToString()); }
/// <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; }
/// <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; _ShowAndroidToastMessage("start at " + m_GroundingPlaneHeight.ToString()); }
/// <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. Debug.Log(gesture.TargetObject.ToString()); // Raycast against the location the player touched to search for objects. RaycastHit[] hits; hits = Physics.RaycastAll(desiredPlacement.PlacementPosition.Value, desiredPlacement.PlacementRotation.Value * Vector3.up); if (hits.Length > 1) { //The the one before the last one in the stack. Collider lastCollider = hits[hits.Length - 1].collider; if (lastCollider.gameObject.Equals(gesture.TargetObject.transform.GetChild(2).gameObject)) { //The one before the last one in the stack. lastCollider = hits[hits.Length - 2].collider; } float x = lastCollider.transform.position.x; float y = lastCollider.transform.position.y; float z = lastCollider.transform.position.z; //float deltaY = 0; //Added all the y-dimensions of the gameObjects in the stack /*for (int i = 0; i < hits.Length; i++) * { * Collider collider = hits[i].collider; * deltaY += collider.bounds.size.y; * }*/ //Subtracted the y-dimension of the given gameObject //deltaY -= GetComponent<Collider>().bounds.size.y; float deltaY = lastCollider.bounds.size.y - 0.011f; m_DesiredLocalPosition = transform.parent.InverseTransformPoint( new Vector3(x, y + deltaY, z)); m_DesiredAnchorPosition = new Vector3(x, y + deltaY, z); m_DesiredRotation = lastCollider.transform.rotation; } else { m_DesiredLocalPosition = transform.parent.InverseTransformPoint( desiredPlacement.HoveringPosition.Value); m_DesiredAnchorPosition = desiredPlacement.PlacementPosition.Value; 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; } } } m_GroundingPlaneHeight = desiredPlacement.UpdatedGroundingPlaneHeight; if (desiredPlacement.PlacementPlane.HasValue) { m_LastHit = desiredPlacement.PlacementPlane.Value; } } }
/// <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; m_IsActive = true; }
/// <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); }
/// <summary> /// Function called when the manipulation is started. /// </summary> /// <param name="gesture">The current gesture.</param> protected override void OnStartManipulation(DragGesture gesture) { _groundingPlaneHeight = transform.parent.position.y; }
private void OnFinished(DragGesture gesture) { m_IsManipulating = false; OnEndManipulation(gesture); }