public bool Intersects(ref RayF ray, out float scale) { int i, ax0, ax1, ax2, side, inside; float f; Vector3F hit = Vector3F.Zero; scale = 0.0f; ax0 = -1; inside = 0; for (i = 0; i < 3; i++) { if (ray.Origin[i] < Minimum[i]) { side = 0; } else if (ray.Origin[i] > Maximum[i]) { side = 1; } else { inside++; continue; } if (ray.Direction[i] == 0.0f) { continue; } f = (ray.Origin[i] - this[side][i]); if (ax0 < 0 || Math.Abs(f) > Math.Abs(scale * ray.Direction[i])) { scale = -(f / ray.Direction[i]); ax0 = i; } } if (scale < 0 || scale > 1) { return(false); } if (ax0 < 0) { scale = 0.0f; return(inside == 3); } ax1 = (ax0 + 1) % 3; ax2 = (ax0 + 2) % 3; hit[ax1] = ray.Origin[ax1] + scale * ray.Direction[ax1]; hit[ax2] = ray.Origin[ax2] + scale * ray.Direction[ax2]; return(hit[ax1] >= Minimum[ax1] && hit[ax1] <= Maximum[ax1] && hit[ax2] >= Minimum[ax2] && hit[ax2] <= Maximum[ax2]); }
public bool Equals(RayF v, float epsilon) { if (!Origin.Equals(v.Origin, epsilon)) { return(false); } if (!Direction.Equals(v.Direction, epsilon)) { return(false); } return(true); }
/// <summary> /// Determines whether the given ray intersects the current instance of <see cref="PlaneF"/>. /// </summary> /// <param name="ray">The ray to check.</param> /// <param name="scale">When the method completes, contains the ray and plane intersection.</param> /// <returns>True if the given ray intersects the current instance of <see cref="PlaneF"/>; False otherwise.</returns> public bool Intersects(RayF ray, out float scale) { float d1 = A * ray.Origin.X + B * ray.Origin.Y + C * ray.Origin.Z + D; float d2 = A * ray.Direction.X + B * ray.Direction.Y + C * ray.Direction.Z; if (d2 == 0.0f) { scale = 0; return(false); } scale = -(d1 / d2); return(true); }
public bool Intersects(RayF ray) { Vector3F p = ray.Origin - Origin; double a = Vector3F.Dot(ray.Direction, ray.Direction); double b = Vector3F.Dot(ray.Direction, p); double c = Vector3F.Dot(p, p) - Radius * Radius; double d = b * b - c * a; if (d < 0) { return(false); } return(true); }
/// <summary> /// Determines whether the given ray intersects the current instance of <see cref="PlaneF"/>. /// </summary> /// <param name="ray">The ray to check.</param> /// <param name="intersectionPoint">The resulting point of intersection of the plane and the ray (if they intersected).</param> /// <returns>True if the given ray intersects the current instance of <see cref="PlaneF"/>; False otherwise.</returns> public bool Intersects(RayF ray, out Vector3F intersectionPoint) { float d1 = A * ray.Origin.X + B * ray.Origin.Y + C * ray.Origin.Z + D; float d2 = A * ray.Direction.X + B * ray.Direction.Y + C * ray.Direction.Z; if (d2 == 0.0f) { intersectionPoint = Vector3F.Zero; return(false); } float scale = -(d1 / d2); intersectionPoint = ray.GetPointOnRay(scale); return(true); }
public ResultItem[] RayTest(RayF ray, Mode mode, bool twoSided) { if (vertices.Length == 0 || indices.Length == 0) { return(new ResultItem[0]); } if (ray.Direction == Vector3F.Zero) { return(new ResultItem[0]); } var octreeObjects = octreeContainer.GetObjects(ray, 0xFFFFFFFF); var resultList = new List <ResultItem>(octreeObjects.Length); foreach (var data in octreeObjects) { int triangleIndex = data.ObjectIndex; ref var vertex0 = ref vertices[indices[triangleIndex * 3 + 0]]; ref var vertex1 = ref vertices[indices[triangleIndex * 3 + 1]];
public bool Intersects(RayF ray, out float scale1, out float scale2) { Vector3F p = ray.Origin - Origin; double a = Vector3F.Dot(ray.Direction, ray.Direction); double b = Vector3F.Dot(ray.Direction, p); double c = Vector3F.Dot(p, p) - Radius * Radius; double d = b * b - c * a; if (d < 0) { scale1 = 0; scale2 = 0; return(false); } double sqrt = Math.Sqrt(d); a = 1.0f / a; scale1 = (float)((-b + sqrt) * a); scale2 = (float)((-b - sqrt) * a); return(true); }
public Ray(RayF source) { Origin = source.Origin.ToVector3(); Direction = source.Direction.ToVector3(); }
public RayF(RayF source) { Origin = source.Origin; Direction = source.Direction; }
public bool Intersects(RayF ray) { float s; return(Intersects(ref ray, out s)); }
public bool Intersects(RayF ray, out float scale) { return(Intersects(ref ray, out scale)); }