public FocusDetails GetFocusDetails(IPointingSource pointingSource) { PointerData pointerData; FocusDetails details = default(FocusDetails); if (GetPointerData(pointingSource, out pointerData)) { details = pointerData.End; } return(details); }
public void UpdateHit(RaycastResult result, RaycastHit hit, RayStep sourceRay, int rayStepIndex) { // We do not update the PreviousEndObject here because // it's already been updated in the first physics raycast. RayStepIndex = rayStepIndex; StartPoint = sourceRay.origin; End = new FocusDetails { Point = hit.point, Normal = hit.normal, Object = result.gameObject }; }
public void ResetFocusedObjects(bool clearPreviousObject = true) { if (clearPreviousObject) { PreviousEndObject = null; } End = new FocusDetails { Point = End.Point, Normal = End.Normal, Object = null }; }
public void UpdateHit(RaycastHit hit, RayStep sourceRay, int rayStepIndex) { LastRaycastHit = hit; PreviousEndObject = End.Object; RayStepIndex = rayStepIndex; StartPoint = sourceRay.origin; End = new FocusDetails { Point = hit.point, Normal = hit.normal, Object = hit.transform.gameObject }; }
/// <summary> /// Notifies this gaze manager of its new hit details. /// </summary> /// <param name="focusDetails">Details of the current focus.</param> /// <param name="hitInfo">Details of the focus raycast hit.</param> /// <param name="isRegisteredForFocus">Whether or not this gaze manager is registered as a focus pointer.</param> public void UpdateHitDetails(FocusDetails focusDetails, RaycastHit hitInfo, bool isRegisteredForFocus) { HitInfo = hitInfo; HitObject = isRegisteredForFocus ? focusDetails.Object : null; // If we're not actually registered for focus, we keep HitObject as null so we don't mislead anyone. if (focusDetails.Object != null) { lastHitDistance = (focusDetails.Point - Rays[0].origin).magnitude; UpdateHitPosition(); HitNormal = focusDetails.Normal; } }
/// <summary> /// Update the cursor's transform /// </summary> protected virtual void UpdateCursorTransform() { FocusDetails focusDetails = FocusManager.Instance.GetFocusDetails(Pointer); GameObject newTargetedObject = focusDetails.Object; Vector3 lookForward = Vector3.forward; // Normalize scale on before update targetScale = Vector3.one; // If no game object is hit, put the cursor at the default distance if (newTargetedObject == null) { TargetedObject = null; TargetedCursorModifier = null; targetPosition = RayStep.GetPointByDistance(Pointer.Rays, DefaultCursorDistance); lookForward = -RayStep.GetDirectionByDistance(Pointer.Rays, DefaultCursorDistance); targetRotation = lookForward.magnitude > 0 ? Quaternion.LookRotation(lookForward, Vector3.up) : transform.rotation; } else { // Update currently targeted object TargetedObject = newTargetedObject; if (TargetedCursorModifier != null) { TargetedCursorModifier.GetModifiedTransform(this, out targetPosition, out targetRotation, out targetScale); } else { // If no modifier is on the target, just use the hit result to set cursor position // Get the look forward by using distance between pointer origin and target position // (This may not be strictly accurate for extremely wobbly pointers, but it should produce usable results) float distanceToTarget = Vector3.Distance(Pointer.Rays[0].origin, focusDetails.Point); lookForward = -RayStep.GetDirectionByDistance(Pointer.Rays, distanceToTarget); targetPosition = focusDetails.Point + (lookForward * SurfaceCursorDistance); Vector3 lookRotation = Vector3.Slerp(focusDetails.Normal, lookForward, LookRotationBlend); targetRotation = Quaternion.LookRotation(lookRotation == Vector3.zero ? lookForward : lookRotation, Vector3.up); } } float deltaTime = UseUnscaledTime ? Time.unscaledDeltaTime : Time.deltaTime; // Use the lerp times to blend the position to the target position transform.position = Vector3.Lerp(transform.position, targetPosition, deltaTime / PositionLerpTime); transform.localScale = Vector3.Lerp(transform.localScale, targetScale, deltaTime / ScaleLerpTime); transform.rotation = Quaternion.Lerp(transform.rotation, targetRotation, deltaTime / RotationLerpTime); }
public void UpdateHit(float extent) { PreviousEndObject = End.Object; RayStep firstStep = PointingSource.Rays[0]; RayStep finalStep = PointingSource.Rays[PointingSource.Rays.Length - 1]; RayStepIndex = 0; StartPoint = firstStep.origin; End = new FocusDetails { Point = finalStep.terminus, Normal = (-finalStep.direction), Object = null }; }
private void PositionMarker() { FocusDetails focusDetails = FocusManager.Instance.GetFocusDetails(currentPointingSource); if (focusDetails.Object != null && (Vector3.Dot(focusDetails.Normal, Vector3.up) > 0.90f)) { isTeleportValid = true; teleportMarker.transform.position = focusDetails.Point; } else { isTeleportValid = false; } animationController.speed = isTeleportValid ? 1 : 0; }
public Vector3 GetModifiedPosition(ICursor cursor) { Vector3 position; if (SnapCursor) { // Snap if the targeted object has a cursor modifier that supports snapping position = HostTransform.position + HostTransform.TransformVector(CursorOffset); } else { FocusDetails focusDetails = FocusManager.Instance.GetFocusDetails(cursor.Pointer); // Else, consider the modifiers on the cursor modifier, but don't snap position = focusDetails.Point + HostTransform.TransformVector(CursorOffset); } return(position); }