1
0
Fork 0
mirror of https://git.coom.tech/drummyfish/raycastlib.git synced 2024-11-24 20:59:58 +01:00

Render camera height

This commit is contained in:
Miloslav Číž 2018-08-31 19:01:36 +02:00
parent 30f8e6f205
commit fb3922a7ba

View file

@ -500,8 +500,11 @@ void _columnFunction(HitResult *hits, uint16_t hitCount, uint16_t x, Ray ray)
dist = dist == 0 ? 1 : dist; // prevent division by zero dist = dist == 0 ? 1 : dist; // prevent division by zero
int32_t height = (UNITS_PER_SQUARE * 50) / dist; int32_t height = perspectiveScale(50,dist,1);
uint32_t start = _camera.resolution.y / 2 - height / 2;
Unit offset = perspectiveScale(_camera.height,dist,1);
uint32_t start = _camera.resolution.y / 2 - height / 2 + offset;
for (uint32_t i = start; i < start + height; ++i) for (uint32_t i = start; i < start + height; ++i)
{ {
@ -510,6 +513,7 @@ void _columnFunction(HitResult *hits, uint16_t hitCount, uint16_t x, Ray ray)
p.position.x = x; p.position.x = x;
p.position.y = i; p.position.y = i;
p.isWall = 1; p.isWall = 1;
p.hit = hit;
_pixelFunction(p); _pixelFunction(p);
} }
@ -554,6 +558,8 @@ Unit degreesToUnitsAngle(int16_t degrees)
Unit perspectiveScale(Unit originalSize, Unit distance, Unit fov) Unit perspectiveScale(Unit originalSize, Unit distance, Unit fov)
{ {
return (originalSize * UNITS_PER_SQUARE) / distance;
distance *= fov; distance *= fov;
distance = distance == 0 ? 1 : distance; // prevent division by zero distance = distance == 0 ? 1 : distance; // prevent division by zero