public bool Raycast(ref Ray3D ray, out Vector3 point) { float dist; if (Geom3D.Raycast(ref this, ref ray, out dist)) { point = ray.GetPoint(dist); return true; } point = ray.Point; return false; }
public static bool Raycast(ref Plane plane, ref Ray3D ray, out float dist) { float dot = Vector3.Dot(ref ray.Normal, ref plane.Normal); if (Math.Abs(dot) < 0.00001f) { dist = 0f; return(false); } dist = (-plane.Distance - Vector3.Dot(plane.Normal, ray.Point)) / dot; if (dist <= 0f) { dist = 0f; return(false); } return(true); }
public bool Raycast(Ray3D ray, out float dist) { return(Geom3D.Raycast(ref this, ref ray, out dist)); }
public bool Raycast(Ray3D ray, out Vector3 point) { return(Raycast(ref ray, out point)); }
public static bool Raycast(ref BoundingBox box, ref Ray3D ray, out float dist) { const float epsilon = 1e-6f; float? tMin = null; float? tMax = null; dist = 0f; if (Math.Abs(ray.Normal.X) < epsilon) { if (ray.Point.X < box.Min.X || ray.Point.X > box.Max.X) { return(false); } } else { tMin = (box.Min.X - ray.Point.X) / ray.Normal.X; tMax = (box.Max.X - ray.Point.X) / ray.Normal.X; if (tMin > tMax) { Calc.Swap(ref tMin, ref tMax); } } if (Math.Abs(ray.Normal.Y) < epsilon) { if (ray.Point.Y < box.Min.Y || ray.Point.Y > box.Max.Y) { return(false); } } else { var tMinY = (box.Min.Y - ray.Point.Y) / ray.Normal.Y; var tMaxY = (box.Max.Y - ray.Point.Y) / ray.Normal.Y; if (tMinY > tMaxY) { Calc.Swap(ref tMinY, ref tMaxY); } if ((tMin.HasValue && tMin > tMaxY) || (tMax.HasValue && tMinY > tMax)) { return(false); } if (!tMin.HasValue || tMinY > tMin) { tMin = tMinY; } if (!tMax.HasValue || tMaxY < tMax) { tMax = tMaxY; } } if (Math.Abs(ray.Normal.Z) < epsilon) { if (ray.Point.Z < box.Min.Z || ray.Point.Z > box.Max.Z) { return(false); } } else { var tMinZ = (box.Min.Z - ray.Point.Z) / ray.Normal.Z; var tMaxZ = (box.Max.Z - ray.Point.Z) / ray.Normal.Z; if (tMinZ > tMaxZ) { Calc.Swap(ref tMinZ, ref tMaxZ); } if ((tMin.HasValue && tMin > tMaxZ) || (tMax.HasValue && tMinZ > tMax)) { return(false); } if (!tMin.HasValue || tMinZ > tMin) { tMin = tMinZ; } if (!tMax.HasValue || tMaxZ < tMax) { tMax = tMaxZ; } } if (tMin < 0f || ((tMin.HasValue && tMin < 0f) && tMax > 0f)) { return(false); } dist = tMin.Value; return(true); }