public RayHitResult HitWithClick(RayCastInfo clickInfo) { var globalRay = clickInfo.GlobalRay; var sphere = getSphere(master); var segmentLength = (sphere.Center - globalRay.Point).Length() * 3; var segment = new LineSegment3(globalRay.Point, globalRay.Point + globalRay.Direction * segmentLength); sphere.Intersect(segment, out var p1, out var p2); if (!p1.HasValue) { return(RayHitResult.Failure()); } var d1 = (p1.Value - globalRay.Point).Length(); Vector3 globalPoint; float distance; if (p2.HasValue) { var d2 = (p2.Value - globalRay.Point).Length(); var use1 = (d1 <= d2) ^ inverted; if (use1) { globalPoint = p1.Value; distance = d1; } else { globalPoint = p2.Value; distance = d2; } } else { globalPoint = p1.Value; distance = d1; } // todo: consider rotation var localPoint = (globalPoint - sphere.Center) / sphere.Radius; return(new RayHitResult { Successful = true, Node = Node, Distance = distance, GlobalHitPoint = globalPoint, LocalHitPoint = localPoint, IntTag = intTag, StrTag = strTag }); }
public RayHitResult HitWithClick(RayCastInfo clickInfo) { var hitResult = hittable.HitWithClick(clickInfo); var cRect = GetRectComponent(); // todo: make overridable and override in more specific components if (cRect.DragByBorders && (1 - hitResult.LocalHitPoint.X.Abs()) * cRect.Rectangle.HalfWidth * RichTextBox.DefaultPixelScaling > RichTextBox.DraggablePaddingInPixels && (1 - hitResult.LocalHitPoint.Y.Abs()) * cRect.Rectangle.HalfHeight * RichTextBox.DefaultPixelScaling > RichTextBox.DraggablePaddingInPixels) { return(RayHitResult.Failure()); } return(hitResult); }
public RayHitResult HitWithClick(RayCastInfo clickInfo) { var globalRay = clickInfo.GlobalRay; var globalTransformInverse = (planeTransform * Node.GlobalTransform).Invert(); var localRay = globalRay * globalTransformInverse; var t = -localRay.Point.Z / localRay.Direction.Z; if (t <= 0f) { return(RayHitResult.Failure()); } var point = localRay.Point + localRay.Direction * t; var rectangle = getLocalRectangle(master); if (!rectangle.ContainsPoint(point.Xy)) { return(RayHitResult.Failure()); } var globalT = t / globalTransformInverse.Scale; var offset = getHitDistanceOffset(master); var globalPoint = globalRay.Point + globalRay.Direction * globalT; var localPoint = new Vector3( (point.X - rectangle.Center.X) / rectangle.HalfWidth, (point.Y - rectangle.Center.Y) / rectangle.HalfHeight, 0); return(new RayHitResult { Successful = true, Node = Node, Distance = globalT + offset, GlobalHitPoint = globalPoint, LocalHitPoint = localPoint, IntTag = intTag, StrTag = strTag }); }
public bool TryHandleInputEvent(IInputEvent eventArgs) { if (!(eventArgs is MouseEvent args)) { return(false); } if (!args.IsLeftClickEvent()) { return(false); } var clickInfo = new RayCastInfo(args.Viewport, args.Viewport.View.Layers.Single(), args.State.Position); var hitResult = rayHitIndex.CastRay(clickInfo).FirstOrNull() ?? RayHitResult.Failure(); if (hitResult.Successful) { int?to = null; var gizmoComponentTo = hitResult.Node.GetComponent <StoryFlowchartNodeGizmoComponent>(); if (gizmoComponentTo != null && gizmoComponentTo.ReferencedNode.Id != from) { to = gizmoComponentTo.ReferencedNode.Id; } if (storyService.GlobalGraph.NodeIds.Contains(hitResult.Node.Id)) { to = hitResult.Node.Id; } if (to.HasValue) { var child = StoryOperations.AddChild(storyService, commonNodeFactory, to.Value, this); storyService.AddEdge(from, child.Id); toolService.CurrentTool = null; return(true); } } toolService.CurrentTool = null; return(false); }
public RayHitResult HitWithClick(RayCastInfo clickInfo) { var globalRay = clickInfo.GlobalRay; var globalTransformInverse = (planeTransform * Node.GlobalTransform).Invert(); var localRay = globalRay * globalTransformInverse; var t = -localRay.Point.Z / localRay.Direction.Z; if (t <= 0f) { return(RayHitResult.Failure()); } var point = localRay.Point + localRay.Direction * t; var cirlce = getLocalCirlce(master); if (!cirlce.Contains(point.Xy)) { return(RayHitResult.Failure()); } var globalT = t / globalTransformInverse.Scale; var offset = getHitDistanceOffset(master); var globalPoint = globalRay.Point + globalRay.Direction * globalT; // todo: consider rotation var localPoint = new Vector3(point.Xy - cirlce.Center, 0) / cirlce.Radius; return(new RayHitResult { Successful = true, Node = Node, Distance = globalT + offset, GlobalHitPoint = globalPoint, LocalHitPoint = localPoint, IntTag = intTag, StrTag = strTag }); }
public RayHitResult HitWithClick(RayCastInfo clickInfo) { // todo: calculate in screen space? var line = getLine(master); var mouseLine = clickInfo.GlobalRay.ToLine(); Line3.GetClosestPoints(line, mouseLine, out var p1, out var p2); var grad = clickInfo.GetAbsPixelGradientAt((p1 + p2) / 2); var diff = (p2 - p1).Abs(); var pixelDiff = Vector3.Dot(diff, grad); return(pixelDiff <= lineWidth ? new RayHitResult { Successful = true, Node = Node, Distance = (clickInfo.GlobalRay.Point - p1).Length(), GlobalHitPoint = p1, LocalHitPoint = p1, IntTag = intTag, StrTag = strTag } : RayHitResult.Failure()); }
public RayHitResult HitWithClick(RayCastInfo clickInfo) => RayHitResult.Failure();
// Hittable public RayHitResult HitWithClick(RayCastInfo clickInfo) => hittable?.HitWithClick(clickInfo) ?? RayHitResult.Failure();