MayaFlux 0.3.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
Windowing.cpp
Go to the documentation of this file.
1// Windowing.cpp
2#include "Windowing.hpp"
3
4#include "Core.hpp"
7
8#include <glm/vec2.hpp>
9#include <glm/vec3.hpp>
10
11namespace MayaFlux {
12
17
18std::shared_ptr<Core::Window> create_window(const Core::WindowCreateInfo& create_info)
19{
20 return get_window_manager().create_window(create_info);
21}
22
23glm::vec3 normalize_coords(double window_x, double window_y,
24 uint32_t window_width, uint32_t window_height)
25{
26 float norm_x = (static_cast<float>(window_x) / static_cast<float>(window_width)) * 2.0F - 1.0F;
27 float norm_y = 1.F - (static_cast<float>(window_y) / static_cast<float>(window_height)) * 2.0F;
28 return { norm_x, norm_y, 0.0F };
29}
30
31glm::vec3 normalize_coords(double window_x, double window_y,
32 const std::shared_ptr<Core::Window>& window)
33{
34 const auto& state = window->get_state();
35 return normalize_coords(window_x, window_y, state.current_width, state.current_height);
36}
37
38glm::vec2 window_coords(double ndc_x, double ndc_y, double ndc_z,
39 uint32_t window_width, uint32_t window_height)
40{
41 (void)ndc_z;
42 float window_x = (static_cast<float>(ndc_x) + 1.0F) * 0.5F * static_cast<float>(window_width);
43 float window_y = (1.0F - static_cast<float>(ndc_y)) * 0.5F * static_cast<float>(window_height);
44 return { window_x, window_y };
45}
46
47glm::vec2 window_coords(double ndc_x, double ndc_y, double ndc_z,
48 const std::shared_ptr<Core::Window>& window)
49{
50 const auto& state = window->get_state();
51 return window_coords(ndc_x, ndc_y, ndc_z, state.current_width, state.current_height);
52}
53
54glm::vec2 window_coords(const glm::vec3& ndc_pos,
55 uint32_t window_width, uint32_t window_height)
56{
57 return window_coords(ndc_pos.x, ndc_pos.y, ndc_pos.z, window_width, window_height);
58}
59
60glm::vec2 window_coords(const glm::vec3& ndc_pos,
61 const std::shared_ptr<Core::Window>& window)
62{
63 const auto& state = window->get_state();
64 return window_coords(ndc_pos.x, ndc_pos.y, ndc_pos.z, state.current_width, state.current_height);
65}
66
67float aspect_ratio(uint32_t window_width, uint32_t window_height)
68{
69 return static_cast<float>(window_width) / static_cast<float>(window_height);
70}
71
72float aspect_ratio(const std::shared_ptr<Core::Window>& window)
73{
74 const auto& state = window->get_state();
75 return aspect_ratio(state.current_width, state.current_height);
76}
77
78glm::vec3 normalize_coords_aspect(double window_x, double window_y,
79 uint32_t window_width, uint32_t window_height)
80{
81 float aspect = aspect_ratio(window_width, window_height);
82 float norm_x = (static_cast<float>(window_x) / static_cast<float>(window_width)) * 2.0F - 1.0F;
83 float norm_y = 1.0F - (static_cast<float>(window_y) / static_cast<float>(window_height)) * 2.0F;
84
85 if (aspect > 1.0F) {
86 norm_y /= aspect;
87 } else {
88 norm_x *= aspect;
89 }
90
91 return { norm_x, norm_y, 0.0F };
92}
93
94glm::vec3 normalize_coords_aspect(double window_x, double window_y,
95 const std::shared_ptr<Core::Window>& window)
96{
97 const auto& state = window->get_state();
98 return normalize_coords_aspect(window_x, window_y, state.current_width, state.current_height);
99}
100
101bool is_in_bounds(double window_x, double window_y,
102 uint32_t window_width, uint32_t window_height)
103{
104 return window_x >= 0.0 && window_x < static_cast<double>(window_width) && window_y >= 0.0 && window_y < static_cast<double>(window_height);
105}
106
107bool is_in_bounds(double window_x, double window_y,
108 const std::shared_ptr<Core::Window>& window)
109{
110 const auto& state = window->get_state();
111 return is_in_bounds(window_x, window_y, state.current_width, state.current_height);
112}
113
114}
Core engine lifecycle and configuration API.
std::shared_ptr< WindowManager > get_window_manager()
Gets the window manager.
Definition Engine.hpp:276
std::shared_ptr< Window > create_window(const WindowCreateInfo &create_info)
Creates a new window.
Manages window lifecycle and GLFW event polling.
std::shared_ptr< Core::Window > create_window(const Core::WindowCreateInfo &create_info)
Create a new window with specified parameters.
Definition Windowing.cpp:18
glm::vec2 window_coords(double ndc_x, double ndc_y, double ndc_z, uint32_t window_width, uint32_t window_height)
Convert NDC coordinates to window pixel coordinates.
Definition Windowing.cpp:38
bool is_in_bounds(double window_x, double window_y, uint32_t window_width, uint32_t window_height)
Check if a point in window coordinates is inside the window bounds.
glm::vec3 normalize_coords(double window_x, double window_y, uint32_t window_width, uint32_t window_height)
Convert window pixel coordinates to normalized device coordinates (NDC)
Definition Windowing.cpp:23
Core::Engine & get_context()
Gets the default engine instance.
Definition Core.cpp:58
glm::vec3 normalize_coords_aspect(double window_x, double window_y, uint32_t window_width, uint32_t window_height)
Normalize coordinates preserving aspect ratio (useful for circular/square shapes)
Definition Windowing.cpp:78
float aspect_ratio(uint32_t window_width, uint32_t window_height)
Get window aspect ratio (width/height)
Definition Windowing.cpp:67
Core::WindowManager & get_window_manager()
Gets a handle to default window manager.
Definition Windowing.cpp:13
Main namespace for the Maya Flux audio engine.
Definition LiveAid.hpp:6
Configuration for creating a single window instance.