From 2467bbbc621cd1997e14e79326594bc6af77b22d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miloslav=20=C4=8C=C3=AD=C5=BE?= Date: Sat, 15 Sep 2018 14:35:21 +0200 Subject: [PATCH] Add init functions --- raycastlib.h | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/raycastlib.h b/raycastlib.h index 04da83c..d6b1096 100644 --- a/raycastlib.h +++ b/raycastlib.h @@ -330,6 +330,9 @@ void moveCameraWithCollision(Camera *camera, Vector2D planeOffset, Unit heightOffset, ArrayFunction floorHeightFunc, ArrayFunction ceilingHeightFunc, int8_t computeHeight, int8_t force); +void initCamera(Camera *camera); +void initRayConstraints(RayConstraints *constraints); + //============================================================================= // privates @@ -1068,6 +1071,9 @@ void _columnFunctionSimple(HitResult *hits, uint16_t hitCount, uint16_t x, int16_t wallHeightWorld = _floorFunction(hit.square.x,hit.square.y); + wallHeightWorld = wallHeightWorld != 0 ? wallHeightWorld : 1; + // ^ prevent division by zero + wallHeightScreen = perspectiveScale((wallHeightWorld * _camera.resolution.y) / UNITS_PER_SQUARE,dist); @@ -1442,4 +1448,22 @@ void moveCameraWithCollision(Camera *camera, Vector2D planeOffset, } } +void initCamera(Camera *camera) +{ + camera->position.x = 0; + camera->position.y = 0; + camera->direction = 0; + camera->resolution.x = 20; + camera->resolution.y = 15; + camera->shear = 0; + camera->height = UNITS_PER_SQUARE; +} + +void initRayConstraints(RayConstraints *constraints) +{ + constraints->maxHits = 1; + constraints->maxSteps = 20; + constraints->computeTextureCoords = 1; +} + #endif