guillaume 2026.6.1
A C++ UI framework designed for modern desktop and extended reality (XR) applications.
Loading...
Searching...
No Matches
hit_test.hpp
Go to the documentation of this file.
1/*
2 Copyright (c) 2026 ETIB Corporation
3
4 Permission is hereby granted, free of charge, to any person obtaining a copy of
5 this software and associated documentation files (the "Software"), to deal in
6 the Software without restriction, including without limitation the rights to
7 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
8 of the Software, and to permit persons to whom the Software is furnished to do
9 so, subject to the following conditions:
10
11 The above copyright notice and this permission notice shall be included in all
12 copies or substantial portions of the Software.
13
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 SOFTWARE.
21 */
22
23#pragma once
24
25#include <utility/graphic/pose.hpp>
26#include <utility/graphic/ray.hpp>
27#include <utility/math/vector.hpp>
28
29#include "guillaume/components/bound.hpp"
30#include "guillaume/components/hand_hover_interaction.hpp"
31#include "guillaume/components/mouse_hover_interaction.hpp"
32#include "guillaume/components/style_state.hpp"
33#include "guillaume/ecs/component_registry.hpp"
34#include "guillaume/ecs/entity.hpp"
35
36namespace guillaume::systems
37{
38
48
61 inline bool isInteractive(const ecs::ComponentRegistry &registry,
62 const ecs::Entity::Identifier &entityIdentifier)
63 {
64 return !registry.hasComponent<components::StyleState>(entityIdentifier)
65 || registry.getComponent<components::StyleState>(entityIdentifier)
66 .isEnabled();
67 }
68
83 inline utility::math::Vector2F
85 const ecs::Entity::Identifier &entityIdentifier)
86 {
88 entityIdentifier)) {
89 const auto margin =
90 registry
92 entityIdentifier)
93 .getAccessibilityMargin();
94 return utility::math::Vector2F(
95 { static_cast<float>(margin.getWidth()),
96 static_cast<float>(margin.getHeight()) });
97 }
99 entityIdentifier)) {
100 const auto margin =
101 registry
103 entityIdentifier)
104 .getAccessibilityMargin();
105 return utility::math::Vector2F(
106 { static_cast<float>(margin.getWidth()),
107 static_cast<float>(margin.getHeight()) });
108 }
109 return utility::math::Vector2F({ 0.0f, 0.0f });
110 }
111
138 inline bool hitTest(const utility::graphic::RayF &ray,
139 const utility::graphic::PoseF &pose,
140 const components::Bound &bound,
141 const utility::math::Vector2F &margin)
142 {
143 const auto size =
144 utility::math::Vector2F({ bound.getWidth() + 2.0f * margin[0],
145 bound.getHeight() + 2.0f * margin[1] });
146
147 // The pose is the top-left corner and the rectangle extends down
148 // (y points up). Ray::intersectRectangle extends its rectangle up
149 // from the corner it is given, so pass the bottom-left corner of the
150 // grown rectangle.
151 const auto &orientation = pose.getOrientation();
152 utility::graphic::PositionF position = pose.getPosition();
153 position.translate(
154 utility::graphic::PositionF(-(orientation.getRight() * margin[0])
155 + (orientation.getUp() * margin[1])
156 - (orientation.getUp() * size[1])));
157
158 return ray.intersectRectangle(
159 utility::graphic::PoseF(position, orientation), size);
160 }
161
162} // namespace guillaume::systems
Size of an entity: the width and height, in dp, of the rectangle that starts at the position of its c...
Definition bound.hpp:62
Whether an XR hand (controller) aims at an entity, what to call when the aim enters or leaves,...
Whether the mouse pointer is over an entity, what to call when it enters or leaves,...
The interaction state of an entity in one place: enabled or disabled, and whether it is hovered,...
bool isEnabled(void) const
Check whether the entity accepts interaction.
Stores every component of a scene, per component type and per entity identifier, and knows which ones...
ComponentType & getComponent(const Entity::Identifier &entityIdentifier)
Get a component of an entity, to read or modify it.
bool hasComponent(const Entity::Identifier &entityIdentifier) const
Tell whether an entity has a component of a given type.
std::size_t Identifier
The key under which an entity's components are stored. Systems and components refer to entities by th...
Definition entity.hpp:86
Rules. Every class here runs each frame on the entities that have the components it declares.
bool hitTest(const utility::graphic::RayF &ray, const utility::graphic::PoseF &pose, const components::Bound &bound, const utility::math::Vector2F &margin)
Whether a ray crosses the rectangle of an entity, grown by a margin.
Definition hit_test.hpp:138
utility::math::Vector2F hitMargin(const ecs::ComponentRegistry &registry, const ecs::Entity::Identifier &entityIdentifier)
Extra hit area of an entity around its Bound, in dp.
Definition hit_test.hpp:84
bool isInteractive(const ecs::ComponentRegistry &registry, const ecs::Entity::Identifier &entityIdentifier)
Whether an entity accepts input.
Definition hit_test.hpp:61