Grabbed dndbeyond's source code
``` ~/go/bin/sourcemapper -output ddb -jsurl https://media.dndbeyond.com/character-app/static/js/main.90aa78c5.js ```
This commit is contained in:
+34
@@ -0,0 +1,34 @@
|
||||
"use strict";
|
||||
|
||||
exports.__esModule = true;
|
||||
exports["default"] = stepper;
|
||||
// stepper is used a lot. Saves allocation to return the same array wrapper.
|
||||
// This is fine and danger-free against mutations because the callsite
|
||||
// immediately destructures it and gets the numbers inside without passing the
|
||||
// array reference around.
|
||||
var reusedTuple = [0, 0];
|
||||
|
||||
function stepper(secondPerFrame, x, v, destX, k, b, precision) {
|
||||
// Spring stiffness, in kg / s^2
|
||||
// for animations, destX is really spring length (spring at rest). initial
|
||||
// position is considered as the stretched/compressed position of a spring
|
||||
var Fspring = -k * (x - destX); // Damping, in kg / s
|
||||
|
||||
var Fdamper = -b * v; // usually we put mass here, but for animation purposes, specifying mass is a
|
||||
// bit redundant. you could simply adjust k and b accordingly
|
||||
// let a = (Fspring + Fdamper) / mass;
|
||||
|
||||
var a = Fspring + Fdamper;
|
||||
var newV = v + a * secondPerFrame;
|
||||
var newX = x + newV * secondPerFrame;
|
||||
|
||||
if (Math.abs(newV) < precision && Math.abs(newX - destX) < precision) {
|
||||
reusedTuple[0] = destX;
|
||||
reusedTuple[1] = 0;
|
||||
return reusedTuple;
|
||||
}
|
||||
|
||||
reusedTuple[0] = newX;
|
||||
reusedTuple[1] = newV;
|
||||
return reusedTuple;
|
||||
}
|
||||
Reference in New Issue
Block a user