import * as Vec2 from 'model/vec2' interface AccParams { dt: number, speed: Vec2.Vec2, dir: Vec2.Vec2 } // max_acc = v_length(board_size) / 90000 const maxAcc: number = 0.04 const inertia: number = 200 export function acc({ dt, speed, dir }: AccParams): Vec2.Vec2 { const v = Vec2.applyOnLength((x) => x * maxAcc, dir) return Vec2.div(Vec2.sub(Vec2.scale(v, dt), speed), inertia) } interface SpeedParams { dt: number, acc: Vec2.Vec2, speed: Vec2.Vec2 } export function speed({ dt, acc, speed }: SpeedParams): Vec2.Vec2 { return Vec2.add(Vec2.scale(acc, dt), speed) } interface PosParams { dt: number, acc: Vec2.Vec2, speed: Vec2.Vec2, pos: Vec2.Vec2 } export function pos({ dt, acc, speed, pos }: PosParams): Vec2.Vec2 { return Vec2.add( Vec2.scale(acc, (dt ** 2) / 2), Vec2.add(Vec2.scale(speed, dt), pos) ) }