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

Update ray constraints

This commit is contained in:
Miloslav Číž 2018-09-05 11:44:15 +02:00
parent 92258384f7
commit 751014a252

View file

@ -116,6 +116,7 @@ typedef struct
{ {
uint16_t maxHits; uint16_t maxHits;
uint16_t maxSteps; uint16_t maxSteps;
uint8_t computeTextureCoords; ///< Turns texture coords on/off.
} RayConstraints; } RayConstraints;
/** /**
@ -579,6 +580,7 @@ int_maybe32_t _camResYLimit = 0;
Unit _middleRow = 0; Unit _middleRow = 0;
ArrayFunction _floorFunction = 0; ArrayFunction _floorFunction = 0;
ArrayFunction _ceilFunction = 0; ArrayFunction _ceilFunction = 0;
uint8_t _computeTextureCoords = 0;
/// Helper function that determines intersection with both ceiling and floor. /// Helper function that determines intersection with both ceiling and floor.
Unit _floorCeilFunction(int16_t x, int16_t y) Unit _floorCeilFunction(int16_t x, int16_t y)
@ -651,7 +653,8 @@ void _columnFunction(HitResult *hits, uint16_t hitCount, uint16_t x, Ray ray)
int_maybe32_t z2ScreenCeil = _middleRow - perspectiveScale( int_maybe32_t z2ScreenCeil = _middleRow - perspectiveScale(
(worldZ2Ceil * _camera.resolution.y) / UNITS_PER_SQUARE,dist); (worldZ2Ceil * _camera.resolution.y) / UNITS_PER_SQUARE,dist);
int_maybe32_t wallScreenHeightCeilNoClamp = z2ScreenCeil - z1ScreenCeilNoClamp; int_maybe32_t wallScreenHeightCeilNoClamp =
z2ScreenCeil - z1ScreenCeilNoClamp;
z2ScreenCeil = clamp(z2ScreenCeil,0,_camResYLimit); z2ScreenCeil = clamp(z2ScreenCeil,0,_camResYLimit);
@ -698,8 +701,11 @@ void _columnFunction(HitResult *hits, uint16_t hitCount, uint16_t x, Ray ray)
{ {
p.position.y = i; p.position.y = i;
p.hit = hit; p.hit = hit;
p.textureCoordY = ((i - z1ScreenNoClamp) * UNITS_PER_SQUARE) /
wallScreenHeightNoClamp; if (_computeTextureCoords)
p.textureCoordY = ((i - z1ScreenNoClamp) * UNITS_PER_SQUARE) /
wallScreenHeightNoClamp;
_pixelFunction(p); _pixelFunction(p);
} }
@ -711,8 +717,11 @@ void _columnFunction(HitResult *hits, uint16_t hitCount, uint16_t x, Ray ray)
{ {
p.position.y = i; p.position.y = i;
p.hit = hit; p.hit = hit;
p.textureCoordY = ((i - z1ScreenCeilNoClamp) * UNITS_PER_SQUARE) /
wallScreenHeightCeilNoClamp; if (_computeTextureCoords)
p.textureCoordY = ((i - z1ScreenCeilNoClamp) * UNITS_PER_SQUARE) /
wallScreenHeightCeilNoClamp;
_pixelFunction(p); _pixelFunction(p);
} }
@ -766,6 +775,7 @@ void render(Camera cam, ArrayFunction floorHeightFunc, ArrayFunction
_camera = cam; _camera = cam;
_camResYLimit = cam.resolution.y - 1; _camResYLimit = cam.resolution.y - 1;
_middleRow = cam.resolution.y / 2; _middleRow = cam.resolution.y / 2;
_computeTextureCoords = constraints.computeTextureCoords;
_startFloorHeight = floorHeightFunc( _startFloorHeight = floorHeightFunc(
divRoundDown(cam.position.x,UNITS_PER_SQUARE), divRoundDown(cam.position.x,UNITS_PER_SQUARE),