mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-11-21 09:59:44 +00:00
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.
This commit is contained in:
parent
ebd506de09
commit
95d2121318
3 changed files with 133 additions and 9 deletions
30
test/physics/Hitbox.cpp
Normal file
30
test/physics/Hitbox.cpp
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
#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);
|
||||
}
|
||||
|
|
@ -31,18 +31,18 @@ TEST(Camera, ViewRotationFarFromOrigin) {
|
|||
}
|
||||
|
||||
TEST(Camera, ViewRelativeToOrigin) {
|
||||
for (float coord : {0.0f, 500.0f, -1e5f, 1e6f, 3e7f}) {
|
||||
Camera camera(glm::vec3(coord, 64.0f, -coord), 1.0f);
|
||||
for (double coord : {0.0, 500.3, -1e5 - 0.3, 1e6 + 0.3, 3e7 + 0.3}) {
|
||||
Camera camera(worldvec3(coord, 64.0, -coord), 1.0f);
|
||||
camera.rotate(glm::radians(-20.0f), glm::radians(35.0f), 0.0f);
|
||||
|
||||
glm::dvec3 origin = camera.getOrigin();
|
||||
glm::vec3 local = camera.getLocalPosition();
|
||||
EXPECT_LE(glm::abs(local.x), 512.0f) << "at " << coord;
|
||||
EXPECT_LE(glm::abs(local.z), 512.0f) << "at " << coord;
|
||||
EXPECT_EQ(glm::dvec3(camera.position), origin + glm::dvec3(local));
|
||||
worldvec3 origin = camera.getOrigin();
|
||||
worldvec3 local = camera.getLocalPosition();
|
||||
EXPECT_LE(glm::abs(local.x), 512.0) << "at " << coord;
|
||||
EXPECT_LE(glm::abs(local.z), 512.0) << "at " << coord;
|
||||
EXPECT_NEAR(camera.position.x, origin.x + local.x, 1e-4) << coord;
|
||||
EXPECT_NEAR(camera.position.z, origin.z + local.z, 1e-4) << coord;
|
||||
|
||||
glm::dvec3 point =
|
||||
glm::dvec3(camera.position) + glm::dvec3(camera.front) * 10.0;
|
||||
worldvec3 point = camera.position + worldvec3(camera.front) * 10.0;
|
||||
glm::vec4 viewPoint =
|
||||
camera.getView() * glm::vec4(glm::vec3(point - origin), 1.0f);
|
||||
EXPECT_NEAR(viewPoint.x, 0.0f, 1e-3f) << "at " << coord;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue