public static WallCoord RayCast(IScene scene, LineF ray) { WallCoord wallCoord = null; float minDist = -1; foreach (IWall wall in scene.GetAll().OfType<IWall>()) { Vector2[] vertices = wall.GetWorldVertices().ToArray(); for (int i = 0; i < vertices.Length; i++) { int iNext = (i + 1) % vertices.Length; IntersectCoord coord = MathExt.LineLineIntersect(ray, new LineF(vertices[i], vertices[iNext]), false); if (coord.Exists) { float dist = ((Vector2)coord.Position - ray[0]).Length; if ((minDist == -1 || minDist < dist)) { minDist = dist; wallCoord = new WallCoord(wall, i, (float)coord.TLast); } } } } return wallCoord; }