From aaade7359724214eff68dd020731c3bb4bfab910 Mon Sep 17 00:00:00 2001 From: failcake <4944278+edunad@users.noreply.github.com> Date: Wed, 16 Oct 2024 16:11:12 +0200 Subject: [PATCH] Add bbox mul operator to scripting --- rawrbox.math/include/rawrbox/math/bbox.hpp | 23 ++++--------------- .../include/rawrbox/render/models/mesh.hpp | 4 +--- .../include/rawrbox/render/models/model.hpp | 5 +--- .../rawrbox/scripting/wrappers/math/bbox.hpp | 5 ++++ 4 files changed, 12 insertions(+), 25 deletions(-) diff --git a/rawrbox.math/include/rawrbox/math/bbox.hpp b/rawrbox.math/include/rawrbox/math/bbox.hpp index aa8c1a26..0e0f3dd3 100644 --- a/rawrbox.math/include/rawrbox/math/bbox.hpp +++ b/rawrbox.math/include/rawrbox/math/bbox.hpp @@ -37,31 +37,18 @@ namespace rawrbox { return pos.x >= this->min.x && pos.x <= this->max.x && pos.y >= this->min.y && pos.y <= this->max.y && pos.z >= this->min.z && pos.z <= this->max.z; } - void combine(const BBOX_t& b) { + void combine(const BBOXType& b) { this->min = {std::min(this->min.x, b.min.x), std::min(this->min.y, b.min.y), std::min(this->min.z, b.min.z)}; this->max = {std::max(this->max.x, b.max.x), std::max(this->max.y, b.max.y), std::max(this->max.z, b.max.z)}; this->size = this->min.abs() + this->max.abs(); } - bool operator==(const BBOX_t& other) const { return this->size == other.size; } - bool operator!=(const BBOX_t& other) const { return !operator==(other); } + bool operator==(const BBOXType& other) const { return this->size == other.size; } + bool operator!=(const BBOXType& other) const { return !operator==(other); } - BBOX_t& operator*(const rawrbox::Vector3_t& vec) { - this->min *= vec; - this->max *= vec; - this->size *= vec; - - return *this; - } - - BBOX_t& operator*(NumberType scalar) { - this->min *= scalar; - this->max *= scalar; - this->size *= scalar; - - return *this; - } + BBOXType operator*(NumberType other) const { return BBOXType(this->min * other, this->max * other, this->size * other); } + BBOXType operator*(const rawrbox::Vector3_t& other) const { return BBOXType(this->min * other, this->max * other, this->size * other); } }; using BBOXd = BBOX_t; diff --git a/rawrbox.render/include/rawrbox/render/models/mesh.hpp b/rawrbox.render/include/rawrbox/render/models/mesh.hpp index 104b6c39..448e69ca 100644 --- a/rawrbox.render/include/rawrbox/render/models/mesh.hpp +++ b/rawrbox.render/include/rawrbox/render/models/mesh.hpp @@ -167,9 +167,7 @@ namespace rawrbox { [[nodiscard]] virtual const std::vector& getVertices() const { return this->vertices; } [[nodiscard]] virtual const std::vector& getIndices() const { return this->indices; } - [[nodiscard]] virtual const rawrbox::BBOX getBBOX() const { - return this->bbox * this->getScale(); - } + [[nodiscard]] virtual rawrbox::BBOX getBBOX() const { return this->bbox * this->_scale; } [[nodiscard]] virtual bool empty() const { return this->indices.empty() || this->vertices.empty(); diff --git a/rawrbox.render/include/rawrbox/render/models/model.hpp b/rawrbox.render/include/rawrbox/render/models/model.hpp index 08c44657..5ac28498 100644 --- a/rawrbox.render/include/rawrbox/render/models/model.hpp +++ b/rawrbox.render/include/rawrbox/render/models/model.hpp @@ -367,10 +367,7 @@ namespace rawrbox { this->updateLights(); } - [[nodiscard]] virtual const rawrbox::BBOX getBBOX() { - return this->_bbox * this->getScale(); - } - + [[nodiscard]] virtual rawrbox::BBOX getBBOX() { return this->_bbox * this->getScale(); } [[nodiscard]] virtual size_t totalMeshes() const { return this->_meshes.size(); } diff --git a/rawrbox.scripting/include/rawrbox/scripting/wrappers/math/bbox.hpp b/rawrbox.scripting/include/rawrbox/scripting/wrappers/math/bbox.hpp index 8e482a3e..c9a39a8e 100644 --- a/rawrbox.scripting/include/rawrbox/scripting/wrappers/math/bbox.hpp +++ b/rawrbox.scripting/include/rawrbox/scripting/wrappers/math/bbox.hpp @@ -9,6 +9,7 @@ namespace rawrbox { requires(std::is_integral_v || std::is_floating_point_v) static void registerTemplate(lua_State* L, const std::string& name) { using BBOXT = rawrbox::BBOX_t; + using VECT = rawrbox::Vector3_t; luabridge::getGlobalNamespace(L) .beginClass(name.c_str()) @@ -21,6 +22,10 @@ namespace rawrbox { .addFunction("isEmpty", &BBOXT::isEmpty) .addFunction("combine", &BBOXT::combine) + .addFunction("__mul", + luabridge::overload(&BBOXT::operator*), + luabridge::overload(&BBOXT::operator*)) + .addFunction("__eq", &BBOXT::operator==) .addFunction("__ne", &BBOXT::operator!=)