Exemple #1
0
        /// <summary>
        /// Enumerates the times and places, if any, where a moving line crosses a point during a time step.
        /// The line's endpoints move at a constant rate along their linear paths.
        /// </summary>
        /// <remarks>Original code found here https://github.com/Strilanc/Methods/blob/master/Methods/Methods/LineSweepPoint/GeometryUtil.cs </remarks>
        public static IEnumerable<Sweep> WhenLineSweepsPoint(Vector2d point, Line pathOfLineStartPoint, Line pathOfLineEndPoint)
        {
            var a = point - pathOfLineStartPoint[0];
            var b = -pathOfLineStartPoint.Delta;
            var c = pathOfLineEndPoint[0] - pathOfLineStartPoint[0];
            var d = pathOfLineEndPoint.Delta - pathOfLineStartPoint.Delta;

            //return from t in QuadraticRoots(b.Cross(d), a.Cross(d) + b.Cross(c), a.Cross(c))
            return from across in QuadraticRoots(Vector2Ext.Cross(b, d), Vector2Ext.Cross(a, d) + Vector2Ext.Cross(b, c), Vector2Ext.Cross(a, c))
                    where across >= 0 && across <= 1
                    let start = pathOfLineStartPoint.Lerp(across)
                    let end = pathOfLineEndPoint.Lerp(across)
                    let time = point.LerpProjectOnto(new Line(start, end))
                    where time >= 0 && time <= 1
                    orderby time
                    select new Sweep(timeProportion: time, acrossProportion: across);
        }
Exemple #2
0
 private static void PlaceOnPortal(IPortalCommon instance, IPortal portal, float t)
 {
     Line portalLine = new Line(Vector2Ext.ToDouble(Portal.GetWorldVerts(portal)));
     Transform2d transform = (Transform2d)instance.WorldTransform;
     transform.Position = (Vector2d)portalLine.Lerp(t);
     instance.WorldTransform = (Transform2)transform;
 }