47 glDisable(GL_DEPTH_TEST);
51 std::vector<Rendering::InstanceData> drawData;
52 for (
const auto& handle : handles) {
53 glm::vec3 color = handle->getAxisDir();
56 if (handle.get() == hoveredHandle || handle.get() == activeHandle) {
57 color = glm::mix(color, glm::vec3(1.0f), 0.7f);
60 const glm::mat4 renderModel = worldToRender * handle->getModelMatrix();
61 drawData.push_back({ renderModel, objectID, color });
65 glEnable(GL_DEPTH_TEST);
72 float closestT = std::numeric_limits<float>::infinity();
74 for (
const auto& handle: handles) {
75 auto worldAABB = localAABB.
getTransformed(handle->getModelMatrix());
76 if (
auto t = worldAABB->intersectRay(ray)) {
79 bestHandle = handle.get();
84 hoveredHandle = bestHandle;
96 activeHandle = hoveredHandle;
103 activeHandle =
nullptr;
107 if (!isDragging || !activeHandle)
110 activeHandle->
onDrag(ray);
Interactive 3D manipulation gizmo for scene objects.
GizmoType
Types of transformation gizmos.
Mathematical utility functions for 3D graphics and physics.
void handleClick(const Math::Ray &ray, float distance) override
Handles mouse click on a gizmo handle.
Gizmo(GizmoType type, SceneManager *sceneManager, SceneObject *target)
Constructs a gizmo for the specified target object.
~Gizmo()
Destructor - frees object IDs and cleans up handles.
bool getHovered() const override
Gets the gizmo's hover state.
uint32_t getObjectID() const override
Gets the gizmo's unique identifier.
std::optional< float > intersectsRay(const Math::Ray &ray) const override
Tests if a ray intersects any of the gizmo's handles.
void handleDrag(const Math::Ray &ray)
Updates the active handle during a drag operation.
Mesh * getMesh() const override
Gets the shared mesh used for all handles.
void draw() const override
Renders all handles with custom depth-test-disabled rendering.
void handleRelease()
Handles mouse release - deactivates the active handle.
void setHovered(bool hovered) override
Sets the gizmo's hover state.
Shader * getShader() const override
Gets the shader used for gizmo rendering.
Abstract interface for gizmo manipulation handles.
virtual void onDrag(const Math::Ray &ray)=0
Handles continuous dragging motion.
virtual void setDragState(glm::vec3 initHitPos)=0
Initializes the drag operation state.
const Physics::Bounding::AABB & getLocalAABB() const
Gets the local-space axis-aligned bounding box.
void drawInstanced(const std::vector< Rendering::InstanceData > &instances)
Draws multiple instances of this mesh in a single draw call.
std::unique_ptr< ICollider > getTransformed(const glm::mat4 &modelMatrix) const override
Creates a transformed copy of this collider in world space.
static Mesh * getMesh(const std::string &name)
static Shader * loadShader(const std::string &vShaderPath, const std::string &fShaderPath, const std::string &name)
void addPickable(IPickable *obj)
void addDrawable(IDrawable *obj) const
static glm::mat4 worldToRenderMatrix()
void freeObjectID(uint32_t objID)
glm::vec3 origin
Starting point of the ray in world space.
glm::vec3 dir
Direction vector (should be normalized)
Represents a ray in 3D space.