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

Add simple movement

This commit is contained in:
Miloslav Číž 2018-09-08 18:07:36 +02:00
parent 39f8b99cf3
commit 64dfbad14c

View file

@ -228,7 +228,7 @@ void render(Camera cam, ArrayFunction floorHeightFunc,
void moveCameraWithCollision(Camera *camera, Vector2D planeOffset, void moveCameraWithCollision(Camera *camera, Vector2D planeOffset,
Unit heightOffset, ArrayFunction floorHeightFunc, Unit heightOffset, ArrayFunction floorHeightFunc,
ArrayFunction ceilingHeightFunc); ArrayFunction ceilingHeightFunc, int8_t computeHeight);
//============================================================================= //=============================================================================
// privates // privates
@ -984,7 +984,7 @@ Unit perspectiveScale(Unit originalSize, Unit distance)
void moveCameraWithCollision(Camera *camera, Vector2D planeOffset, void moveCameraWithCollision(Camera *camera, Vector2D planeOffset,
Unit heightOffset, ArrayFunction floorHeightFunc, Unit heightOffset, ArrayFunction floorHeightFunc,
ArrayFunction ceilingHeightFunc) ArrayFunction ceilingHeightFunc, int8_t computeHeight)
{ {
// TODO: have the cam coll parameters precomputed as macros? => faster // TODO: have the cam coll parameters precomputed as macros? => faster
@ -1017,6 +1017,7 @@ void moveCameraWithCollision(Camera *camera, Vector2D planeOffset,
// checks a single square for collision against the camera // checks a single square for collision against the camera
#define collCheck(dir,s1,s2)\ #define collCheck(dir,s1,s2)\
if (computeHeight)\
{\ {\
Unit height = floorHeightFunc(s1,s2);\ Unit height = floorHeightFunc(s1,s2);\
if (height > bottomLimit)\ if (height > bottomLimit)\
@ -1028,6 +1029,8 @@ void moveCameraWithCollision(Camera *camera, Vector2D planeOffset,
dir##Collides = true;\ dir##Collides = true;\
}\ }\
}\ }\
else\
dir##Collides = floorHeightFunc(s1,s2) > CAMERA_COLL_STEP_HEIGHT;
// check a collision against non-diagonal square // check a collision against non-diagonal square
#define collCheckOrtho(dir,dir2,s1,s2,x)\ #define collCheckOrtho(dir,dir2,s1,s2,x)\
@ -1083,7 +1086,7 @@ void moveCameraWithCollision(Camera *camera, Vector2D planeOffset,
camera->position.y = cornerNew.y - yDir * CAMERA_COLL_RADIUS; camera->position.y = cornerNew.y - yDir * CAMERA_COLL_RADIUS;
} }
if (movesInPlane || heightOffset != 0) if (computeHeight && (movesInPlane || heightOffset != 0))
{ {
camera->height += heightOffset; camera->height += heightOffset;