// This one needs to be rewritten :/ public static Zone[] LoadAll(BinaryReader reader) { int count = reader.ReadInt32(); Zone[] zones = new Zone[count]; List <RectangleF>[] portals = new List <RectangleF> [count]; for (int i = 0; i < count; i++) { RectangleF bounds = new RectangleF(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle()); Zone zone = new Zone(bounds); int meshCount = reader.ReadInt32(); for (int j = 0; j < meshCount; j++) { zone.AddMesh(MeshObject.Load(reader)); } int portalCount = reader.ReadInt32(); portals[i] = new List <RectangleF>(); for (int j = 0; j < portalCount; j++) { Vector2 start = GameSave.ReadVector2(reader); Vector2 end = GameSave.ReadVector2(reader); zone.AddPortal(new Portal(null, start, end)); portals[i].Add(GameSave.ReadRectangleF(reader)); } zones[i] = zone; } for (int i = 0; i < count; i++) { int portalCount = zones[i].portals.Count; for (int j = 0; j < portalCount; j++) { RectangleF bounds = portals[i][j]; Zone zone = zones.Where((Zone z) => { return(z.Bounds.Equals(bounds)); }).First(); Vector2 start = zones[i].portals[j].Start; Vector2 end = zones[i].portals[j].End; zones[i].portals[j] = new Portal(zone, start, end); } } return(zones); }
public void Raster(Scene scene) { Camera camera = scene.Camera; // Reset console for (int i = 0; i < console.Width; i++) { for (int j = 0; j < console.Height; j++) { console.Data[i, j] = ' '; console.Color[i, j] = 255; zBuffer[i, j] = 1; bBuffer[i, j] = Vector3.Zero; tBuffer[i, j] = null; } } List <Triangle> triangles = new List <Triangle>(); ASCII_FPS.triangleCount = 0; ASCII_FPS.triangleCountClipped = 0; ASCII_FPS.zonesRendered = 0; // Extract dynamic meshes Matrix cameraSpaceMatrix = camera.CameraSpaceMatrix; foreach (GameObject gameObject in scene.gameObjects) { MeshObject mesh = gameObject.MeshObject; ASCII_FPS.triangleCount += mesh.triangles.Count; Matrix meshToCameraMatrix = mesh.WorldSpaceMatrix * cameraSpaceMatrix; foreach (Triangle triangle in mesh.triangles) { Vector3 v0 = Vector3.Transform(triangle.V0, meshToCameraMatrix); Vector3 v1 = Vector3.Transform(triangle.V1, meshToCameraMatrix); Vector3 v2 = Vector3.Transform(triangle.V2, meshToCameraMatrix); triangles.Add(new Triangle(v0, v1, v2, triangle.Texture, triangle.UV0, triangle.UV1, triangle.UV2)); } } // Clipping triangles = ClipTriangles(triangles, camera); ASCII_FPS.triangleCountClipped += triangles.Count; // Rendering RenderTriangles(triangles, camera, 0, console.Width); // Find first zone Zone firstZone = null; foreach (Zone zone in scene.zones) { if (zone.Bounds.TestPoint(new Vector2(camera.CameraPos.X, camera.CameraPos.Z))) { firstZone = zone; break; } } if (firstZone != null) { ProcessZone(camera, firstZone, 0, console.Width); } // Shading for (int i = 0; i < console.Width; i++) { for (int j = 0; j < console.Height; j++) { Triangle triangle = tBuffer[i, j]; if (triangle != null) { float z = zBuffer[i, j]; Vector3 bar = bBuffer[i, j]; // Sample from texture Vector2 uv = bar.X * triangle.UV0 + bar.Y * triangle.UV1 + bar.Z * triangle.UV2; if (EyeEasy) { float d = Math.Clamp(1f - (float)Math.Pow(z, 25), 0f, 1f); console.Data[i, j] = '@'; console.Color[i, j] = Mathg.ColorTo8Bit(triangle.Texture.Sample(uv) * d); } else { int fogId = (z < 0) ? 0 : Math.Min((int)(Math.Pow(z, 10) * fogString.Length + offset[i, j]), fogString.Length - 1); console.Data[i, j] = fogString[fogId]; console.Color[i, j] = Mathg.ColorTo8Bit(triangle.Texture.Sample(uv)); } } } } }
public void AddMesh(MeshObject mesh) { meshes.Add(mesh); }