public static void DrawDebug() { screen.Line(0, 0, 0, screen.height, 0xffff00); scene.DrawDebug(screen); camera.DrawDebug(screen); Draw(); }
// 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 DrawDebug(Surface screen, int color, bool shadow = false) { if (shadow && intsect.Primitive == null) { intsect.Distance = 1f; } screen.Line( TX(origin.X, screen), TY(origin.Z, screen), TX(origin.X + direction.X * intsect.Distance, screen), TY(origin.Z + direction.Z * intsect.Distance, screen), color); }
public void DrawDebug(Surface screen) { DrawCircle(screen, position.X, position.Z, 0.1f, Vector3.One); screen.Line(TX(TopLeft.X, screen), TY(TopLeft.Z, screen), TX(TopRight.X, screen), TY(TopRight.Z, screen), 0xffffff); //screen.Box(TX(TopLeft.X, screen), TY(TopLeft.Z - 0.02f, screen), TX(TopRight.X, screen), TY(TopRight.Z + 0.02f, screen), 0xffffff); }
public void RenderSphere(Vector3 pos, float radius, Primitive p) { float x1, x2, z1, z2; //draw 90 lines for each circle for (int i = 0; i < 360; i += 4) { x1 = (float)(pos.X + radius * Math.Cos(i * Math.PI / 180)); z1 = (float)(pos.Z + radius * Math.Sin(i * Math.PI / 180)); x2 = (float)(pos.X + radius * Math.Cos((i + 4) * Math.PI / 180)); z2 = (float)(pos.Z + radius * Math.Sin((i + 4) * Math.PI / 180)); surface.Line(TX(x1), TY(z1), TX(x2), TY(z2), createColor(p.color)); } }
// 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 }
public override void DrawDebug(Surface screen) { screen.Line(TX(Origin.X, screen), TY(Origin.Z, screen), TX(direction.X, screen), TY(direction.Z, screen), 0xffffff); base.DrawDebug(screen); }
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; } } }