WoW Model Viewer
Your premiere tool for viewing, equipping and animating World of Warcraft models.
Loading...
Searching...
No Matches
InputManager.cpp
Go to the documentation of this file.
1#include "InputManager.h"
2
3#include "imgui.h"
4
9
10// ---------------------------------------------------------------------------
11// Default bindings — reproduces the original hardcoded viewer controls
12// ---------------------------------------------------------------------------
13
15{
16 m_bindings.clear();
17 m_bindings.reserve(14);
18
19 // ---- Mouse bindings ---------------------------------------------------
20
21 // Left drag -> orbit (yaw + pitch)
23 ImGuiMouseButton_Left, ImGuiKey_None,
24 -0.25f, -0.25f, 0.0f, 0.1f});
25
26 // Right drag -> pan (lateral + vertical)
28 ImGuiMouseButton_Right, ImGuiKey_None,
29 -(0.25f * 0.025f), (0.25f * 0.025f), 0.0f, 0.1f});
30
31 // Middle drag -> zoom (Y-axis only)
33 ImGuiMouseButton_Middle, ImGuiKey_None,
34 0.0f, (0.25f / 10.0f), 0.0f, 0.1f});
35
36 // Scroll wheel -> zoom
38 ImGuiMouseButton_Left, ImGuiKey_None,
39 -0.5f, 0.0f, 0.0f, 0.1f});
40
41 // ---- Numpad orbit -----------------------------------------------------
42
43 // Numpad 4 -> yaw left
45 ImGuiMouseButton_Left, ImGuiKey_Keypad4,
46 0.0f, 0.0f, 1.0f, 1.0f});
47
48 // Numpad 6 -> yaw right
50 ImGuiMouseButton_Left, ImGuiKey_Keypad6,
51 0.0f, 0.0f, -1.0f, 1.0f});
52
53 // Numpad 8 -> pitch up
55 ImGuiMouseButton_Left, ImGuiKey_Keypad8,
56 0.0f, 0.0f, 1.0f, 1.0f});
57
58 // Numpad 2 -> pitch down
60 ImGuiMouseButton_Left, ImGuiKey_Keypad2,
61 0.0f, 0.0f, -1.0f, 1.0f});
62
63 // ---- Numpad pan -------------------------------------------------------
64
65 // Numpad 7 -> pan up (world Z+)
67 ImGuiMouseButton_Left, ImGuiKey_Keypad7,
68 0.0f, 0.0f, 0.2f, 1.0f});
69
70 // Numpad 9 -> pan down (world Z-)
72 ImGuiMouseButton_Left, ImGuiKey_Keypad9,
73 0.0f, 0.0f, -0.2f, 1.0f});
74
75 // Numpad 1 -> pan left (camera right -)
77 ImGuiMouseButton_Left, ImGuiKey_Keypad1,
78 0.0f, 0.0f, -0.2f, 1.0f});
79
80 // Numpad 3 -> pan right (camera right +)
82 ImGuiMouseButton_Left, ImGuiKey_Keypad3,
83 0.0f, 0.0f, 0.2f, 1.0f});
84
85 // ---- Reset ------------------------------------------------------------
86
87 // Numpad 5 -> reset camera
89 ImGuiMouseButton_Left, ImGuiKey_Keypad5,
90 0.0f, 0.0f, 0.0f, 1.0f});
91}
92
93// ---------------------------------------------------------------------------
94// Per-frame update — resolve all bindings against ImGui IO
95// ---------------------------------------------------------------------------
96
98{
99 m_state = {};
100
101 const ImGuiIO& io = ImGui::GetIO();
102
103 for (const auto& b : m_bindings)
104 {
105 const float shiftMul = (io.KeyShift && b.shiftScale != 1.0f)
106 ? b.shiftScale : 1.0f;
107
108 switch (b.trigger)
109 {
111 {
112 if (!ImGui::IsMouseDragging(b.mouseButton))
113 break;
114
115 const float dx = io.MouseDelta.x * b.scaleX * shiftMul;
116 const float dy = io.MouseDelta.y * b.scaleY * shiftMul;
117
118 switch (b.action)
119 {
121 m_state.orbitYaw += dx;
122 m_state.orbitPitch += dy;
123 break;
125 m_state.panX += dx;
126 m_state.panZ += dy;
127 break;
129 m_state.zoom += dy;
130 break;
131 default:
132 break;
133 }
134 break;
135 }
136
138 {
139 if (io.MouseWheel == 0.0f)
140 break;
141
142 const float scroll = io.MouseWheel * b.scaleX * shiftMul;
143
144 if (b.action == ViewportAction::Zoom)
145 m_state.zoom += scroll;
146 break;
147 }
148
150 {
151 if (!ImGui::IsKeyDown(b.key))
152 break;
153
154 const float delta = b.keyDelta;
155
156 switch (b.action)
157 {
158 case ViewportAction::OrbitYaw: m_state.orbitYaw += delta; break;
159 case ViewportAction::OrbitPitch: m_state.orbitPitch += delta; break;
160 case ViewportAction::PanLateral: m_state.panX += delta; break;
161 case ViewportAction::PanVertical: m_state.panZ += delta; break;
162 case ViewportAction::Zoom: m_state.zoom += delta; break;
163 default: break;
164 }
165 break;
166 }
167
169 {
170 if (!ImGui::IsKeyPressed(b.key))
171 break;
172
173 if (b.action == ViewportAction::ResetCamera)
174 m_state.resetCamera = true;
175 break;
176 }
177 }
178 }
179}
void loadDefaults()
Populate the binding table with default viewer controls.
std::vector< InputBinding > m_bindings
InputState m_state
bool resetCamera
Definition InputAction.h:78
float orbitPitch
Definition InputAction.h:74
float orbitYaw
Definition InputAction.h:73