The game world is 2D coordinate system. Player has position (x, y), direction (angle between X axis and where the player looks) and field of view (FOV).
Every wall is a line segment defined by 2 points {A. B} and a color value. Every ray from a camera is a linear equation y=mx+b where m=tan(angle of ray) and b=Yplayer-mXplayer. The only exceptions are vertical rays (a=1/2PI or 3/2PI). Their equation is simply x=Xplayer. Then I find closest intersection with a wall for each ray, calculate the height using trigonometry and draw a line with wall's color.
Негізгі бет Raycasting Engine (C# GDI+ WinForms)
Пікірлер: 6