public void PatternPatternTransform() { Sphere s = new Sphere(); TestPattern pattern = new TestPattern(); pattern.Transform = Matrix4.ScaleMatrix(2, 2, 2); Color c = pattern.PatternAtObject(s, new Point(2, 3, 4)); Color answer = new Color(1, 1.5f, 2); Assert.True(c == answer); }
public void PatternObjectPatternTransform() { Sphere s = new Sphere(); s.Transform = Matrix4.ScaleMatrix(2, 2, 2); TestPattern pattern = new TestPattern(); pattern.Transform = Matrix4.TranslateMatrix(0.5f, 1, 1.5f); Color c = pattern.PatternAtObject(s, new Point(2.5f, 3, 3.5f)); Color answer = new Color(0.75f, 0.5f, 0.25f); Assert.True(c == answer); }
///------------------------------------------------------------------------------------------------- /// <summary> Main entry-point for this application. </summary> /// /// <remarks> Kemp, 1/18/2019. </remarks> /// /// <param name="args"> An array of command-line argument strings. </param> ///------------------------------------------------------------------------------------------------- static void Main(string[] args) { World defaultWorld = new World(); defaultWorld.AddLight(new LightPoint(new Point(-10, 10, -10), new Color(1, 1, 1))); Sphere s1 = new Sphere(); s1.Material = new Material(); s1.Material.Color = new Color(0.8, 1.0, 0.6); s1.Material.Diffuse = new Color(0.7, 0.7, 0.7); s1.Material.Specular = new Color(0.2, 0.2, 0.2); Sphere s2 = new Sphere(); s2.Transform = MatrixOps.CreateScalingTransform(0.5, 0.5, 0.5); defaultWorld.AddObject(s1); defaultWorld.AddObject(s2); Color white = new Color(1, 1, 1); Color black = new Color(0, 0, 0); Sphere s = new Sphere(); { Material m = new Material(); m.Pattern = new StripePattern(white, black); m.Ambient = new Color(1, 1, 1); m.Diffuse = new Color(0, 0, 0); m.Specular = new Color(0, 0, 0); m.Shininess = 0; RayTracerLib.Vector eyev = new RayTracerLib.Vector(0, 0, -1); RayTracerLib.Vector normalv = new RayTracerLib.Vector(0, 0, -1); Point p1 = new Point(0.9, 0, 0); Point p2 = new Point(1.1, 0, 0); LightPoint light = new LightPoint(new Point(0, 0, -10), new Color(1, 1, 1)); Color c1 = Ops.Lighting(m, s, light, p1, eyev, normalv, false); Color c2 = Ops.Lighting(m, s, light, p2, eyev, normalv, false); bool foo1 = (c1.Equals(white)); bool foo2 = (c2.Equals(black)); Console.WriteLine("~~~~~~~~~~~~~~~~~~~~~"); } //public void PatternWithObjectTransformation() { Shape shape = new Sphere() { Transform = MatrixOps.CreateScalingTransform(2, 2, 2) }; Pattern pattern = new TestPattern { Transform = MatrixOps.CreateTranslationTransform(0.5, 1, 1.5) }; Color c = pattern.PatternAtObject(shape, new Point(2.5, 3, 3.5)); bool foo1 = (c.Equals(new Color(0.75, 0.5, 0.25))); Console.WriteLine("~~~~~~~~~~~~~~~~~~~~~"); } //public void GradientInterpolates() { Pattern pattern = new GradientPattern(black, white); bool foo1 = (pattern.PatternAt(new Point(0, 0, 0)).Equals(black)); bool foo2 = (pattern.PatternAt(new Point(0.25, 0, 0)).Equals(new Color(0.25, 0.25, 0.25))); bool foo3 = (pattern.PatternAt(new Point(0.5, 0, 0)).Equals(new Color(0.5, 0.5, 0.5))); bool foo4 = (pattern.PatternAt(new Point(0.75, 0, 0)).Equals(new Color(0.75, 0.75, 0.75))); Console.WriteLine("~~~~~~~~~~~~~~~~~~~~~"); } { Pattern pattern = new CheckedPattern(black, white); bool foo1 = (pattern.PatternAt(new Point(0, 0, 0)).Equals(black)); bool foo2 = (pattern.PatternAt(new Point(0.99, 0, 0)).Equals(black)); bool foo3 = (pattern.PatternAt(new Point(1.01, 0, 0)).Equals(white)); Console.WriteLine("~~~~~~~~~~~~~~~~~~~~~"); } Console.Write("Press Enter to finish ... "); Console.Read(); }