// initialize public void Init() { // Set recursion level Recursion = 5; // Add light(s) Light[] lights = new Light[2]; lights[0] = new Light(new VPoint(1, 2, 0), 1, 1, 1); lights[1] = new Light(new VPoint(2, 10, 5), 2, 2, 2); // Add primitive(s) Primitive[] primitives = new Primitive[5]; primitives[0] = new Plane(new VPoint(0, 1, 0), -2, new Material(0.5f, 1)); primitives[1] = new Sphere(new VPoint(0, 0, 5), 1.5f, new Material(new VPoint(255, 50, 100), 0.5f)); primitives[2] = new Sphere(new VPoint(-3, 0, 5), 1.5f, new Material(new VPoint(0, 255, 10), 0.5f)); primitives[3] = new Sphere(new VPoint(3, 0, 5), 1.5f, new Material(new VPoint(255, 255, 255), 0.75f)); // The sphere in which the whole scene is situated primitives[4] = new Sphere(new VPoint(0, -5, 1), 10f, new Material(0f, 2)); // Create scene Scene scene = new Scene(lights, primitives); // Create raytracer Tracer = new Raytracer(scene, Screen); // Set debugging Debugging = true; // Calculating the sinus every time you need is, is slow, as such we calculate the values once and use an array SinTable = new float[360]; for (int i = 0; i < 360; i++) { SinTable[i] = (float)Math.Sin(i * Math.PI / 180); } //load bitmap4space string s = Path.Combine(Environment.CurrentDirectory, @"..\..\", "Space.jpg"); Space = new Bitmap(s); }
// plot a single pixel public void Plot(int x, int y, Vector3 c) { if ((x >= 0) && (y >= 0) && (x < width) && (y < height)) { pixels[x + y * width] = Raytracer.VecToInt(c); } }
public void Raytracing() { // prepare for generic OpenGL rendering GL.Enable(EnableCap.DepthTest); GL.Disable(EnableCap.Texture2D); GL.Clear(ClearBufferMask.DepthBufferBit); float FOV = 400; // creating a scene Scene Scene1 = new Scene(); // Adding axis in the Debug view Scene1.toggleaxis(true); if (Scene1.Axis == true) { GL.Color4(1f, 1f, 1f, 1f); GL.Begin(PrimitiveType.Lines); GL.Vertex2(0.5f, 1); GL.Vertex2(0.5f, -1f); GL.Vertex2(0, 0); GL.Vertex2(1, 0); GL.End(); } // Adding main objects to the scene Sphere Sphere1 = new Sphere(new Vector3(200, 0, 200), 100f, new Vector3(255,0,0), aspectratio); Sphere Sphere2 = new Sphere(new Vector3(-200, 0, 200), 100f, new Vector3(0, 0, 255), aspectratio); Sphere Sphere3 = new Sphere(new Vector3(-100, 0, 200), 100f, new Vector3(0, 255,0), aspectratio); Camera mainCamera = new Camera(new Vector3(0,0,-400), new Vector3(0,0,1), FOV); Light LightSource1 = new Light(new Vector3(0, 200, 200), 255, 255, 0); // adding light source(s) to the list Scene1.LightList.Add(LightSource1); //adding primitives to te primitive list Scene1.PrimitivesList.Add(Sphere1); Scene1.PrimitivesList.Add(Sphere3); Scene1.PrimitivesList.Add(Sphere2); // draw every primitive in the list foreach (Sphere item in Scene1.PrimitivesList) { Scene1.DrawCircle(DebugConverter(item.Position), item.Color, item.Radius, screen); } // start raytracing Raytracer raytracer = new Raytracer(); raytracer.Render(mainCamera, Scene1, screen); for (int renderx = 0; renderx < 512; renderx++) { for (int rendery = 0; rendery < 512; rendery++) { int pixel = renderx + rendery * 512; screen.Plot(renderx, rendery, (int)raytracer.Image[pixel]); } } Raytr = raytracer; }
void Render (Raytracer raytracer, Template.Surface screen) { for (int renderx = 0; renderx < 512; renderx++) { for (int rendery = 0; rendery < 512; rendery++) { int pixel = renderx + rendery * 512; screen.pixels[pixel] = (int)raytracer.Image[pixel]; } } }
protected override void OnLoad(EventArgs e) { // called upon app init GL.ClearColor(Color.Black); GL.Enable(EnableCap.Texture2D); GL.Disable(EnableCap.DepthTest); GL.Hint(HintTarget.PerspectiveCorrectionHint, HintMode.Nicest); ClientSize = new Size(1024, 512); rayTracer = new Raytracer(); rayTracer.screen = new Surface(Width, Height); rayTracer.Init(); Sprite.target = rayTracer.screen; screenID = rayTracer.screen.GenTexture(); }
//Constructor of the application. static public void CreateApplication(Camera cam, Surface scr, Scene sce, Rectangle bound) { raytracer = new Raytracer(); camera = cam; screen = scr; scene = sce; bounds = bound; //Move the cursor to the middle of the screen and instantiate the variables to measure mouse movement. Cursor.Position = new Point(bounds.Left + bounds.Width / 2, bounds.Top + bounds.Height / 2); currentCursor = Cursor.Position; previousCursor = Cursor.Position; mouseDelta = Vector2.Zero; }
// initialize public void Init() { scene = new Scene(); displaySurf = new Surface(0, 0); Light light2 = new Light(new Vector3(-3, -10, 0), new Vector3(1, 1f, 1f)); scene.lights.Add(light2); Light light = new Light(new Vector3(-15f, -5, 0), new Vector3(1f, 1, 1)); scene.lights.Add(light); Plane plane1 = new Plane(1, new Vector3(0, 1, 0), new Vector3(1, 1, 1), false); scene.primitives.Add(plane1); Plane plane2 = new Plane(5, new Vector3(-1, 0, 0), new Vector3(1, 1, 1), false); scene.primitives.Add(plane2); Plane plane3 = new Plane(5, new Vector3(1, 0, 0), new Vector3(1, 1, 1), false); scene.primitives.Add(plane3); Plane plane4 = new Plane(10, new Vector3(0, 0, 1), new Vector3(1, 1, 1), false); scene.primitives.Add(plane4); Plane plane5 = new Plane(10, new Vector3(0, 0, -1), new Vector3(1, 1, 1), false); scene.primitives.Add(plane5); Sphere sphere2 = new Sphere(new Vector3(-1.5f, 0, -2), 1, new Vector3(1, 1, 0.5f), false); scene.primitives.Add(sphere2); Sphere sphere1 = new Sphere(new Vector3(0, 0, 0), 1, new Vector3(0.5f, 1, 1), false, 100); scene.primitives.Add(sphere1); Sphere sphere3 = new Sphere(new Vector3(1.5f, 0, -2), 1, new Vector3(1, 1, 1), true); scene.primitives.Add(sphere3); raytracer = new Raytracer(cam, scene, displaySurf); raytracer.screen = screen; raytracer.InitializeOutside(); }
private float xlength, ylength; //length of x axis and y axis //initialize public void Init() { screen = new Surface(1024, 512); float FOVfactor = z * Math.Abs((float)Math.Tan(FOV * Math.PI/360)); camera = new Camera(- FOVfactor, FOVfactor, FOVfactor, - FOVfactor, z, cameraDir); scene = new Scene(debug); left = camera.screenlu.X; up = camera.screenlu.Y; right = camera.screenru.X; down = camera.screenld.Y; xlength = Math.Abs(left) + Math.Abs(right); ylength = Math.Abs(up) + Math.Abs(down); debug = new Debug(screen, camera, scene); raytracer = new Raytracer(screen, camera, scene, debug); }
protected override void OnLoad(EventArgs e) { // called upon app init GL.ClearColor(Color.Black); GL.Enable(EnableCap.Texture2D); GL.Disable(EnableCap.DepthTest); GL.Hint(HintTarget.PerspectiveCorrectionHint, HintMode.Nicest); ClientSize = new Size(1024, 512); raytracer = new Raytracer { scene = new Scene(), camera = new Camera(new Vector3(0, 0, 0), new Vector3(0.0f, 0, 1.0f)), screen = new Surface(screenSize, screenSize, Vector3.Zero, Vector3.Zero, Vector3.Zero), screenDebug = new Surface(screenDebugSize, screenDebugSize, Vector3.Zero, Vector3.Zero, Vector3.Zero) }; Sprite.target = raytracer.screen; screenID = raytracer.screen.GenTexture(); screenIDDebug = raytracer.screenDebug.GenTexture(); raytracer.Init(); }
// initialize public void Init() { raytracer = new Raytracer(); application = new Application(); }
// initialize public void Init() { screen = new Surface(2 * size, size); raytracer = new Raytracer(screen, scene, size, size); }
public void Init() { Camera.DisplayKeyInfo(); raytracer = new Raytracer(); }