voxelcore/test/physics/Hitbox.cpp
ostermine 95d2121318 add tests for positions far from the world origin
dev/tests/far_coords.lua: at 1M and 30M blocks a position of a player,
a spawn point and an entity is read back as it was set, a ray hits the
block it is cast to, a body with a velocity moves the same way as at
the world origin, and a position at 30M survives saving and loading of
the world. test/physics/Hitbox.cpp checks the AABB of a hitbox far from
the world origin, test/window/Camera.cpp checks the view relative to the
rendering origin with positions in doubles.
2026-11-12 10:05:09 +03:00

30 lines
1.1 KiB
C++

#include <gtest/gtest.h>
#include "physics/Hitbox.hpp"
TEST(Hitbox, AABBRelativeToOrigin) {
for (double coord : {0.0, 1e6, 3e7}) {
worldvec3 position(coord + 0.3, 64.25, -coord - 0.7);
Hitbox hitbox(
1, BodyType::DYNAMIC, position, glm::vec3(0.3f, 0.9f, 0.3f)
);
AABB aabb = hitbox.getAABB(glm::floor(position));
EXPECT_NEAR(aabb.a.x, 0.0f, 1e-6f) << "at " << coord;
EXPECT_NEAR(aabb.a.y, -0.65f, 1e-6f) << "at " << coord;
EXPECT_NEAR(aabb.a.z, 0.0f, 1e-6f) << "at " << coord;
EXPECT_NEAR(aabb.b.x, 0.6f, 1e-6f) << "at " << coord;
EXPECT_NEAR(aabb.b.y, 1.15f, 1e-6f) << "at " << coord;
EXPECT_NEAR(aabb.b.z, 0.6f, 1e-6f) << "at " << coord;
}
}
TEST(Hitbox, SetPosFarFromOrigin) {
worldvec3 position(3e7 + 0.3, 64.25, -3e7 - 0.7);
Hitbox hitbox(1, BodyType::DYNAMIC, {}, glm::vec3(0.3f, 0.9f, 0.3f));
hitbox.setPos(position);
EXPECT_EQ(hitbox.position, position);
EXPECT_EQ(hitbox.prevPosition, position);
hitbox.setPos(position + worldvec3(0.05, 0.0, 0.0));
EXPECT_EQ(hitbox.prevPosition, position);
}