mirror of
https://git.coom.tech/drummyfish/raycastlib.git
synced 2024-12-24 01:36:19 +01:00
Render camera height
This commit is contained in:
parent
30f8e6f205
commit
fb3922a7ba
1 changed files with 8 additions and 2 deletions
10
raycastlib.h
10
raycastlib.h
|
@ -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
|
||||
|
||||
int32_t height = (UNITS_PER_SQUARE * 50) / dist;
|
||||
uint32_t start = _camera.resolution.y / 2 - height / 2;
|
||||
int32_t height = perspectiveScale(50,dist,1);
|
||||
|
||||
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)
|
||||
{
|
||||
|
@ -510,6 +513,7 @@ void _columnFunction(HitResult *hits, uint16_t hitCount, uint16_t x, Ray ray)
|
|||
p.position.x = x;
|
||||
p.position.y = i;
|
||||
p.isWall = 1;
|
||||
p.hit = hit;
|
||||
|
||||
_pixelFunction(p);
|
||||
}
|
||||
|
@ -554,6 +558,8 @@ Unit degreesToUnitsAngle(int16_t degrees)
|
|||
|
||||
Unit perspectiveScale(Unit originalSize, Unit distance, Unit fov)
|
||||
{
|
||||
return (originalSize * UNITS_PER_SQUARE) / distance;
|
||||
|
||||
distance *= fov;
|
||||
distance = distance == 0 ? 1 : distance; // prevent division by zero
|
||||
|
||||
|
|
Loading…
Reference in a new issue