mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-11-20 09:29:44 +00:00
Camera::getView built the view with lookAt(position, position + front): the direction came back as a difference of large floats. Far from the origin the view turned away from where the camera looks - at 16M blocks by up to 24 degrees, at 30M the camera looked straight up or down whatever its yaw (at pitch 0 the direction is a zero vector, the matrix is NaN). The rotation is built from front itself now, then translated by -position: the same matrix, without the subtraction.
31 lines
1 KiB
C++
31 lines
1 KiB
C++
#include <gtest/gtest.h>
|
|
|
|
#include <cmath>
|
|
#include <glm/ext.hpp>
|
|
|
|
#include "window/Camera.hpp"
|
|
|
|
TEST(Camera, ViewRotationFarFromOrigin) {
|
|
for (float coord : {0.0f, 1e5f, 1e6f, 3e7f}) {
|
|
for (bool rotated : {false, true}) {
|
|
Camera camera(glm::vec3(coord, 64.0f, coord), 1.0f);
|
|
if (rotated) {
|
|
camera.rotate(glm::radians(-20.0f), glm::radians(35.0f), 0.0f);
|
|
}
|
|
glm::mat4 rotation = camera.getView(false);
|
|
glm::mat4 view = camera.getView();
|
|
for (int col = 0; col < 4; col++) {
|
|
for (int row = 0; row < 4; row++) {
|
|
ASSERT_TRUE(std::isfinite(view[col][row]))
|
|
<< "at " << coord;
|
|
}
|
|
}
|
|
for (int col = 0; col < 3; col++) {
|
|
for (int row = 0; row < 3; row++) {
|
|
EXPECT_NEAR(rotation[col][row], view[col][row], 1e-5f)
|
|
<< "at " << coord << ", rotated " << rotated;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|