Estella 0.113.0
A fast 2D and 3D game engine powered by WebAssembly and ECS
Loading...
Searching...
No Matches
SpringBoneSolver.hpp File Reference

The arithmetic of a spring chain, with no registry in it: Verlet integration, length constraints, collision against spheres and capsules, and the rotation that aims a bone at where its child has got to. More...

#include "../core/Types.hpp"
#include "../math/Math.hpp"
#include <vector>
Include dependency graph for SpringBoneSolver.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  esengine::springbone::Particle
 One simulated point of a chain. More...
struct  esengine::springbone::StepParams
 What shapes one step. More...
struct  esengine::springbone::Collider
 A collider in world space: a sphere when a == b, else a capsule from a to b. More...

Namespaces

namespace  esengine
namespace  esengine::springbone

Functions

f32 esengine::springbone::gustFactor (f32 time, f32 frequency, f32 gust, i32 index)
 The factor gusts put on the wind's strength for a particle at a moment: a travelling wave down the chain, so the strand ripples instead of swaying as one.
void esengine::springbone::reset (std::vector< Particle > &chain)
 Sets every particle to rest at its target: the state a chain starts in and the one it is put back in after a teleport.
void esengine::springbone::step (std::vector< Particle > &chain, const StepParams &params, const std::vector< Collider > &colliders, f32 dt)
 Advances the chain by dt seconds.
glm::quat esengine::springbone::shortestArc (const glm::vec3 &from, const glm::vec3 &to)
 The shortest rotation that turns direction from onto direction to; identity when either has no length.
bool esengine::springbone::pushOut (glm::vec3 &p, const Collider &c, f32 extra)
 Moves p out of c if it is inside (radius widened by extra), returning whether it moved.

Variables

constexpr f32 esengine::springbone::kReferenceStep = 1.0f / 60.0f
 The rate the integration is stepped at: the stiffness and drag are per frame of this.
constexpr f32 esengine::springbone::kMaxStep = 1.0f / 20.0f
 Longest stretch of time one call integrates; a stall must not become a lurch.

Detailed Description

The arithmetic of a spring chain, with no registry in it: Verlet integration, length constraints, collision against spheres and capsules, and the rotation that aims a bone at where its child has got to.

Everything is over plain arrays and plain structs so the same code is exercised by a unit test, by the editor's world, and by a build with no JIT. A chain is a tree stored parents-first: a node's parent always has a smaller index.

Definition in file SpringBoneSolver.hpp.