21 std::unordered_map<std::string, PresetRecord> s_registry;
23 std::string make_key(
const std::shared_ptr<Core::Window>& window,
const std::string& name)
25 return std::to_string(
reinterpret_cast<uintptr_t
>(window.get())) +
"_" + name;
28 std::string event_name(
const std::string& prefix,
const char* suffix)
30 return "vp_" + prefix +
"_" + suffix;
36 const std::shared_ptr<Core::Window>& window,
37 const std::shared_ptr<Buffers::RenderProcessor>& processor,
40 const std::string& name)
44 "ViewportPresetMode {} is not yet implemented",
45 static_cast<int>(mode));
49 auto& record = s_registry[make_key(window, name)];
50 record.saved_config = window->get_input_config();
51 record.registered_events.clear();
53 auto st = std::make_shared<Kinesis::NavigationState>(
58 st->first_mouse =
true; }, event_name(name,
"rmb_dn"));
77 st->first_mouse = true;
80 if (st->first_mouse) {
83 st->first_mouse = false;
87 static_cast<float>(x - st->last_x),
88 static_cast<float>(y - st->last_y));
90 st->last_y = y; }, event_name(name,
"mouse"));
99 processor->set_view_transform_source(
101 auto win = window_weak.lock();
105 const auto& ws = win->get_state();
106 const float aspect = (ws.current_height > 0)
107 ?
static_cast<float>(ws.current_width) /
static_cast<float>(ws.current_height)
114 const std::shared_ptr<Core::Window>& window,
117 const std::string& name)
119 for (
const auto& buf : window->get_rendering_buffers()) {
120 auto rp = buf->get_render_processor();
129 const std::shared_ptr<Core::Window>& window,
130 const std::string& name)
132 const std::string key = make_key(window, name);
133 auto it = s_registry.find(key);
134 if (it == s_registry.end()) {
138 s_registry.erase(it);
140 window->set_input_config(saved);
142 static const char*
const k_suffixes[] = {
143 "w_dn",
"w_up",
"s_dn",
"s_up",
144 "a_dn",
"a_up",
"d_dn",
"d_up",
145 "q_dn",
"q_up",
"e_dn",
"e_up",
148 "kp1",
"kp3",
"kp7",
"kp9"
151 for (
const auto& ev : it->second.registered_events) {
#define MF_RT_ERROR(comp, ctx,...)
std::vector< std::string > registered_events
Core::InputConfig saved_config
@ EventDispatch
Event dispatching and coordination.
@ API
MayaFlux/API Wrapper and convenience functions.
NavigationState make_navigation_state(const NavigationConfig &config)
Construct a NavigationState from a NavigationConfig.
void apply_mouse_delta(NavigationState &st, float dx, float dy)
Apply a mouse delta to yaw and pitch.
void apply_scroll(NavigationState &st, float ticks)
Dolly eye along the current forward vector.
ViewTransform compute_view_transform(NavigationState &st, float aspect)
Compute a ViewTransform from the current NavigationState.
void snap_ortho(NavigationState &st, int view)
Snap to a named ortho view.
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.
ViewportPresetMode
Selects which navigation controller bind_viewport_preset installs.
@ Fly
First-person fly: WASD/QE translate, RMB drag yaw/pitch, scroll dolly, KP ortho snaps.
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 ViewportPresetConfig &config, const std::string &name)
Bind a navigation preset to a window and render processor.
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 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 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.
Main namespace for the Maya Flux audio engine.
Tuning parameters for a first-person fly-navigation controller.