31 lines
926 B
TypeScript
31 lines
926 B
TypeScript
import { DELTA_RATIO, VELOCITY_RATIO } from './constants'
|
|
import { IDelta, IMovable, IPosition } from './types'
|
|
|
|
export function longToNumber(arr: number[]) {
|
|
return arr[1] + 4294967296 * arr[0]
|
|
}
|
|
|
|
export function round(val: number, precision: number = 1) {
|
|
const pow = Math.pow(10, precision)
|
|
return Math.round((val + Number.EPSILON) * pow) / pow
|
|
}
|
|
|
|
export function dist2(from: IPosition, to: IPosition) {
|
|
const x = from.x - to.x
|
|
const y = from.y - to.y
|
|
const z = from.z - to.z
|
|
return (x * x) + (y * y) + (z * z)
|
|
}
|
|
|
|
export function applyVelocity(movable: IMovable) {
|
|
movable.x += (movable.velocityX / VELOCITY_RATIO)
|
|
movable.y += (movable.velocityY / VELOCITY_RATIO)
|
|
movable.z += (movable.velocityZ / VELOCITY_RATIO)
|
|
}
|
|
|
|
export function applyDelta(movable: IMovable, delta: IDelta) {
|
|
movable.x += (delta.dX / DELTA_RATIO)
|
|
movable.y += (delta.dY / DELTA_RATIO)
|
|
movable.z += (delta.dZ / DELTA_RATIO)
|
|
}
|