MayaFlux 0.4.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ bind_screenspace_preset() [2/2]

MAYAFLUX_API void MayaFlux::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 = "default" 
)

Bind the screenspace navigation controller to a window and render processor.

Drag translates the eye along the camera's local right and up axes derived from the current yaw and pitch. Rotation is never modified. Scroll dollies along the forward vector. Perspective projection is preserved throughout.

To set the initial viewing direction, supply a NavigationConfig with initial_eye and initial_target; yaw and pitch are derived from those on construction exactly as in bind_fly_preset.

Parameters
windowWindow supplying input events
processorRenderProcessor that receives the ViewTransform source
configCamera tuning parameters; move_speed is unused
key_mapInput assignments; defaults to RMB drag
nameUnique prefix for registered events; must be unique per window

Definition at line 318 of file ViewportPreset.cpp.

324{
325 auto& record = s_registry[make_key(window, name)];
326 record.saved_config = window->get_input_config();
327 record.registered_events.clear();
328
329 auto st = std::make_shared<Kinesis::NavigationState>(
330 Kinesis::make_navigation_state(config));
331
332 on_mouse_pressed(window, key_map.drag_button, [st](double /*x*/, double /*y*/) {
333 st->rmb_held = true;
334 st->first_mouse = true; }, event_name(name, "drag_dn"));
335
336 on_mouse_released(window, key_map.drag_button, [st](double /*x*/, double /*y*/) { st->rmb_held = false; }, event_name(name, "drag_up"));
337
338 on_mouse_move(window, [st](double x, double y) {
339 if (!st->rmb_held) {
340 st->first_mouse = true;
341 return;
342 }
343 if (st->first_mouse) {
344 st->last_x = x;
345 st->last_y = y;
346 st->first_mouse = false;
347 return;
348 }
349 const auto dx = static_cast<float>(x - st->last_x);
350 const auto dy = static_cast<float>(y - st->last_y);
351 st->last_x = x;
352 st->last_y = y;
353
354 const glm::vec3 forward {
355 std::cos(st->pitch) * std::sin(st->yaw),
356 std::sin(st->pitch),
357 std::cos(st->pitch) * std::cos(st->yaw)
358 };
359 const glm::vec3 right = glm::normalize(glm::cross(forward, glm::vec3(0.0F, 1.0F, 0.0F)));
360 const glm::vec3 up = glm::normalize(glm::cross(right, forward));
361
362 st->eye -= right * (dx * st->mouse_sensitivity);
363 st->eye += up * (dy * st->mouse_sensitivity); }, event_name(name, "mouse"));
364
365 on_scroll(window, [st](double /*dx*/, double dy) { Kinesis::apply_scroll(*st, static_cast<float>(dy)); }, event_name(name, "scroll"));
366
367 processor->set_view_transform_source(
368 [st, window_weak = std::weak_ptr<Core::Window>(window)]() -> Kinesis::ViewTransform {
369 auto win = window_weak.lock();
370 if (!win)
371 return {};
372 const auto& ws = win->get_state();
373 const float aspect = (ws.current_height > 0)
374 ? static_cast<float>(ws.current_width) / static_cast<float>(ws.current_height)
375 : 1.0F;
376 return Kinesis::build_view_transform(*st, aspect);
377 });
378}
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.
Definition Chronie.cpp:217
void on_scroll(const std::shared_ptr< Core::Window > &window, std::function< void(double, double)> callback, std::string name)
Schedule a mouse scroll handler.
Definition Chronie.cpp:250
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.
Definition Chronie.cpp:183
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.
Definition Chronie.cpp:200
IO::MouseButtons drag_button
Button held to pan.

References MayaFlux::Kinesis::apply_scroll(), MayaFlux::Kinesis::build_view_transform(), MayaFlux::Kinesis::ScreenspaceKeyMap::drag_button, MayaFlux::Kinesis::make_navigation_state(), on_mouse_move(), on_mouse_pressed(), on_mouse_released(), and on_scroll().

Referenced by bind_screenspace_preset(), and bind_viewport_preset().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: