MayaFlux 1.0.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 319 of file ViewportPreset.cpp.

325{
326 auto& record = s_registry[make_key(window, name)];
327 record.saved_config = window->get_input_config();
328 record.registered_events.clear();
329
330 auto st = std::make_shared<Kinesis::NavigationState>(
331 Kinesis::make_navigation_state(config));
332
333 on_mouse_pressed(window, key_map.drag_button, [st](double /*x*/, double /*y*/) {
334 st->rmb_held = true;
335 st->first_mouse = true; }, event_name(name, "drag_dn"));
336
337 on_mouse_released(window, key_map.drag_button, [st](double /*x*/, double /*y*/) { st->rmb_held = false; }, event_name(name, "drag_up"));
338
339 on_mouse_move(window, [st](double x, double y) {
340 if (!st->rmb_held) {
341 st->first_mouse = true;
342 return;
343 }
344 if (st->first_mouse) {
345 st->last_x = x;
346 st->last_y = y;
347 st->first_mouse = false;
348 return;
349 }
350 const auto dx = static_cast<float>(x - st->last_x);
351 const auto dy = static_cast<float>(y - st->last_y);
352 st->last_x = x;
353 st->last_y = y;
354
355 const glm::vec3 forward {
356 std::cos(st->pitch) * std::sin(st->yaw),
357 std::sin(st->pitch),
358 std::cos(st->pitch) * std::cos(st->yaw)
359 };
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));
362
363 st->eye -= right * (dx * st->mouse_sensitivity);
364 st->eye += up * (dy * st->mouse_sensitivity); }, event_name(name, "mouse"));
365
366 on_scroll(window, [st](double /*dx*/, double dy) { Kinesis::apply_scroll(*st, static_cast<float>(dy)); }, event_name(name, "scroll"));
367
368 processor->set_view_transform_source(
369 [st, window_weak = std::weak_ptr<Core::Window>(window)]() -> Kinesis::ViewTransform {
370 auto win = window_weak.lock();
371 if (!win)
372 return {};
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)
376 : 1.0F;
377 return Kinesis::build_view_transform(*st, aspect);
378 });
379}
std::weak_ptr< Core::Window > window
Definition Picker.cpp:23
std::string name
Definition VKDevice.cpp:123
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:231
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:264
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:197
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:214
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(), name, on_mouse_move(), on_mouse_pressed(), on_mouse_released(), on_scroll(), and window.

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: