Skip to content

Commit

Permalink
Add operator* to AABB, use in physics (#86)
Browse files Browse the repository at this point in the history
  • Loading branch information
crocdialer authored Dec 5, 2024
1 parent 4cc029d commit f978a65
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
17 changes: 16 additions & 1 deletion include/vierkant/intersection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

#pragma once

#include <vector>
#include <vierkant/math.hpp>
#include <vierkant/transform.hpp>
#include <vector>

namespace vierkant
{
Expand Down Expand Up @@ -317,6 +317,21 @@ struct AABB
return *this;
}

AABB operator*(float grow_factor) const
{
AABB ret(*this);
ret *= grow_factor;
return ret;
}

AABB &operator*=(float grow_factor)
{
auto c = center();
min = c + (min - c) * grow_factor;
max = c + (max - c) * grow_factor;
return *this;
}

inline explicit operator bool() const { return valid(); }

inline bool operator==(const AABB &aabb) const { return min == aabb.min && max == aabb.max; }
Expand Down
5 changes: 5 additions & 0 deletions src/physics_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1014,6 +1014,7 @@ void PhysicsScene::remove_object(const Object3DPtr &object)
{
if(object)
{
// remove all children
vierkant::LambdaVisitor visitor;
visitor.traverse(*object, [this](const auto &obj) -> bool {
if(auto phy_cmp_ptr = obj.template get_component_ptr<vierkant::physics_component_t>())
Expand All @@ -1022,6 +1023,10 @@ void PhysicsScene::remove_object(const Object3DPtr &object)
}
return true;
});

// grow aabb by a factor, wake up other objects there
constexpr float aabb_grow_factor = 1.2f;
m_context.body_interface().activate_in_aabb(object->aabb() * aabb_grow_factor);
}
vierkant::Scene::remove_object(object);
}
Expand Down

0 comments on commit f978a65

Please sign in to comment.