20 std::unordered_map<std::string, PresetRecord> s_registry;
22 std::string make_key(
const std::shared_ptr<Core::Window>&
window,
const std::string&
name)
24 return std::to_string(
reinterpret_cast<uintptr_t
>(
window.get())) +
"_" +
name;
27 std::string event_name(
const std::string& prefix,
const char* suffix)
29 return "vp_" + prefix +
"_" + suffix;
35 const std::shared_ptr<Core::Window>&
window,
36 const std::shared_ptr<Buffers::RenderProcessor>& processor,
38 const std::string&
name)
55 "ViewportPresetMode {} is not yet implemented",
56 static_cast<int>(
mode));
61 const std::shared_ptr<Core::Window>&
window,
63 const std::string&
name)
65 for (
const auto& buf :
window->get_rendering_buffers()) {
66 auto rp = buf->get_render_processor();
74 const std::shared_ptr<Core::Window>&
window,
75 const std::shared_ptr<Buffers::RenderProcessor>& processor,
78 const std::string&
name)
80 auto& record = s_registry[make_key(
window,
name)];
81 record.saved_config =
window->get_input_config();
82 record.registered_events.clear();
84 auto st = std::make_shared<Kinesis::NavigationState>(
89 st->first_mouse =
true; }, event_name(
name,
"rmb_dn"));
117 st->first_mouse = true;
120 if (st->first_mouse) {
123 st->first_mouse = false;
127 static_cast<float>(x - st->last_x),
128 static_cast<float>(y - st->last_y));
130 st->last_y = y; }, event_name(
name,
"mouse"));
134 processor->set_view_transform_source(
136 auto win = window_weak.lock();
140 const auto& ws = win->get_state();
141 const float aspect = (ws.current_height > 0)
142 ?
static_cast<float>(ws.current_width) /
static_cast<float>(ws.current_height)
149 const std::shared_ptr<Core::Window>&
window,
152 const std::string&
name)
154 for (
const auto& buf :
window->get_rendering_buffers()) {
155 auto rp = buf->get_render_processor();
164 const std::shared_ptr<Core::Window>&
window,
165 const std::shared_ptr<Buffers::RenderProcessor>& processor,
168 const std::string&
name)
170 auto& record = s_registry[make_key(
window,
name)];
171 record.saved_config =
window->get_input_config();
172 record.registered_events.clear();
178 st->first_mouse =
true; }, event_name(
name,
"mmb_dn"));
187 st->first_mouse = true;
190 if (st->first_mouse) {
193 st->first_mouse = false;
196 const auto dx =
static_cast<float>(x - st->last_x);
197 const auto dy =
static_cast<float>(y - st->last_y);
205} }, event_name(
name,
"mouse"));
218 processor->set_view_transform_source(
220 auto win = window_weak.lock();
223 const auto& ws = win->get_state();
224 const float aspect = (ws.current_height > 0)
225 ?
static_cast<float>(ws.current_width) /
static_cast<float>(ws.current_height)
232 const std::shared_ptr<Core::Window>&
window,
235 const std::string&
name)
237 for (
const auto& buf :
window->get_rendering_buffers()) {
238 auto rp = buf->get_render_processor();
246 const std::shared_ptr<Core::Window>&
window,
247 const std::shared_ptr<Buffers::RenderProcessor>& processor,
250 const std::string&
name)
252 auto& record = s_registry[make_key(
window,
name)];
253 record.saved_config =
window->get_input_config();
254 record.registered_events.clear();
259 st->drag_held = true;
260 st->first_mouse = true; }, event_name(
name,
"drag_dn"));
265 if (!st->drag_held) {
266 st->first_mouse = true;
269 if (st->first_mouse) {
272 st->first_mouse = false;
275 const auto dx =
static_cast<float>(x - st->last_x);
276 const auto dy =
static_cast<float>(y - st->last_y);
280 auto win = window_weak.lock();
283 const auto& ws = win->get_state();
284 if (ws.current_width > 0 && ws.current_height > 0) {
286 static_cast<float>(ws.current_width),
287 static_cast<float>(ws.current_height));
288 } }, event_name(
name,
"mouse"));
292 processor->set_view_transform_source(
294 auto win = window_weak.lock();
297 const auto& ws = win->get_state();
298 const float aspect = (ws.current_height > 0)
299 ?
static_cast<float>(ws.current_width) /
static_cast<float>(ws.current_height)
306 const std::shared_ptr<Core::Window>&
window,
309 const std::string&
name)
311 for (
const auto& buf :
window->get_rendering_buffers()) {
312 auto rp = buf->get_render_processor();
320 const std::shared_ptr<Core::Window>&
window,
321 const std::shared_ptr<Buffers::RenderProcessor>& processor,
324 const std::string&
name)
326 auto& record = s_registry[make_key(
window,
name)];
327 record.saved_config =
window->get_input_config();
328 record.registered_events.clear();
330 auto st = std::make_shared<Kinesis::NavigationState>(
335 st->first_mouse = true; }, event_name(
name,
"drag_dn"));
341 st->first_mouse = true;
344 if (st->first_mouse) {
347 st->first_mouse = false;
350 const auto dx =
static_cast<float>(x - st->last_x);
351 const auto dy =
static_cast<float>(y - st->last_y);
355 const glm::vec3 forward {
356 std::cos(st->pitch) * std::sin(st->yaw),
358 std::cos(st->pitch) * std::cos(st->yaw)
360 const glm::vec3 right = glm::normalize(glm::cross(forward, glm::vec3(0.0F, 1.0F, 0.0F)));
361 const glm::vec3 up = glm::normalize(glm::cross(right, forward));
363 st->eye -= right * (dx * st->mouse_sensitivity);
364 st->eye += up * (dy * st->mouse_sensitivity); }, event_name(
name,
"mouse"));
368 processor->set_view_transform_source(
370 auto win = window_weak.lock();
373 const auto& ws = win->get_state();
374 const float aspect = (ws.current_height > 0)
375 ?
static_cast<float>(ws.current_width) /
static_cast<float>(ws.current_height)
382 const std::shared_ptr<Core::Window>&
window,
385 const std::string&
name)
387 for (
const auto& buf :
window->get_rendering_buffers()) {
388 auto rp = buf->get_render_processor();
396 const std::shared_ptr<Core::Window>&
window,
397 const std::string&
name)
399 const std::string key = make_key(
window,
name);
400 auto it = s_registry.find(key);
401 if (it == s_registry.end())
404 window->set_input_config(it->second.saved_config);
406 for (
const auto& ev : it->second.registered_events)
409 s_registry.erase(it);
#define MF_RT_ERROR(comp, ctx,...)
std::weak_ptr< Core::Window > window
std::vector< std::string > registered_events
Core::InputConfig saved_config
@ EventDispatch
Event dispatching and coordination.
@ API
MayaFlux/API Wrapper and convenience functions.
void apply_orbit_rotate(OrbitState &st, float dx, float dy)
Apply a mouse delta to azimuth and elevation.
ViewTransform compute_pan_zoom_view_transform(const PanZoom2DState &st, float aspect)
Build a ViewTransform from the current PanZoom2DState.
PanZoom2DState make_pan_zoom_state(const PanZoom2DConfig &config)
Construct a PanZoom2DState from a PanZoom2DConfig.
void apply_pan_zoom_scroll(PanZoom2DState &st, float ticks)
Zoom by multiplying the half-height, clamped to [min_zoom, max_zoom].
ViewTransform build_view_transform(const NavigationState &st, float aspect)
Build a ViewTransform from the current NavigationState without mutating it.
void apply_pan_zoom_pan(PanZoom2DState &st, float dx, float dy, float viewport_width, float viewport_height)
Pan by a pixel delta, scaled to world units by the current zoom level.
void apply_scroll(NavigationState &st, float ticks)
Dolly eye along the current forward vector.
void apply_orbit_scroll(OrbitState &st, float ticks)
Dolly the camera toward or away from the focal point.
ViewTransform compute_orbit_view_transform(const OrbitState &st, float aspect)
Build a ViewTransform from the current OrbitState.
NavigationState make_navigation_state(const NavigationConfig &config)
Construct a NavigationState from a NavigationConfig.
void apply_orbit_pan(OrbitState &st, float dx, float dy)
Pan the focal point in the camera's local right/up plane.
ViewTransform compute_view_transform(NavigationState &st, float aspect)
Compute a ViewTransform from the current NavigationState.
OrbitState make_orbit_state(const OrbitConfig &config)
Construct an OrbitState from an OrbitConfig.
void apply_mouse_delta(NavigationState &st, float dx, float dy)
Apply a mouse delta to yaw and pitch.
bool cancel_event_handler(const std::string &name)
Cancel an event handler by name.
void on_mouse_move(const std::shared_ptr< Core::Window > &window, std::function< void(double, double)> callback, std::string name)
Schedule a mouse movement handler.
void on_scroll(const std::shared_ptr< Core::Window > &window, std::function< void(double, double)> callback, std::string name)
Schedule a mouse scroll handler.
void bind_screenspace_preset(const std::shared_ptr< Core::Window > &window, const std::shared_ptr< Buffers::RenderProcessor > &processor, const Kinesis::NavigationConfig &config, const Kinesis::ScreenspaceKeyMap &key_map, const std::string &name)
Bind the screenspace navigation controller to a window and render processor.
ViewportPresetMode
Selects which navigation controller bind_viewport_preset installs.
@ PanZoom2D
Orthographic 2D pan and zoom (not yet implemented)
@ Orbit
Tumble around a focal point (not yet implemented)
@ Fly
First-person fly: WASD/QE translate, RMB drag yaw/pitch, scroll dolly, KP ortho snaps.
@ Screenspace
Perspective pan in camera's local right/up plane, scroll dolly, no rotation.
void on_mouse_pressed(const std::shared_ptr< Core::Window > &window, IO::MouseButtons button, std::function< void(double, double)> callback, std::string name)
Schedule a mouse button press handler.
void bind_viewport_preset(const std::shared_ptr< Core::Window > &window, const std::shared_ptr< Buffers::RenderProcessor > &processor, ViewportPresetMode mode, const std::string &name)
Bind a navigation preset to a window and render processor using default settings.
void on_key_released(const std::shared_ptr< Core::Window > &window, IO::Keys key, std::function< void()> callback, std::string name)
Schedule a key release handler.
void bind_pan_zoom_preset(const std::shared_ptr< Core::Window > &window, const std::shared_ptr< Buffers::RenderProcessor > &processor, const Kinesis::PanZoom2DConfig &config, const Kinesis::PanZoom2DKeyMap &key_map, const std::string &name)
Bind the 2D pan/zoom controller to a window and render processor.
void on_mouse_released(const std::shared_ptr< Core::Window > &window, IO::MouseButtons button, std::function< void(double, double)> callback, std::string name)
Schedule a mouse button release handler.
void bind_orbit_preset(const std::shared_ptr< Core::Window > &window, const std::shared_ptr< Buffers::RenderProcessor > &processor, const Kinesis::OrbitConfig &config, const Kinesis::OrbitKeyMap &key_map, const std::string &name)
Bind the orbit navigation controller to a window and render processor.
void unbind_viewport_preset(const std::shared_ptr< Core::Window > &window, const std::string &name)
Cancel all event handlers registered by bind_viewport_preset() and restore the window input config to...
void on_key_pressed(const std::shared_ptr< Core::Window > &window, IO::Keys key, std::function< void()> callback, std::string name)
Schedule a key press handler.
void bind_fly_preset(const std::shared_ptr< Core::Window > &window, const std::shared_ptr< Buffers::RenderProcessor > &processor, const ViewportPresetConfig &config, const Kinesis::FlyKeyMap &key_map, const std::string &name)
Bind the fly navigation controller to a window and render processor.
Main namespace for the Maya Flux audio engine.
std::optional< IO::Keys > ortho_top
Snap to top (+Y) view.
std::optional< IO::Keys > ortho_right
Snap to right (+X) view.
std::optional< IO::Keys > ortho_flip
Flip to opposite view.
std::optional< IO::Keys > ortho_front
Snap to front (+Z) view.
Key assignments for the Fly navigation preset.
Tuning parameters for a first-person fly-navigation controller.
Construction parameters for an orbit navigation controller.
std::optional< IO::Keys > ortho_right
IO::Keys pan_modifier
Held during MMB drag to pan instead of rotate.
std::optional< IO::Keys > ortho_flip
std::optional< IO::Keys > ortho_front
std::optional< IO::Keys > ortho_top
Key assignments for the Orbit navigation preset.
Construction parameters for a 2D pan/zoom orthographic controller.
IO::MouseButtons drag_button
Button held to pan.
Input assignments for the PanZoom2D navigation preset.
IO::MouseButtons drag_button
Button held to pan.
Input assignments for the Screenspace navigation preset.