// tick: renders one frame public void Tick() { //Check if there are keys pressed CheckMovement(); //Clear the screen and draw a line between the debugscreen and the raytracer screen.Clear(0); screen.Line(512, 0, 512, 512, 0xffffff); //Shoot rays for (int x = 0; x < camera.pixels.GetLength(0); x++) for (int y = 0; y < camera.pixels.GetLength(1); y++) { //Make sure we only draw an apropriate amount of debugrays if (y == 255 && x % 10 == 0) debugRay = true; screen.pixels[x + y * screen.width] = VectorToInt(ShootRay(camera.pixels[x, y], x, y, 0)); debugRay = false; } //Write suitable information on the screen screen.Print("FOV = " + camera.fov, 517, 5, 0xffffff); screen.Print("Camera Position = " + camera.origin.X + "; " + camera.origin.Y + "; " + camera.origin.Z + ";", 517, 25, 0xffffff); screen.Print("Camera Direction = " + camera.direction.X + "; " + camera.direction.Y + "; " + camera.direction.Z + ";", 517, 45, 0xffffff); screen.Print("Recursion = " + recursionMax + "; Debug recursion = " + debugRecusrionMax + ";", 517, 65, 0xffffff); //Draw the debugscreen DebugScreen(primitives, lights, camera, debugRays); debugRays.Clear(); }
public void Tick() { screen.Print((DateTime.Now - lastframe).TotalMilliseconds.ToString(), 2, 30, 0xffffff); lastframe = DateTime.Now; screen.Print(camera.Position.ToString(), 2, 2, 0xffffff); screen.Print(camera.FOV.ToString(), 2, 58, 0xffffff); //camera.update(); if (Keyboard.GetState().IsKeyDown(Key.S)) { camera.Position = camera.Position + new Vector3(0, -1f, 0); } if (Keyboard.GetState().IsKeyDown(Key.W)) { camera.Position = camera.Position + new Vector3(0, 1f, 0); } if (Keyboard.GetState().IsKeyDown(Key.D)) { camera.Position = camera.Position + new Vector3(1f, 0, 0); } if (Keyboard.GetState().IsKeyDown(Key.A)) { camera.Position = camera.Position + new Vector3(-1f, 0, 0); } if (Keyboard.GetState().IsKeyDown(Key.Q)) { camera.Position = camera.Position + new Vector3(0, 0, -1f); } if (Keyboard.GetState().IsKeyDown(Key.E)) { camera.Position = camera.Position + new Vector3(0, 0, 1f); } if (Keyboard.GetState().IsKeyDown(Key.Z)) { camera.FOV -= 0.1f; } if (Keyboard.GetState().IsKeyDown(Key.X)) { camera.FOV += 0.1f; } if (Keyboard.GetState().IsKeyDown(Key.R)) { Init(); } if (Keyboard.GetState().IsKeyDown(Key.T)) { scene = Scene.Multiballs(); } if (Keyboard.GetState().IsKeyDown(Key.Y)) { scene = Scene.Walls(); } if (Keyboard.GetState().IsKeyDown(Key.G)) { scene = Scene.ThreeBalls(); } }
// tick: renders one frame public void Tick() { screen.Clear(0); render.Print("Dit is raytracer, niet game! Kusje, Laura", 2, 2, 0xffffff); // geef camera weer op scherm //debug.Box(camera.location[0], camera.location[2], camera.location[0] + 0.1f, camera.location[2] + 0.1f, CreateColor(255,255,255)); List <primitive> primitieven = scene.getprimitives(); int color; int teller = 0; foreach (primitive primitieve in primitieven) { if (teller > 3) { teller = 0; } switch (teller) { case 0: color = CreateColor(255, 0, 0); // red break; case 1: color = CreateColor(0, 255, 0); // green break; case 2: color = CreateColor(0, 0, 255); // blue break; case 3: color = CreateColor(255, 0, 255); // pink?? break; default: color = CreateColor(255, 255, 255); // white break; } if (primitieve.GetType().Equals(typeof(plane))) { plane screenplane = (plane)primitieve; // vanuit positie camera en richting camera en FOV (hoek) en afstand camera tot scherm // (FOV is nu 90) // bepaal je de lengte van het scherm. float[] middenscreenplane = new float[3]; middenscreenplane = nieuwelocatie(camera.location, screenplane.distancetoorigin, camera.direction); float lengtehalfscherm = (float)(Math.Tan(45) * screenplane.distancetoorigin); float[] punt1 = nieuwelocatie(middenscreenplane, lengtehalfscherm, nieuwerichting(camera.direction, 1)); float[] punt2 = nieuwelocatie(middenscreenplane, lengtehalfscherm, nieuwerichting(camera.direction, 0)); debug.Line(0, punt1[2], punt2[0], punt2[2], CreateColor(0, 255, 0)); // op basis van de lengte van het scherm en de normaal (of de kijkrichting) bepaal je // de uiterste punten van de plane, zowel x, y als z // met x en z teken je de plane als een lijn op je scherm //debug.Plane(plane.position,plane.width,plane.height, color); teller++; } else if (primitieve.GetType().Equals(typeof(sphere))) { sphere bol = (sphere)primitieve; debug.Circle(bol.position[0], bol.position[2], bol.radius, color); teller++; } } render.CopyTo(screen, 0, 0); debug.CopyTo(screen, 512, 0); // TODO teken hier de spheres: links in 3d en rechts in 2d bovenaanzicht }
void DrawMSAA(Surface screen, Surface debugScreen) { if (MSAA > 64) { return; } Vector3 subScreenPoint; Vector3 finalColor = new Vector3(0); Ray ray = new Ray(Vector3.UnitX, Vector3.Zero); Vector3 screenPoint; Vector3 dir; Vector3 screenHorz = camera.TopRight - camera.TopLeft; //Horizontal vector of the screen Vector3 screenVert = camera.BottomLeft - camera.TopLeft; //Vertical vector of the screen float horzStep = 1f / screen.width; float vertStep = 1f / screen.height; float msX = 0; float msY = 0; for (int y = yoffset; y < (yoffset + yjump); ++y, u = 0, v += vertStep, offset += screen.width) { for (int x = 0; x < screen.width; ++x, u += horzStep) { screenPoint = camera.TopLeft + u * screenHorz + v * screenVert; //Top left + u * horz + v * vert => screen point dir = screenPoint - camera.Position; finalColor = new Vector3(0); msX = 0; msY = 0; for (int subY = 0; subY < msaaValue; subY++, msX = 0, msY += axisoffsetY) { for (int subX = 0; subX < msaaValue; subX++, msX += axisoffsetX) { subScreenPoint = new Vector3(screenPoint.X + msX, screenPoint.Y + msY, screenPoint.Z); //subScreenPoint = screenPoint; dir = subScreenPoint - camera.Position; //A vector from the camera to that screen point ray = new Ray(dir.Normalized(), camera.Position); //Create a primary ray from there //foreach (Primitive p in scene.Primitives) // p.Intersect(ray); //Calculate the intersection with all the primitives //byte i = (byte)(1024 / (ray.Intsect.Distance * ray.Intsect.Distance)); finalColor += ray.GetColor(scene); //Console.WriteLine("InLoop: " +subScreenPoint + " : " + subColor + " : " + finalColor); //Draw some rays on the debug screen } } screen.pixels[x + offset] = CreateColor(finalColor * msaaFactor); } } screen.Line(0, yoffset + yjump, screen.width, yoffset + yjump, 0xff00ff); if (screen.height - yoffset > 64) { screen.Print("MSAAx" + MSAA.ToString(), screen.width / 2 - 20, yoffset + yjump + 2, 0xffffff); } if (yoffset < screen.height - yjump) { yoffset += yjump; } else { yoffset = 0; u = 0; v = 0; offset = 0; if (MSAA < 64) { MSAA = MSAA * 4; } } }
public override void DrawDebug(Surface debugScreen) { debugScreen.Print("Ello", 20, 40, 0x000000); DrawCircle(debugScreen, position.X, position.Z, radius, color); base.DrawDebug(debugScreen); }