11 std::optional<uint32_t> collection)
13 , m_buf(
std::move(buf))
14 , m_collection(collection)
18 "Hull needs a buffer");
25 "Hull contains nothing: no geometry could be read from the buffer");
36 const float det = glm::determinant(glm::mat3(drawn));
37 if (det == 0.0F || !std::isfinite(det)) {
41 return m_local->contains(glm::vec3(glm::inverse(drawn) * glm::vec4(p, 1.0F)));
51 const glm::vec3 center = glm::vec3(drawn * glm::vec4(
m_local->center(), 1.0F));
54 for (
int corner = 0; corner < 8; ++corner) {
55 const glm::vec3 local {
60 radius = std::max(
radius, glm::length(glm::vec3(drawn * glm::vec4(local, 1.0F)) - center));
75 "Hull::refit kept the previous bounds: no geometry could be read from the buffer");
#define MF_ERROR(comp, ctx,...)
#define MF_WARN(comp, ctx,...)
Expanse::CrossingFn on_enter
Expanse::CrossingFn on_exit
std::function< void(uint32_t)> CrossingFn
const std::optional< Kinesis::AABB3D > & bounds() const
The box, if set.
std::function< bool(const glm::vec3 &)> ContainsFn
virtual std::pair< glm::vec3, float > reach() const
Where the region is centred and how far it reaches, for perceptions.
A defined region of space with a containment test and crossing actions.
void refit()
Read the buffer's geometry again and take its bounds.
Hull(std::shared_ptr< Buffers::VKBuffer > buf, CrossingFn on_enter={}, CrossingFn on_exit={}, std::optional< uint32_t > collection=std::nullopt)
Build from a buffer.
std::optional< uint32_t > m_collection
std::optional< Kinesis::AABB3D > m_local
bool contains(const glm::vec3 &p) const override
Test whether a world position lies within the buffer's bounds as drawn.
std::pair< glm::vec3, float > reach() const override
The centre of the bounds as drawn, and the distance to their farthest corner.
std::shared_ptr< Buffers::VKBuffer > m_buf
@ Init
Engine/subsystem initialization.
@ Runtime
General runtime operations (default fallback)
@ Nexus
Spatial indexing and scheduling for user-defined behaviour.
glm::mat4 read_placement(const std::shared_ptr< Buffers::VKBuffer > &buf)
Where a buffer is drawn: the geometry transform of its primary render processor.
std::optional< Kinesis::AABB3D > read_bounds(const std::shared_ptr< Buffers::VKBuffer > &buf, const std::optional< uint32_t > &collection)
Bounds of a buffer's geometry in its own stored coordinates.