mirror of
https://git.coom.tech/drummyfish/raycastlib.git
synced 2024-11-23 20:49:57 +01:00
Render wall height offset
This commit is contained in:
parent
fb3922a7ba
commit
50df4a40f4
1 changed files with 28 additions and 24 deletions
14
raycastlib.h
14
raycastlib.h
|
@ -485,14 +485,14 @@ void castRaysMultiHit(Camera cam, ArrayFunction arrayFunc,
|
|||
}
|
||||
|
||||
PixelFunction _pixelFunction = 0;
|
||||
ArrayFunction _arrayFunction = 0;
|
||||
Camera _camera;
|
||||
|
||||
void _columnFunction(HitResult *hits, uint16_t hitCount, uint16_t x, Ray ray)
|
||||
{
|
||||
if (hitCount == 0)
|
||||
return;
|
||||
|
||||
HitResult hit = hits[0];
|
||||
for (uint32_t j = 0; j < hitCount; ++j)
|
||||
{
|
||||
HitResult hit = hits[j];
|
||||
|
||||
Unit dist = // adjusted distance
|
||||
(hit.distance * vectorsAngleCos(angleToDirection(_camera.direction),
|
||||
|
@ -502,7 +502,9 @@ void _columnFunction(HitResult *hits, uint16_t hitCount, uint16_t x, Ray ray)
|
|||
|
||||
int32_t height = perspectiveScale(50,dist,1);
|
||||
|
||||
Unit offset = perspectiveScale(_camera.height,dist,1);
|
||||
int16_t z = _arrayFunction(hit.square.x,hit.square.y) * 50;
|
||||
|
||||
Unit offset = perspectiveScale(_camera.height - z,dist,1);
|
||||
|
||||
uint32_t start = _camera.resolution.y / 2 - height / 2 + offset;
|
||||
|
||||
|
@ -517,12 +519,14 @@ void _columnFunction(HitResult *hits, uint16_t hitCount, uint16_t x, Ray ray)
|
|||
|
||||
_pixelFunction(p);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void render(Camera cam, ArrayFunction arrayFunc, PixelFunction pixelFunc,
|
||||
RayConstraints constraints)
|
||||
{
|
||||
_pixelFunction = pixelFunc;
|
||||
_arrayFunction = arrayFunc;
|
||||
_camera = cam;
|
||||
castRaysMultiHit(cam,arrayFunc,_columnFunction,constraints);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue