Merge branch 'main' into volume-renderer

This commit is contained in:
MihailRis 2026-02-02 20:17:17 +03:00
commit b69c92b330
8 changed files with 96 additions and 7 deletions

View file

@ -1,9 +1,13 @@
#include "Transform.hpp"
#include "data/dv_util.hpp"
#include "debug/Logger.hpp"
#include "maths/util.hpp"
#include <glm/gtc/matrix_transform.hpp>
static debug::Logger logger("entity-transform");
void Transform::refresh() {
combined = glm::mat4(1.0f);
combined = glm::translate(combined, pos);
@ -31,3 +35,34 @@ void Transform::deserialize(const dv::value& root) {
dv::get_vec(root, "size", size);
dv::get_mat(root, "rot", rot);
}
bool Transform::checkValue(const glm::vec3& vector, std::string_view name) {
if (util::is_nan_or_inf(vector)) {
auto message = "invalid vector attempted set to " + std::string(name) +
" : " + std::to_string(vector.x) + ", " +
std::to_string(vector.y) + ", " +
std::to_string(vector.z);
#ifndef NDEBUG
throw std::invalid_argument(message);
#else
logger.warning() << message;
return false;
#endif
}
return true;
}
bool Transform::checkValue(const glm::mat3& matrix, std::string_view name) {
if (util::is_nan_or_inf(matrix)) {
auto message =
"invalid matrix (contains nan or inf) attempted set to " +
std::string(name);
#ifndef NDEBUG
throw std::invalid_argument(message);
#else
logger.warning() << message;
return false;
#endif
}
return true;
}

View file

@ -2,6 +2,7 @@
#define GLM_ENABLE_EXPERIMENTAL
#include <stdexcept>
#include <glm/vec3.hpp>
#include <glm/mat4x4.hpp>
#include <glm/gtx/norm.hpp>
@ -24,11 +25,17 @@ struct Transform {
void refresh();
inline void setRot(const glm::mat3& m) {
if (!checkValue(m, "rotation")) {
return;
}
rot = m;
dirty = true;
}
inline void setSize(const glm::vec3& v) {
if (!checkValue(v, "size")) {
return;
}
if (glm::distance2(displaySize, v) >= EPSILON) {
dirty = true;
}
@ -36,9 +43,15 @@ struct Transform {
}
inline void setPos(const glm::vec3& v) {
if (!checkValue(v, "position")) {
return;
}
if (glm::distance2(displayPos, v) >= EPSILON) {
dirty = true;
}
pos = v;
}
static bool checkValue(const glm::vec3& v, std::string_view name);
static bool checkValue(const glm::mat3& v, std::string_view name);
};