mirror of
https://git.coom.tech/drummyfish/raycastlib.git
synced 2024-11-21 20:29:59 +01:00
Fix simple rendering func
This commit is contained in:
parent
9c0a2f2e5f
commit
4eb84296cb
1 changed files with 20 additions and 7 deletions
27
raycastlib.h
27
raycastlib.h
|
@ -795,6 +795,11 @@ Unit _floorCeilFunction(int16_t x, int16_t y)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Unit _floorHeightNotZeroFunction(int16_t x, int16_t y)
|
||||||
|
{
|
||||||
|
return _floorFunction(x,y) == 0 ? 0 : UNITS_PER_SQUARE;
|
||||||
|
}
|
||||||
|
|
||||||
Unit adjustDistance(Unit distance, Camera *camera, Ray *ray)
|
Unit adjustDistance(Unit distance, Camera *camera, Ray *ray)
|
||||||
{
|
{
|
||||||
/* FIXME/TODO: The adjusted (=orthogonal, camera-space) distance could
|
/* FIXME/TODO: The adjusted (=orthogonal, camera-space) distance could
|
||||||
|
@ -955,7 +960,7 @@ void _columnFunctionSimple(HitResult *hits, uint16_t hitCount, uint16_t x,
|
||||||
Ray ray)
|
Ray ray)
|
||||||
{
|
{
|
||||||
int16_t y = 0;
|
int16_t y = 0;
|
||||||
int16_t wallScreenHeight = 0;
|
int16_t wallHeightScreen = 0;
|
||||||
int16_t coordHelper = 0;
|
int16_t coordHelper = 0;
|
||||||
int16_t wallStart = _middleRow;
|
int16_t wallStart = _middleRow;
|
||||||
int16_t wallEnd = _middleRow;
|
int16_t wallEnd = _middleRow;
|
||||||
|
@ -970,20 +975,27 @@ void _columnFunctionSimple(HitResult *hits, uint16_t hitCount, uint16_t x,
|
||||||
{
|
{
|
||||||
HitResult hit = hits[0];
|
HitResult hit = hits[0];
|
||||||
p.hit = hit;
|
p.hit = hit;
|
||||||
|
|
||||||
dist = adjustDistance(hit.distance,&_camera,&ray);
|
dist = adjustDistance(hit.distance,&_camera,&ray);
|
||||||
|
|
||||||
int16_t wallHeightWorld = _floorFunction(hit.square.x,hit.square.y);
|
int16_t wallHeightWorld = _floorFunction(hit.square.x,hit.square.y);
|
||||||
wallScreenHeight = perspectiveScale((wallHeightWorld *
|
|
||||||
|
wallHeightScreen = perspectiveScale((wallHeightWorld *
|
||||||
_camera.resolution.y) / UNITS_PER_SQUARE,dist);
|
_camera.resolution.y) / UNITS_PER_SQUARE,dist);
|
||||||
|
|
||||||
|
int16_t normalizedWallHeight =
|
||||||
|
(UNITS_PER_SQUARE * wallHeightScreen) / wallHeightWorld;
|
||||||
|
|
||||||
heightOffset = perspectiveScale(_cameraHeightScreen,dist);
|
heightOffset = perspectiveScale(_cameraHeightScreen,dist);
|
||||||
|
|
||||||
wallStart = _middleRow - wallScreenHeight / 2 + heightOffset;
|
wallStart = _middleRow - wallHeightScreen + heightOffset +
|
||||||
|
normalizedWallHeight;
|
||||||
|
|
||||||
coordHelper = -1 * wallStart;
|
coordHelper = -1 * wallStart;
|
||||||
coordHelper = coordHelper >= 0 ? coordHelper : 0;
|
coordHelper = coordHelper >= 0 ? coordHelper : 0;
|
||||||
|
|
||||||
|
wallEnd = clamp(wallStart + wallHeightScreen,0,_camResYLimit);
|
||||||
wallStart = clamp(wallStart,0,_camResYLimit);
|
wallStart = clamp(wallStart,0,_camResYLimit);
|
||||||
wallEnd = clamp(wallStart + wallScreenHeight,0,_camResYLimit);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// draw ceiling
|
// draw ceiling
|
||||||
|
@ -1012,9 +1024,10 @@ void _columnFunctionSimple(HitResult *hits, uint16_t hitCount, uint16_t x,
|
||||||
p.position.y = y;
|
p.position.y = y;
|
||||||
|
|
||||||
if (_computeTextureCoords)
|
if (_computeTextureCoords)
|
||||||
p.textureCoordY = (coordHelper * UNITS_PER_SQUARE) / wallScreenHeight;
|
p.textureCoordY = (coordHelper * UNITS_PER_SQUARE) / wallHeightScreen;
|
||||||
|
|
||||||
_pixelFunction(&p);
|
_pixelFunction(&p);
|
||||||
|
|
||||||
++y;
|
++y;
|
||||||
++coordHelper;
|
++coordHelper;
|
||||||
}
|
}
|
||||||
|
@ -1089,8 +1102,8 @@ void renderSimple(Camera cam, ArrayFunction floorHeightFunc,
|
||||||
|
|
||||||
constraints.maxHits = 1;
|
constraints.maxHits = 1;
|
||||||
|
|
||||||
castRaysMultiHit(cam,_floorFunction,typeFunc,_columnFunctionSimple,
|
castRaysMultiHit(cam,_floorHeightNotZeroFunction,typeFunc,
|
||||||
constraints);
|
_columnFunctionSimple, constraints);
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector2D normalize(Vector2D v)
|
Vector2D normalize(Vector2D v)
|
||||||
|
|
Loading…
Reference in a new issue