1
0
Fork 0
mirror of https://git.coom.tech/drummyfish/raycastlib.git synced 2024-11-23 20:49:57 +01:00

Improve physics

This commit is contained in:
Miloslav Číž 2018-09-08 10:08:14 +02:00
parent d61340df62
commit a12da2290a

View file

@ -1006,6 +1006,9 @@ void moveCameraWithCollision(Camera *camera, Vector2D planeOffset,
int16_t xSquare = divRoundDown(corner.x,UNITS_PER_SQUARE); int16_t xSquare = divRoundDown(corner.x,UNITS_PER_SQUARE);
int16_t ySquare = divRoundDown(corner.y,UNITS_PER_SQUARE); int16_t ySquare = divRoundDown(corner.y,UNITS_PER_SQUARE);
int8_t isOnGround = camera->height - CAMERA_COLL_HEIGHT_BELOW -
floorHeightFunc(xSquareNew,ySquareNew) < 2;
cornerNew.x = corner.x + planeOffset.x; cornerNew.x = corner.x + planeOffset.x;
cornerNew.y = corner.y + planeOffset.y; cornerNew.y = corner.y + planeOffset.y;
@ -1013,7 +1016,7 @@ void moveCameraWithCollision(Camera *camera, Vector2D planeOffset,
ySquareNew = divRoundDown(cornerNew.y,UNITS_PER_SQUARE); ySquareNew = divRoundDown(cornerNew.y,UNITS_PER_SQUARE);
Unit bottomLimit = camera->height - CAMERA_COLL_HEIGHT_BELOW + Unit bottomLimit = camera->height - CAMERA_COLL_HEIGHT_BELOW +
CAMERA_COLL_RADIUS; (isOnGround ? CAMERA_COLL_STEP_HEIGHT : 0);
Unit topLimit = camera->height + CAMERA_COLL_HEIGHT_ABOVE; Unit topLimit = camera->height + CAMERA_COLL_HEIGHT_ABOVE;
// checks a single square for collision against the camera // checks a single square for collision against the camera
@ -1058,10 +1061,7 @@ void moveCameraWithCollision(Camera *camera, Vector2D planeOffset,
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;\
collHandle(x) if (!xCollides && !yCollides) /* if non-diagonal collision happend, corner
collHandle(y)
if (!xCollides && !yCollides) /* if collision happend by now, corner
collision can't happen */ collision can't happen */
{ {
if (xSquare != xSquareNew && ySquare != ySquareNew) // corner? if (xSquare != xSquareNew && ySquare != ySquareNew) // corner?
@ -1070,9 +1070,18 @@ void moveCameraWithCollision(Camera *camera, Vector2D planeOffset,
collCheck(xy,xSquareNew,ySquareNew) collCheck(xy,xSquareNew,ySquareNew)
if (xyCollides) if (xyCollides)
cornerNew = corner; {
if (wrap(cornerNew.x,UNITS_PER_SQUARE) >
wrap(cornerNew.y,UNITS_PER_SQUARE))
yCollides = true;
else
xCollides = true;
} }
} }
}
collHandle(x)
collHandle(y)
#undef collCheck #undef collCheck
#undef collHandle #undef collHandle