Skip to content

Commit

Permalink
Add bbox mul operator to scripting
Browse files Browse the repository at this point in the history
  • Loading branch information
edunad committed Oct 16, 2024
1 parent 4ac60fd commit aaade73
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 25 deletions.
23 changes: 5 additions & 18 deletions rawrbox.math/include/rawrbox/math/bbox.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<NumberType>& 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<NumberType>& other) const { return this->size == other.size; }
bool operator!=(const BBOX_t<NumberType>& 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<NumberType>& operator*(const rawrbox::Vector3_t<NumberType>& vec) {
this->min *= vec;
this->max *= vec;
this->size *= vec;

return *this;
}

BBOX_t<NumberType>& 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<NumberType>& other) const { return BBOXType(this->min * other, this->max * other, this->size * other); }
};

using BBOXd = BBOX_t<double>;
Expand Down
4 changes: 1 addition & 3 deletions rawrbox.render/include/rawrbox/render/models/mesh.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,7 @@ namespace rawrbox {
[[nodiscard]] virtual const std::vector<T>& getVertices() const { return this->vertices; }
[[nodiscard]] virtual const std::vector<uint32_t>& 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();
Expand Down
5 changes: 1 addition & 4 deletions rawrbox.render/include/rawrbox/render/models/model.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ namespace rawrbox {
requires(std::is_integral_v<T> || std::is_floating_point_v<T>)
static void registerTemplate(lua_State* L, const std::string& name) {
using BBOXT = rawrbox::BBOX_t<T>;
using VECT = rawrbox::Vector3_t<T>;

luabridge::getGlobalNamespace(L)
.beginClass<BBOXT>(name.c_str())
Expand All @@ -21,6 +22,10 @@ namespace rawrbox {
.addFunction("isEmpty", &BBOXT::isEmpty)
.addFunction("combine", &BBOXT::combine)

.addFunction("__mul",
luabridge::overload<T>(&BBOXT::operator*),
luabridge::overload<const VECT&>(&BBOXT::operator*))

.addFunction("__eq", &BBOXT::operator==)
.addFunction("__ne", &BBOXT::operator!=)

Expand Down

0 comments on commit aaade73

Please sign in to comment.