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

Improve movement

This commit is contained in:
Miloslav Číž 2018-09-06 19:17:31 +02:00
parent f86215c4c1
commit 04b9c42e0a

View file

@ -979,34 +979,51 @@ void moveCameraWithCollision(Camera *camera, Vector2D planeOffset,
int16_t xSquareNew = divRoundDown(cornerNew.x,UNITS_PER_SQUARE); int16_t xSquareNew = divRoundDown(cornerNew.x,UNITS_PER_SQUARE);
int16_t ySquareNew = divRoundDown(cornerNew.y,UNITS_PER_SQUARE); int16_t ySquareNew = divRoundDown(cornerNew.y,UNITS_PER_SQUARE);
int8_t xCollides = Unit bottomLimit = camera->height - camera->collisionHeightBelow;
xSquare != xSquareNew && Unit topLimit = camera->height + camera->collisionHeightAbove;
floorHeightFunc(xSquareNew,ySquare) > UNITS_PER_SQUARE;
int8_t yCollides = int8_t xCollides;
ySquare != ySquareNew && int8_t yCollides;
floorHeightFunc(xSquare,ySquareNew) > UNITS_PER_SQUARE;
#define collideHelper(dir)\ #define collideHelper(dir,s1,s2)\
if (dir##Square != dir##SquareNew)\
{\
Unit height = floorHeightFunc(xSquare##s1,ySquare##s2);\
if (height > bottomLimit)\
dir##Collides = true;\
else if (ceilingHeightFunc != 0)\
{\
height = ceilingHeightFunc(xSquare##s1,ySquare##s2);\
if (height < topLimit)\
dir##Collides = true;\
}\
}\
else\
dir##Collides = false;\
\
if (dir##Collides)\ if (dir##Collides)\
cornerNew.dir = (dir##Square) * UNITS_PER_SQUARE + UNITS_PER_SQUARE / 2 +\ cornerNew.dir = (dir##Square) * UNITS_PER_SQUARE + UNITS_PER_SQUARE / 2 +\
dir##Dir * (UNITS_PER_SQUARE / 2) - dir##Dir; dir##Dir * (UNITS_PER_SQUARE / 2) - dir##Dir;\
collideHelper(x) collideHelper(x,New,)
collideHelper(y) collideHelper(y,,New)
#undef collideHelper #undef collideHelper
camera->position.x = cornerNew.x - xDir * camera->collisionRadius; camera->position.x = cornerNew.x - xDir * camera->collisionRadius;
camera->position.y = cornerNew.y - yDir * camera->collisionRadius; camera->position.y = cornerNew.y - yDir * camera->collisionRadius;
camera->height += heightOffset; camera->height += heightOffset;
xSquareNew = divRoundDown(camera->position.x,UNITS_PER_SQUARE);
ySquareNew = divRoundDown(camera->position.y,UNITS_PER_SQUARE);
Unit floorHeightNew = floorHeightFunc(xSquareNew,ySquareNew);
Unit ceilingHeightNew = ceilingHeightFunc != 0 ?
ceilingHeightFunc(xSquareNew,ySquareNew) : UNIT_INFINITY;
/*
camera->height = clamp(camera->height, camera->height = clamp(camera->height,
floorHeight2 + camera->collisionHeightBelow, floorHeightNew + camera->collisionHeightBelow,
ceilHeight2 - camera->collisionHeightAbove); ceilingHeightNew - camera->collisionHeightAbove);
*/
} }
#endif #endif