mirror of
https://git.coom.tech/drummyfish/raycastlib.git
synced 2024-11-21 20:29:59 +01:00
Add simple render
This commit is contained in:
parent
2a689d6f7a
commit
1373f5e2e4
1 changed files with 25 additions and 6 deletions
31
raycastlib.h
31
raycastlib.h
|
@ -675,6 +675,7 @@ ArrayFunction _ceilFunction = 0;
|
||||||
uint8_t _computeTextureCoords = 0;
|
uint8_t _computeTextureCoords = 0;
|
||||||
Unit _fogStartYBottom = 0;
|
Unit _fogStartYBottom = 0;
|
||||||
Unit _fogStartYTop = 0;
|
Unit _fogStartYTop = 0;
|
||||||
|
int16_t _cameraHeightScreen = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Helper function that determines intersection with both ceiling and floor.
|
Helper function that determines intersection with both ceiling and floor.
|
||||||
|
@ -928,6 +929,11 @@ void _columnFunctionSimple(HitResult *hits, uint16_t hitCount, uint16_t x,
|
||||||
{
|
{
|
||||||
int16_t y = 0;
|
int16_t y = 0;
|
||||||
int16_t wallScreenHeight = 0;
|
int16_t wallScreenHeight = 0;
|
||||||
|
int16_t coordHelper = 0;
|
||||||
|
int16_t wallStart = _middleRow;
|
||||||
|
int16_t wallEnd = _middleRow;
|
||||||
|
int16_t heightOffset = 0;
|
||||||
|
|
||||||
Unit dist = 1;
|
Unit dist = 1;
|
||||||
|
|
||||||
PixelInfo p;
|
PixelInfo p;
|
||||||
|
@ -941,10 +947,19 @@ void _columnFunctionSimple(HitResult *hits, uint16_t hitCount, uint16_t x,
|
||||||
int16_t wallHeightWorld = _floorFunction(hit.square.x,hit.square.y);
|
int16_t wallHeightWorld = _floorFunction(hit.square.x,hit.square.y);
|
||||||
wallScreenHeight = perspectiveScale((wallHeightWorld *
|
wallScreenHeight = perspectiveScale((wallHeightWorld *
|
||||||
_camera.resolution.y) / UNITS_PER_SQUARE,dist);
|
_camera.resolution.y) / UNITS_PER_SQUARE,dist);
|
||||||
}
|
|
||||||
|
|
||||||
int16_t wallStart = clamp(_middleRow - wallScreenHeight / 2,0,_camResYLimit);
|
heightOffset = perspectiveScale(_cameraHeightScreen,dist);
|
||||||
int16_t wallEnd = clamp(wallStart + wallScreenHeight,0,_camResYLimit);
|
|
||||||
|
wallStart = _middleRow - wallScreenHeight / 2 + heightOffset;
|
||||||
|
|
||||||
|
coordHelper = -1 * wallStart;
|
||||||
|
coordHelper = coordHelper >= 0 ? coordHelper : 0;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
wallStart = clamp(wallStart,0,_camResYLimit);
|
||||||
|
wallEnd = clamp(wallStart + wallScreenHeight,0,_camResYLimit);
|
||||||
|
}
|
||||||
|
|
||||||
// draw ceiling
|
// draw ceiling
|
||||||
|
|
||||||
|
@ -958,6 +973,7 @@ void _columnFunctionSimple(HitResult *hits, uint16_t hitCount, uint16_t x,
|
||||||
p.position.y = y;
|
p.position.y = y;
|
||||||
_pixelFunction(p);
|
_pixelFunction(p);
|
||||||
++y;
|
++y;
|
||||||
|
p.depth += _floorDepthStep;
|
||||||
}
|
}
|
||||||
|
|
||||||
// draw wall
|
// draw wall
|
||||||
|
@ -966,8 +982,6 @@ void _columnFunctionSimple(HitResult *hits, uint16_t hitCount, uint16_t x,
|
||||||
p.isFloor = 1;
|
p.isFloor = 1;
|
||||||
p.depth = dist;
|
p.depth = dist;
|
||||||
|
|
||||||
int16_t coordHelper = 0;
|
|
||||||
|
|
||||||
while (y < wallEnd)
|
while (y < wallEnd)
|
||||||
{
|
{
|
||||||
p.position.y = y;
|
p.position.y = y;
|
||||||
|
@ -983,13 +997,14 @@ void _columnFunctionSimple(HitResult *hits, uint16_t hitCount, uint16_t x,
|
||||||
// draw floor
|
// draw floor
|
||||||
|
|
||||||
p.isWall = 0;
|
p.isWall = 0;
|
||||||
p.depth = 1;
|
p.depth = _middleRow * _floorDepthStep;
|
||||||
|
|
||||||
while (y < _camera.resolution.y)
|
while (y < _camera.resolution.y)
|
||||||
{
|
{
|
||||||
p.position.y = y;
|
p.position.y = y;
|
||||||
_pixelFunction(p);
|
_pixelFunction(p);
|
||||||
++y;
|
++y;
|
||||||
|
p.depth -= _floorDepthStep;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1040,6 +1055,10 @@ void renderSimple(Camera cam, ArrayFunction floorHeightFunc,
|
||||||
_middleRow = cam.resolution.y / 2;
|
_middleRow = cam.resolution.y / 2;
|
||||||
_computeTextureCoords = constraints.computeTextureCoords;
|
_computeTextureCoords = constraints.computeTextureCoords;
|
||||||
|
|
||||||
|
_cameraHeightScreen =
|
||||||
|
(_camera.resolution.y * (_camera.height - UNITS_PER_SQUARE)) /
|
||||||
|
UNITS_PER_SQUARE;
|
||||||
|
|
||||||
// TODO
|
// TODO
|
||||||
_floorDepthStep = (12 * UNITS_PER_SQUARE) / cam.resolution.y;
|
_floorDepthStep = (12 * UNITS_PER_SQUARE) / cam.resolution.y;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue