Physics Simulation & Visualization Tool 0.1
A C++ physics simulation engine with real-time 3D visualization
Loading...
Searching...
No Matches
IHandle.h
Go to the documentation of this file.
1
6#pragma once
7#include "../core/IDrawable.h"
8#include <glm/gtc/quaternion.hpp>
9#include "Axis.h"
10
17constexpr glm::vec3 axisDir(Axis a) {
18 switch (a) {
19 case Axis::X:
20 return {1,0,0};
21 case Axis::Y:
22 return {0,1,0};
23 default:
24 return {0,0,1};
25 }
26}
27
28class Mesh;
29
47class IHandle{
48public:
52 virtual ~IHandle() = default;
53
69 virtual void onDrag(const Math::Ray& ray) = 0;
70
84 virtual void setDragState(glm::vec3 initHitPos) = 0;
85
94 virtual glm::vec3 getAxisDir() const = 0;
95
108 virtual glm::mat4 getModelMatrix() const = 0;
109
110protected:
114 IHandle() = default;
115
127 static glm::mat4 rotateFromYToAxis(Axis axis) {
128 glm::vec3 from = {0, 1, 0};
129 glm::vec3 to = axisDir(axis);
130 glm::vec3 crossA = glm::cross(from, to);
131 float cosA = glm::dot(from, to);
132
133 if (glm::length(crossA) < 1e-3f) {
134 return glm::mat4(1.0f);
135 }
136
137 float angle = std::acos(glm::clamp(cosA, -1.0f, 1.0f));
138 return glm::rotate(glm::mat4(1.0f), angle, glm::normalize(crossA));
139 }
140};
Axis
Cardinal axes for handle orientation.
Definition Axis.h:7
@ Y
Definition Axis.h:8
@ X
Definition Axis.h:8
constexpr glm::vec3 axisDir(Axis a)
Converts an axis enum to its corresponding unit vector.
Definition IHandle.h:17
Abstract interface for gizmo manipulation handles.
Definition IHandle.h:47
virtual void onDrag(const Math::Ray &ray)=0
Handles continuous dragging motion.
virtual glm::vec3 getAxisDir() const =0
Gets the axis direction this handle operates along/around.
virtual glm::mat4 getModelMatrix() const =0
Gets the model transformation matrix for rendering this handle.
virtual ~IHandle()=default
Virtual destructor for proper cleanup of derived classes.
static glm::mat4 rotateFromYToAxis(Axis axis)
Computes rotation matrix to align mesh from +Y to target axis.
Definition IHandle.h:127
IHandle()=default
Protected constructor to enforce interface-only usage.
virtual void setDragState(glm::vec3 initHitPos)=0
Initializes the drag operation state.
GPU mesh representation with support for instanced rendering.
Definition Mesh.h:58
Represents a ray in 3D space.
Definition Ray.h:11