Как убрать рыбий глаз в RayCast
У меня код C#. Сделана система левый край -1 правый 1 верх -1 низ 1. Вот код
using System;
namespace RayCast2D
{
partial class Render
{
static public Vector cameraPoint = new Vector(0, 0);
static public double cameraR = 0;
public const int lines = 100;
static public void Render3D()
{
for(double x = -lines;x < lines;x++)
{
for(double z = 0.1;z < 8;z += 0.025)
{
double angle = cameraR + x * 48 / lines;
Vector vector = new Vector(cameraPoint.x + MathApp.Sin(angle) * z, cameraPoint.y + MathApp.Cos(angle) * z);
ColorRGB color = Game.ObjRender(vector, z);
if(((int)(vector.x * 2) + (int)(vector.y * 2)) % 2 == 0)
{
Rect(x / lines * 2, 1 / z, 2.0 / lines, 0.1 / Math.Pow(z, 2), (int)(255 / Math.Max(z, 1)), 0, 0);
}
if(color.r != -1)
{
Rect(x / lines * 2, 0, 2.0 / lines, 2 / z, (byte)(color.r * 255), (byte)(color.g * 255), (byte)(color.b * 255));
z = double.MaxValue;
}
}
}
}
}
}
using System;
namespace RayCast2D
{
struct Vector
{
public double x, y;
public Vector(double _x, double _y)
{
x = _x;
y = _y;
}
public bool HitBox(in Vector a, in Vector b)
{
if(x > Math.Min(a.x, b.x) && x < Math.Max(a.x, b.x))
if(y > Math.Min(a.y, b.y) && y < Math.Max(a.y, b.y))
return true;
return false;
}
}
struct ColorRGB
{
public double r, g, b;
public ColorRGB(double _r, double _g, double _b)
{
r = _r;
g = _g;
b = _b;
}
public ColorRGB(double _r, double _g, double _b, double z)
{
r = _r / z;
g = _g / z;
b = _b / z;
}
}
class MathApp
{
static public double Sin(double a)
{
return Math.Sin(a * Math.PI / 180);
}
static public double Cos(double a)
{
return Math.Cos(a * Math.PI / 180);
}
static public double Dist(double x, double y, double x2, double y2)
{
return Math.Sqrt(Math.Pow(x2 - x, 2) + Math.Pow(y2 - y, 2));
}
}
}
using System;
namespace RayCast2D
{
class Game
{
static public void Draw()
{
Render.Render3D();
}
static public ColorRGB ObjRender(Vector vector, double z)
{
if(vector.HitBox(new Vector(-5, -5), new Vector(5, -4)))
return new ColorRGB(1, 1, 1, z);
return new ColorRGB(-1, -1, -1);
}
}
}
Помогите пожалуйста как решить проблему.