MayaFlux 0.4.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
ForceFields.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "Tendency.hpp"
4
6
8
9/**
10 * @brief Radial attraction/repulsion toward an anchor point
11 * @param anchor Target position
12 * @param strength Force magnitude scalar (positive attracts, negative repels)
13 * @return VectorField: glm::vec3 -> glm::vec3
14 *
15 * Force magnitude follows inverse square: strength / max(d², floor).
16 * Direction is normalized delta from evaluation point to anchor.
17 * Floor of 0.1 prevents singularity at the anchor position.
18 */
19inline VectorField point_attractor(const glm::vec3& anchor, float strength)
20{
21 return { .fn = [anchor, strength](const glm::vec3& p) -> glm::vec3 {
22 glm::vec3 delta = anchor - p;
23 float d = glm::length(delta);
24 if (d < 0.001F)
25 return glm::vec3(0.0F);
26 return (delta / d) * (strength / std::max(d * d, 0.1F));
27 } };
28}
29
30/**
31 * @brief Uniform random force field using Stochastic infrastructure
32 * @param strength Maximum magnitude per axis
33 * @param rng Stochastic generator instance (captured by value, caller controls seed)
34 * @return VectorField: glm::vec3 -> glm::vec3
35 *
36 * Produces a different random vector on each evaluation. Position input
37 * is ignored: the field is spatially uniform but temporally varying.
38 * For spatially coherent noise, compose with a Perlin/simplex generator.
39 */
41{
42 return { .fn = [strength, rng](const glm::vec3&) mutable -> glm::vec3 {
43 return glm::vec3(
44 rng(-1.0F, 1.0F),
45 rng(-1.0F, 1.0F),
46 rng(-1.0F, 1.0F))
47 * strength;
48 } };
49}
50
51} // namespace MayaFlux::Kinesis::ForceFields
Unified generative infrastructure for stochastic and procedural algorithms.
VectorField turbulence(float strength, Stochastic::Stochastic rng=Stochastic::Stochastic())
Uniform random force field using Stochastic infrastructure.
VectorField point_attractor(const glm::vec3 &anchor, float strength)
Radial attraction/repulsion toward an anchor point.
std::function< R(const D &)> fn
Definition Tendency.hpp:23
Typed, composable, stateless callable from domain D to range R.
Definition Tendency.hpp:22