public static World GetManyBallWorld(int width, int height) { var world = GetDefaultWorld(width, height); // world.objects = new List<Shape3D>(); PhongIlluminationModel illuminationModel = new PhongIlluminationModel(world); var r = new Random(); var center = Vector.Build.DenseOfArray(new float[] { 0.0f, -0.3f, 3.5f }); var radius = 0.3f; var mir = Mirror.GetMirror(illuminationModel); var glass = TransmissiveMaterial.GetTransmissiveMaterial(illuminationModel); var blue = PhongMaterial.Blue(illuminationModel); for (int i = 0; i < 100; i++) { var rVec = Vector.Build.DenseOfArray(new float[] { (float)(r.NextDouble() * 2) - 1, (float)(r.NextDouble() * 2) - 1, (float)(r.NextDouble() * 2) - 1 }); rVec = rVec.Normalize(); var rC = center + (rVec * radius); // PhongMaterial mat = mir; PhongMaterial mat = (i % 2 == 0) ? mir : blue;//(PhongMaterial)glass; Sphere ball = new Sphere(rC, (float)(r.NextDouble() * 0.01f), mat); world.AddObject(ball); } return(world); }
public static Mirror GetMirror(PhongIlluminationModel model) { Mirror m = new Mirror(model); return(m); }
public static World GetDefaultWorld(int width, int height) { World world = new World(width, height, Rgba32.Black); // initialize light source Vector lightPos = Vector.Build.DenseOfArray(new float[] { 0.0f, -0.4f, -5.0f }); LightSource l1 = new LightSource(lightPos, Rgba32.White, 10.0f); world.AddLightSource(l1); // initialize camera Vector cameraPos = Vector.Build.DenseOfArray(new float[] { -0.0f, -0.3f, -5.0f }); Vector cameraUp = Vector.Build.DenseOfArray(new float[] { 0.0f, -1.0f, 0.0f }); Vector cameraLookAt = Vector.Build.DenseOfArray(new float[] { 0.0f, 0.0f, 0.0f }); world.cameras.Add(new Camera(cameraPos, cameraLookAt, cameraUp, world)); PhongIlluminationModel illuminationModel = new PhongIlluminationModel(world); // sphere 0 Vector s0Center = Vector.Build.DenseOfArray(new float[] { -0.0f, -0.05f, -2.75f }); float s0Radius = 0.15f; Rgba32[] s0colors = new Rgba32[] { Rgba32.Blue, Rgba32.White }; float[] s0coefficients = new float[] { 0.0f, 0.0f }; PhongMaterial s0PhongMaterial = new PhongMaterial(illuminationModel, s0colors, s0coefficients, 7.0f); s0PhongMaterial.kTransmission = 0.95f; Sphere sphere0 = new Sphere(s0Center, s0Radius, s0PhongMaterial); // sphere 1 Vector s1Center = Vector.Build.DenseOfArray(new float[] { -0.0f, -0.1f, -1.75f }); float s1Radius = 0.15f; Rgba32[] s1colors = new Rgba32[] { Rgba32.Silver, Rgba32.White }; float[] s1coefficients = new float[] { 0.1f, 0.1f }; PhongMaterial s1PhongMaterial = new PhongMaterial(illuminationModel, s1colors, s1coefficients, 10.0f); CheckerboardMaterial s1checkerMaterial = new CheckerboardMaterial(s1PhongMaterial, s0PhongMaterial, 0.1f); s1PhongMaterial.kReflection = 0.9f; Sphere sphere1 = new Sphere(s1Center, s1Radius, Mirror.GetMirror(illuminationModel)); // plane0 (floor) Vector p0Center = Vector.Build.DenseOfArray(new float[] { 0.0f, 0.2f, 0.0f }); Vector p0Normal = Vector.Build.DenseOfArray(new float[] { 0.0f, -1.0f, 0.0f }); Rgba32[] p01colors = new Rgba32[] { Rgba32.Red, Rgba32.White }; float[] p01coefficients = new float[] { 0.9f, 0.1f }; Rgba32[] p02colors = new Rgba32[] { Rgba32.Yellow, Rgba32.White }; float[] p02coefficients = new float[] { 0.9f, 0.1f }; PhongMaterial pm0 = new PhongMaterial(illuminationModel, p01colors, p01coefficients, 10.0f); PhongMaterial pm1 = new PhongMaterial(illuminationModel, p02colors, p02coefficients, 10.0f); CheckerboardMaterial p0checkerMaterial = new CheckerboardMaterial(pm0, pm1, 0.12f); p0checkerMaterial.kReflection = 0.0f; Plane plane0 = new Plane(p0Center, p0Normal, 3.0f, 8.0f, p0checkerMaterial); var max_y_c = Vector.Build.DenseOfArray(new float[] { 0.0f, -0.8f, 5.0f }); var max_y_n = Vector.Build.DenseOfArray(new float[] { 0.0f, 0.0f, -1.0f }); Plane max_y = new Plane(max_y_c, max_y_n, 3.0f, 3.0f, Mirror.GetMirror(illuminationModel)); world.AddObject(sphere0); world.AddObject(sphere1); world.AddObject(plane0); // world.AddObject(max_y); return(world); }