private static float?CheckSphereAt(Vector3 spherePosition, Vector3 origin, Vector3 direction) { var sphere = new Sphere(spherePosition, Color.red); var r = new Ray(origin, direction); return(sphere.Intersect(r)); }
public void RayMissesSphere() { var ray = new Ray(Tuple3D.Point(0, 2, -5), Tuple3D.Vector(0, 0, 1)); var sphere = new Sphere(); var xs = sphere.Intersect(ray); Assert.That(xs.Count, Is.EqualTo(0), "intersection point count"); }
public void IntersectSetsObjectOnIntersection() { var r = new Ray(Tuple3D.Point(0, 0, -5), Tuple3D.Vector(0, 0, 1)); var s = new Sphere(); var xs = s.Intersect(r); Assert.That(xs.Count, Is.EqualTo(2), "list count"); Assert.That(xs[0].TheObject, Is.EqualTo(s), "intersection 1"); Assert.That(xs[1].TheObject, Is.EqualTo(s), "intersection 2"); }
public void IntersectTranslatedSphereWithRay() { var ray = new Ray(Tuple3D.Point(0, 0, -5), Tuple3D.Vector(0, 0, 1)); var sphere = new Sphere(); sphere.Transform = Transformation.Translation(5, 0, 0); var xs = sphere.Intersect(ray); Assert.That(xs.Count, Is.EqualTo(0), "intersection point count"); }
public void SphereBehindRay() { var ray = new Ray(Tuple3D.Point(0, 0, 5), Tuple3D.Vector(0, 0, 1)); var sphere = new Sphere(); var xs = sphere.Intersect(ray); Assert.That(xs.Count, Is.EqualTo(2), "intersection point count"); Assert.That(xs[0].Time, Is.EqualTo(-6), "xs[0]"); Assert.That(xs[1].Time, Is.EqualTo(-4), "xs[1]"); }
public void RayOriginatesInsideSphere() { var ray = new Ray(Tuple3D.Point(0, 0, 0), Tuple3D.Vector(0, 0, 1)); var sphere = new Sphere(); var xs = sphere.Intersect(ray); Assert.That(xs.Count, Is.EqualTo(2), "intersection point count"); Assert.That(xs[0].Time, Is.EqualTo(-1), "xs[0]"); Assert.That(xs[1].Time, Is.EqualTo(1), "xs[1]"); }
public void RayIntersectsSphereAtTangent() { var ray = new Ray(Tuple3D.Point(0, 1, -5), Tuple3D.Vector(0, 0, 1)); var sphere = new Sphere(); var xs = sphere.Intersect(ray); Assert.That(xs.Count, Is.EqualTo(2), "intersection point count"); Assert.That(xs[0].Time, Is.EqualTo(5), "xs[0]"); Assert.That(xs[1].Time, Is.EqualTo(5), "xs[1]"); }
public void IntersectScaledSphereWithRay() { var ray = new Ray(Tuple3D.Point(0, 0, -5), Tuple3D.Vector(0, 0, 1)); var sphere = new Sphere { Transform = Transformation.Scaling(2, 2, 2) }; var xs = sphere.Intersect(ray); Assert.That(xs.Count, Is.EqualTo(2), "intersection point count"); Assert.That(xs[0].Time, Is.EqualTo(3), "xs[0]"); Assert.That(xs[1].Time, Is.EqualTo(7), "xs[1]"); }