internal bool HasLOS(Vector3 pos1, Vector3 pos2) { var pos2d = new Vector2(pos1.X, pos1.Y); var dir2d = (new Vector2(pos2.X - pos1.X, pos2.Y - pos1.Y)).NormalizedCopy(); var ray2d = new Ray2D(pos2d, dir2d); // try to eliminate the big stuff first var potentialColliders = _wmoTree.Query(ray2d); foreach (var holder in potentialColliders) { //holder.WMO. } return false; }
/// <summary> /// /// </summary> /// <param name="selectRay">A ray in Xna Coords that was cast according to the viewport</param> /// <param name="add">Whether to add the selected triangle to the selection</param> public void UpdateSelectedTriangle(Ray selectRay, bool add) { if (!add) { Vertices.Clear(); Indices.Clear(); } var pos3D = selectRay.Position; var dir3D = selectRay.Direction; PositionUtil.TransformXnaCoordsToWoWCoords(ref pos3D); PositionUtil.TransformXnaCoordsToWoWCoords(ref dir3D); var ray3D = new Ray(pos3D, dir3D); var pos2D = new Vector2(pos3D.X, pos3D.Y); var dir2D = new Vector2(dir3D.X, dir3D.Y).NormalizedCopy(); var ray2D = new Ray2D(pos2D, dir2D); var closestTime = float.MaxValue; var closestVec0 = Vector3.Zero; var closestVec1 = Vector3.Zero; var closestVec2 = Vector3.Zero; foreach (var tile in _adtManager.MapTiles) { var results = new List<Index3>(); if (!tile.GetPotentialColliders(ray2D, results)) continue; foreach (var tri in results) { var vec0 = tile.TerrainVertices[tri.Index0]; var vec1 = tile.TerrainVertices[tri.Index1]; var vec2 = tile.TerrainVertices[tri.Index2]; float time; if (!Intersection.RayTriangleIntersect(ray3D, vec0, vec1, vec2, out time)) continue; if (time > closestTime) continue; closestTime = time; closestVec0 = vec0; closestVec1 = vec1; closestVec2 = vec2; } } if (closestTime == float.MaxValue) return; AddSelectedTriangle(closestVec0, closestVec1, closestVec2); }
public float? IntersectWith(Ray2D ray) { var time = 0.0f; float maxValue = int.MaxValue; if (Math.Abs(ray.Direction.X) < 1E-06f) { if ((ray.Position.X < X) || (ray.Position.X > Right)) { return null; } } else { var invDenom = 1f / ray.Direction.X; var time0 = (X - ray.Position.X) * invDenom; var time1 = (Right - ray.Position.X) * invDenom; if (time0 > time1) { var temp = time0; time0 = time1; time1 = temp; } time = MathHelper.Max(time0, time); maxValue = MathHelper.Min(time1, maxValue); if (time > maxValue) { return null; } } if (Math.Abs(ray.Direction.Y) < 1E-06f) { if ((ray.Position.Y < Y) || (ray.Position.Y > Bottom)) { return null; } } else { var invDenom = 1f / ray.Direction.Y; var time0 = (Y - ray.Position.Y) * invDenom; var time1 = (Bottom - ray.Position.Y) * invDenom; if (time0 > time1) { var temp = time0; time0 = time1; time1 = temp; } time = MathHelper.Max(time0, time); maxValue = MathHelper.Min(time1, maxValue); if (time > maxValue) { return null; } } return time; }
public bool IntersectsWith(Ray2D ray) { var time = IntersectWith(ray); return time.HasValue; }
public abstract bool GetPotentialColliders(Ray2D ray2D, List<Index3> results);
public bool ClipRay(Ray2D ray2d, out Vector2 new1, out Vector2 new2) { var point1 = ray2d.Position; var point2 = ray2d.Position + ray2d.Direction*float.MaxValue; return ClipLine(point1, point2, out new1, out new2); }
public override bool GetPotentialColliders(Ray2D ray2D, List<Index3> results) { if (results == null) { results = new List<Index3>(); } var chunks = QuadTree.Query(ray2D); foreach (var chunk in chunks) { results.AddRange(chunk.TerrainTris); } return true; }
public float?IntersectWith(Ray2D ray) { float f2_1 = 0.0f; float f2_2 = int.MaxValue; if (Math.Abs(ray.Direction.X) < 9.99999997475243E-07) { if (ray.Position.X < (double)X || ray.Position.X > (double)Right) { return(new float?()); } } else { float num1 = 1f / ray.Direction.X; float f1_1 = (X - ray.Position.X) * num1; float f1_2 = (Right - ray.Position.X) * num1; if (f1_1 > (double)f1_2) { float num2 = f1_1; f1_1 = f1_2; f1_2 = num2; } f2_1 = MathHelper.Max(f1_1, f2_1); f2_2 = MathHelper.Min(f1_2, f2_2); if (f2_1 > (double)f2_2) { return(new float?()); } } if (Math.Abs(ray.Direction.Y) < 9.99999997475243E-07) { if (ray.Position.Y < (double)Y || ray.Position.Y > (double)Bottom) { return(new float?()); } } else { float num1 = 1f / ray.Direction.Y; float f1_1 = (Y - ray.Position.Y) * num1; float f1_2 = (Bottom - ray.Position.Y) * num1; if (f1_1 > (double)f1_2) { float num2 = f1_1; f1_1 = f1_2; f1_2 = num2; } f2_1 = MathHelper.Max(f1_1, f2_1); float num3 = MathHelper.Min(f1_2, f2_2); if (f2_1 > (double)num3) { return(new float?()); } } return(f2_1); }
public bool IntersectsWith(Ray2D ray) { return(IntersectWith(ray).HasValue); }
public bool ClipRay(Ray2D ray2d, out Vector2 new1, out Vector2 new2) { return(ClipLine(ray2d.Position, ray2d.Position + ray2d.Direction * float.MaxValue, out new1, out new2)); }