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

◆ stroke_samples()

void MayaFlux::Kinesis::stroke_samples ( std::span< float >  samples,
std::optional< size_t > &  previous,
float  position,
float  level 
)
inlinenoexcept

Write a level into an evenly spaced sample array at a fractional position, filling linearly from the previously written index.

position in [0, 1] selects the index (0 is the first sample, 1 the last). level is clamped to [0, 1]. When previous holds a different valid index, every sample between that index and the new one is set on the line from the value last stored at previous to level, in either direction, so a fast gesture leaves no gaps. previous is updated to the index just written; reset it to clear the gesture.

A NaN position selects the first sample; infinite positions clamp to the nearest end. An empty array is untouched.

Parameters
samplesSamples to write into.
previousIndex written by the previous call of this gesture.
positionFractional position in [0, 1].
levelLevel in [0, 1].

Definition at line 24 of file Stroke.hpp.

29{
30 if (samples.empty())
31 return;
32
33 if (std::isnan(position))
34 position = 0.F;
35
36 const size_t last = samples.size() - 1;
37 const size_t index = static_cast<size_t>(std::clamp(position, 0.F, 1.F) * static_cast<float>(last));
38 const float target = std::clamp(level, 0.F, 1.F);
39
40 if (previous && *previous != index && *previous <= last) {
41 const size_t from = *previous;
42 const float start = samples[from];
43 const size_t lo = std::min(from, index);
44 const size_t hi = std::max(from, index);
45 const auto run = static_cast<float>(hi - lo);
46
47 for (size_t i = lo; i <= hi; ++i) {
48 const size_t travelled = i > from ? i - from : from - i;
49 const float fraction = static_cast<float>(travelled) / run;
50 samples[i] = start + (target - start) * fraction;
51 }
52 } else {
53 samples[index] = target;
54 }
55
56 previous = index;
57}
std::optional< glm::vec3 > position
Definition Decoder.cpp:93
uint32_t index
Definition VKDevice.cpp:122
void run()
Definition main.cpp:21

References index, position, and run().

Referenced by MayaFlux::Portal::Forma::Geometry::wire_canvas_drag().

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