Skip to content

Commit

Permalink
fix movement and collisions
Browse files Browse the repository at this point in the history
  • Loading branch information
proller committed Dec 29, 2024
1 parent aa5cbf1 commit 5dfb8c1
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
18 changes: 9 additions & 9 deletions src/collision.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ CollisionAxis axisAlignedCollision(
{
//TimeTaker tt("axisAlignedCollision");

aabb3f relbox(
aabb3o relbox(
(movingbox.MaxEdge.X - movingbox.MinEdge.X) + (staticbox.MaxEdge.X - staticbox.MinEdge.X), // sum of the widths
(movingbox.MaxEdge.Y - movingbox.MinEdge.Y) + (staticbox.MaxEdge.Y - staticbox.MinEdge.Y),
(movingbox.MaxEdge.Z - movingbox.MinEdge.Z) + (staticbox.MaxEdge.Z - staticbox.MinEdge.Z),
Expand Down Expand Up @@ -241,7 +241,7 @@ static bool add_area_node_boxes(const v3pos_t min, const v3pos_t max, IGameDef *
// Calculate float position only once
auto posf = intToFloat(p, BS);
for (auto boxf : nodeboxes) {
aabb3o box {v3fToOpos(boxf.MinEdge), v3fToOpos(boxf.MaxEdge)};
aabb3o box = ToOpos(boxf);
box.MinEdge += posf;
box.MaxEdge += posf;
cinfo.emplace_back(false, n_bouncy_value, p, box);
Expand Down Expand Up @@ -376,18 +376,18 @@ collisionMoveResult collisionMoveSimple(Environment *env, IGameDef *gamedef,
cinfo.clear();

{
v3f minpos_f(
v3opos_t minpos_f(
MYMIN(pos_f->X, newpos_f.X),
MYMIN(pos_f->Y, newpos_f.Y) + 0.01f * BS, // bias rounding, player often at +/-n.5
MYMIN(pos_f->Z, newpos_f.Z)
);
v3f maxpos_f(
v3opos_t maxpos_f(
MYMAX(pos_f->X, newpos_f.X),
MYMAX(pos_f->Y, newpos_f.Y),
MYMAX(pos_f->Z, newpos_f.Z)
);
v3pos_t min = floatToInt(minpos_f + box_0.MinEdge, BS) - v3pos_t(1, 1, 1);
v3pos_t max = floatToInt(maxpos_f + box_0.MaxEdge, BS) + v3pos_t(1, 1, 1);
v3pos_t min = floatToInt(minpos_f + v3fToOpos(box_0.MinEdge), BS) - v3pos_t(1, 1, 1);
v3pos_t max = floatToInt(maxpos_f + v3fToOpos(box_0.MaxEdge), BS) + v3pos_t(1, 1, 1);

bool any_position_valid = add_area_node_boxes(min, max, gamedef, env, cinfo);

Expand Down Expand Up @@ -424,7 +424,7 @@ collisionMoveResult collisionMoveSimple(Environment *env, IGameDef *gamedef,
break;
}

aabb3o movingbox(v3fToOpos(box_0.MinEdge), v3fToOpos(box_0.MaxEdge));
aabb3o movingbox(ToOpos(box_0));
movingbox.MinEdge += *pos_f;
movingbox.MaxEdge += *pos_f;

Expand Down Expand Up @@ -551,7 +551,7 @@ collisionMoveResult collisionMoveSimple(Environment *env, IGameDef *gamedef,
/*
Final touches: Check if standing on ground, step up stairs.
*/
aabb3o box(v3fToOpos(box_0.MinEdge), v3fToOpos(box_0.MaxEdge));
aabb3o box(ToOpos(box_0));
box.MinEdge += *pos_f;
box.MaxEdge += *pos_f;
for (const auto &box_info : cinfo) {
Expand All @@ -570,7 +570,7 @@ collisionMoveResult collisionMoveSimple(Environment *env, IGameDef *gamedef,
cbox.MinEdge.Z + d < box.MaxEdge.Z) {
if (box_info.is_step_up) {
pos_f->Y += cbox.MaxEdge.Y - box.MinEdge.Y;
box = {(v3fToOpos(box_0.MinEdge), v3fToOpos(box_0.MaxEdge))};
box = ToOpos(box_0);
box.MinEdge += *pos_f;
box.MaxEdge += *pos_f;
}
Expand Down
1 change: 0 additions & 1 deletion src/environment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,6 @@ void Environment::continueRaycast(RaycastState *state, PointedThing *result_p)
v3opos_t npf = intToFloat(np, BS);
v3opos_t rel_start = state->m_shootline.start - npf;
for (aabb3f &box : boxes) {
//aabb3o box(v3fToOpos(boxf.MinEdge), v3fToOpos(boxf.MaxEdge));
v3opos_t intersection_point;
v3f intersection_normal;
if (!boxLineCollision(box, rel_start,
Expand Down
2 changes: 1 addition & 1 deletion src/raycast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ bool boxLineCollision(const aabb3f &box, const v3opos_t start,
collision_normal->set(0, 0, 0);
return true;
}
float m = 0;
opos_t m = 0;

// Test X collision
if (dir.X != 0) {
Expand Down

0 comments on commit 5dfb8c1

Please sign in to comment.