/// <summary> /// adrr contains the save address of the generated image, /// and must have the extension .pgm; /// Example /home/user/image.pgm /// </summary> public void ExportMapPGM(string adrr, int baseColor, int lineColor) { FrameBuffer frame = new FrameBuffer((int)this.size.X + 1, (int)this.size.Y + 1, baseColor); foreach (intTuple item in this.edge) { Vector2 a = this.vertex[item.A]; Vector2 b = this.vertex[item.B]; LineGeneration.plotLine(a, b, frame, lineColor); } frame.Export(adrr); }
public static void ExportViewPGM(Player player, Map map, Vector2 resolution, RaycastingProperties properties, string adrr) { FrameBuffer frame = new FrameBuffer((int)resolution.X, (int)resolution.Y, 0); float angleInc = player.FOV / resolution.Y; float angleAtt = player.Rotation - (player.FOV / 2); float angleFinal = player.Rotation + (player.FOV / 2); int index = 0; while (angleAtt <= angleFinal) { Vector2 intersect = map.RayCasting(player, angleAtt); if (intersect == null) { intersect = new Vector2(float.PositiveInfinity, float.PositiveInfinity); } else { map.ViewRay("map.pgm", player.Position, intersect, 0, 255, 125); Thread.Sleep(TimeSpan.FromSeconds(0.5f)); } float distance = (float)Vector2.Distance(intersect, player.Position); float height = properties.getHeight((float)distance); int minH = (int)((resolution.X / 2) - (height / 2)); int maxH = (int)((resolution.X / 2) + (height / 2)); LineGeneration.plotLine(new Vector2(index, minH), new Vector2(index, maxH), frame, properties.getColor(distance, 255, 125)); Console.WriteLine(minH + ", " + maxH + ", " + index); //Console.WriteLine(index); angleAtt += angleInc; index += 1; } frame.Export("test.pgm"); //Thread.Sleep(TimeSpan.FromSeconds(0.5f)); //frame.Export(adrr); }
public void ViewRay(string adrr, Vector2 pos, Vector2 intersect, int baseColor, int lineColor, int PlayerColor) { FrameBuffer frame = new FrameBuffer((int)this.size.X + 1, (int)this.size.Y + 1, baseColor); foreach (intTuple item in this.edge) { Vector2 a = this.vertex[item.A]; Vector2 b = this.vertex[item.B]; LineGeneration.plotLine(a, b, frame, lineColor); } LineGeneration.plotLine(pos, intersect, frame, 255); LineGeneration.plotPoint(pos, frame, PlayerColor); frame.Export(adrr); }