protected override void DragUpdate(InteractiveHandle target, DragUpdateInfo info) { if (target != ownerHandle) { return; } var currentDir = info.translation.currentPosition - transform.position; var deltaAngle = Vector3.SignedAngle(m_LastDirection, currentDir, m_Normal); m_TotalAngle += deltaAngle; m_LastDirection = currentDir; if (rotationUpdated != null) { rotationUpdated.Invoke(new RotationUpdateInfo( new RotationInfo( // World m_TotalAngle, deltaAngle, m_Normal), new RotationInfo( // Local m_TotalAngle, deltaAngle, transform.worldToLocalMatrix.rotation * m_Normal))); } }
protected override void DragUpdate(InteractiveHandle target, DragUpdateInfo info) { if (target != ownerHandle) { return; } var delta = GetWorldTranslationDelta(info.translation, m_InitialPosWorld); m_TotalTranslation = m_TotalTranslation + delta; m_CurrentDirection = delta.normalized; var inverseRotation = Quaternion.Inverse(transform.rotation); if (translationUpdated != null) { translationUpdated.Invoke(new TranslationUpdateInfo( //World new TranslationInfo( m_InitialPosWorld, delta, m_TotalTranslation, m_CurrentDirection), //Local new TranslationInfo( m_InitialPosLocal, inverseRotation * delta, inverseRotation * m_TotalTranslation, inverseRotation * m_CurrentDirection) )); } }
protected override void DragBegin(InteractiveHandle target, DragBeginInfo info) { if (target != ownerHandle) { return; } m_LastDirection = info.translation.initialPosition - transform.position; m_TotalAngle = 0f; m_Normal = planeNormal; if (rotationBegun != null) { rotationBegun.Invoke(new RotationBeginInfo( new RotationInfo( // World 0, 0, m_Normal), new RotationInfo( // Local 0, 0, transform.worldToLocalMatrix.rotation * m_Normal))); } }
protected override void DragBegin(InteractiveHandle target, DragBeginInfo info) { if (target != ownerHandle) { return; } m_InitialPosWorld = info.translation.initialPosition; m_InitialPosLocal = Quaternion.Inverse(transform.localRotation) * transform.localPosition; m_TotalTranslation = Vector3.zero; if (translationBegun != null) { translationBegun.Invoke(new TranslationBeginInfo( //World new TranslationInfo( m_InitialPosWorld, Vector3.zero, Vector3.zero, transform.forward), //Local new TranslationInfo( m_InitialPosLocal, Vector3.zero, Vector3.zero, transform.localRotation * Vector3.forward))); } OnTranslationBegin(info.translation); }
protected override void DragEnd(InteractiveHandle target, DragEndInfo info) { if (target != ownerHandle) { return; } if (translationEnded != null) { translationEnded.Invoke(new TranslationEndInfo( //World new TranslationInfo( m_InitialPosWorld, Vector3.zero, m_TotalTranslation, Vector3.zero), //Local new TranslationInfo( m_InitialPosLocal, Vector3.zero, Quaternion.Inverse(transform.rotation) * m_TotalTranslation, Vector3.zero))); } m_CurrentDirection = Vector3.zero; m_TotalTranslation = Vector3.zero; OnTranslationEnd(info.translation); }
public static Vector3 ProjectWorldPositionOnHandle(InteractiveHandle handle, Vector3 position) { if (handle == null) { return(Vector3.zero); } return(handle.GetProjectionPlane(position).ClosestPointOnPlane(position)); }
public static Vector3 ProjectScreenPositionOnHandle(InteractiveHandle handle, Vector2 screenPosition, Camera camera) { if (handle == null || camera == null) { return(Vector3.zero); } var plane = handle.GetProjectionPlane(camera.transform.position); var ray = camera.ScreenPointToRay(screenPosition); float hitDistance; if (!plane.Raycast(ray, out hitDistance)) { return(handle.transform.position); } return(ray.origin + ray.direction * hitDistance); }
public void SetHovered(InteractiveHandle handle) { if (m_ActiveHandle == handle) { return; } m_HoverHandle = handle; if (m_State != State.Dragging) { if (m_ActiveHandle) { var eventData = new HoverEndInfo(); foreach (var behaviour in TakeSnapshot(m_Context.GetHandleBehaviours())) { if (behaviour == null) { continue; } behaviour.DoHoverEnd(m_ActiveHandle, eventData); } } m_ActiveHandle = handle; //If we are dragging, we keep the current active engaged as Hovering and Dragging m_State = m_ActiveHandle != null ? State.Hovering : State.Idle; if (m_ActiveHandle) { var eventData = new HoverBeginInfo(); foreach (var behaviour in TakeSnapshot(m_Context.GetHandleBehaviours())) { if (behaviour == null) { continue; } behaviour.DoHoverBegin(m_ActiveHandle, eventData); } } } }
protected override void DragEnd(InteractiveHandle target, DragEndInfo info) { if (target != ownerHandle) { return; } var worldToLocalRotation = transform.worldToLocalMatrix.rotation; if (rotationEnded != null) { rotationEnded.Invoke(new RotationEndInfo( new RotationInfo( // World m_TotalAngle, 0, m_Normal), new RotationInfo( // Local m_TotalAngle, 0, worldToLocalRotation * m_Normal))); } }