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

◆ axis_fraction()

std::function< float(glm::vec2)> MayaFlux::Kinesis::axis_fraction ( AABB2D  bounds,
float  handle_extent = 0.F,
bool  horizontal = true 
)
inlinenoexcept

Fraction along one axis of bounds, inverse to fader placement.

horizontal_fader and vertical_fader place the handle's leading edge at min + value * (extent - handle_extent), so the handle centre travels a span shorter than the track by one handle. This subtracts half a handle before dividing by the reduced span, so the handle centre tracks the cursor across the whole range rather than lagging by up to half a handle at the extremes.

Pass handle_extent of zero for mappings with no handle inset, such as a level_meter used as a scrub region.

Parameters
boundsTrack region in NDC.
handle_extentHandle width for horizontal, height for vertical.
horizontalTrue to map the x axis, false for y.
Returns
Callable producing a value in [0, 1].

Definition at line 37 of file Projection.hpp.

38{
39 const float extent = horizontal ? bounds.width() : bounds.height();
40 const float span = extent - handle_extent;
41 const float origin = horizontal ? bounds.min.x : bounds.min.y;
42 const float half = handle_extent * 0.5F;
43
44 return [origin, half, span, horizontal](glm::vec2 p) -> float {
45 if (span <= 0.F)
46 return 0.F;
47 const float pos = horizontal ? p.x : p.y;
48 return std::clamp((pos - origin - half) / span, 0.F, 1.F);
49 };
50}
float height() const noexcept
Definition Bounds.hpp:38
float width() const noexcept
Definition Bounds.hpp:37

References MayaFlux::Kinesis::AABB2D::height(), MayaFlux::Kinesis::AABB2D::min, and MayaFlux::Kinesis::AABB2D::width().

Referenced by MayaFlux::Portal::Forma::Geometry::horizontal_fader(), and MayaFlux::Portal::Forma::Geometry::vertical_fader().

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