MCPcopy
hub / github.com/bbycroft/llm-viz / applySpringStep

Function applySpringStep

src/llm/Camera.ts:186–200  ·  view source on GitHub ↗
(pos: Vec3, target: Vec3, vel: Vec3 | null | undefined, dt: number, config: ISpringConfig)

Source from the content-addressed store, hash-verified

184}
185
186export function applySpringStep(pos: Vec3, target: Vec3, vel: Vec3 | null | undefined, dt: number, config: ISpringConfig) {
187 // default to critically damped
188 let friction = config.friction ?? 2 * Math.sqrt(config.mass * config.tension);
189 let dtS = dt / 1000;
190 vel = vel ?? new Vec3();
191 let dist = pos.sub(target);
192 let springExtra = dist.lenSq() === 0.0 ? new Vec3() : dist.normalize().mul(config.extra ?? 0);
193 let springF = (dist.add(springExtra)).mul(-config.tension);
194 let dampF = vel.mul(-friction);
195 let accel = springF.add(dampF).mul(1.0 / config.mass);
196
197 vel = vel.add(accel.mul(dtS));
198 pos = pos.add(vel.mul(dtS));
199 return { pos, vel };
200}

Callers

nothing calls this directly

Calls 5

subMethod · 0.45
lenSqMethod · 0.45
mulMethod · 0.45
normalizeMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected