Shkyera Engine
Easy to use, game engine for Python
Loading...
Searching...
No Matches
InputUtils.hpp
Go to the documentation of this file.
1#pragma once
2
8
10
12std::optional<Entity> getHoveredObject(const RegistryViewer& viewer) {
13 if (const auto cameraOpt = viewer.getEntity<CameraTag>()) {
14 const auto camera = *cameraOpt;
15 const auto& mousePosition = InputManager::getInstance().getRelativeMousePosition(CS);
17 const auto& cameraComponent = viewer.read<CameraComponent>(camera);
19
20 float closestDistance = std::numeric_limits<float>::max();
21 std::optional<Entity> closestEntity;
22 for (const auto& [entity, boxColliderComponent] : viewer.readAll<BoxColliderComponent<RN>>()) {
23 if (!viewer.has<RequiredComponents...>(entity)) {
24 continue;
25 }
31 }
32 }
33 return closestEntity;
34 }
35
36 SHKYERA_ASSERT(false, "{} CameraTag not registered. Cannot find what it's hovering over", typeid(CameraTag).name());
37 return std::nullopt;
38}
39
40} // namespace shkyera::utils::input
#define SHKYERA_ASSERT(predicate,...)
Definition Assert.hpp:7
Definition CameraComponent.hpp:10
CoordinateSystem
Definition InputManager.hpp:11
static InputManager & getInstance()
Definition InputManager.cpp:7
Definition RegistryViewer.hpp:51
Definition TransformComponent.hpp:21
Definition InputUtils.hpp:9
std::optional< Entity > getHoveredObject(const RegistryViewer &viewer)
Definition InputUtils.hpp:12
glm::mat4 getGlobalTransformMatrix(Entity entity, const RegistryViewer &viewer)
Definition TransformUtils.cpp:22
RuntimeMode
Definition Types.hpp:9
Definition Clock.hpp:9