46 float nearest_distance = std::numeric_limits<float>::infinity();
51 [&](
entity::id entity_id,
const auto& picking,
const auto& transform)
54 if (!~(flags | picking.flags))
60 transform.world * picking.sphere.center,
61 picking.sphere.radius *
math::max(transform.world.scale)
68 float t0 = std::get<0>(*result);
69 float t1 = std::get<1>(*result);
71 if (t0 < nearest_distance)
73 nearest_eid = entity_id;
74 nearest_distance = t0;
86 float nearest_sqr_distance = std::numeric_limits<float>::infinity();
94 [&](
entity::id entity_id,
const auto& picking,
const auto& transform)
97 if (!~(flags | picking.flags))
101 math::fvec3 picking_sphere_center = transform.world * picking.sphere.center;
104 if (picking_plane.
distance(picking_sphere_center) < 0.0f)
113 nearest_eid = entity_id;
collision_system(entity::registry ®istry)
virtual void update(float t, float dt)
Perform's a system's update() function.
entity::id pick_nearest(const geom::ray< float, 3 > &ray, std::uint32_t flags) const
Picks the nearest entity with the specified picking flags that intersects a ray.
Abstract base class for updatable systems.
entity::registry & registry
Registry on which the system operate.
entt::registry registry
Component registry type.
entt::entity id
Entity ID type.
hypersphere< T, 3 > sphere
3-dimensional hypersphere.
constexpr std::optional< T > intersection(const ray< T, N > &ray, const hyperplane< T, N > &hyperplane) noexcept
Ray-hyperplane intersection test.
constexpr T sqr_distance(const vector< T, N > &p0, const vector< T, N > &p1) noexcept
Calculates the square distance between two points.
constexpr vector< T, N > max(const vector< T, N > &x, const vector< T, N > &y)
Returns a vector containing the maximum elements of two vectors.
@ normal
Vertex normal (vec3)
constexpr T distance(const vector_type &point) const noexcept
Calculates the signed distance from the hyperplane to a point.
Half of a line proceeding from an initial point.