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

◆ normalize_coords() [2/2]

MAYAFLUX_API glm::vec3 MayaFlux::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)

Parameters
window_xX coordinate in window space [0, width]
window_yY coordinate in window space [0, height] (top-left origin)
window_widthWindow width in pixels
window_heightWindow height in pixels
Returns
NDC coordinates as vec3 (x, y, 0.0) in range [-1, +1] (center origin, +Y up)

Window coordinates use top-left origin with Y increasing downward. NDC coordinates use center origin with Y increasing upward. Z is always set to 0.0 for 2D screen-space positions.

Example: normalize_coords(0, 0, 800, 600) → (-1.0, -1.0, 0.0) // top-left normalize_coords(400, 300, 800, 600) → (0.0, 0.0, 0.0) // center normalize_coords(800, 600, 800, 600) → (+1.0, +1.0, 0.0) // bottom-right

Definition at line 23 of file Windowing.cpp.

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}

Referenced by normalize_coords().

+ Here is the caller graph for this function: