diff --git a/src/model/vector3.js b/src/model/vector3.js index e659a16..08525c3 100644 --- a/src/model/vector3.js +++ b/src/model/vector3.js @@ -77,6 +77,14 @@ export default class Vector3 { ); } + divide(scalar) { + return new Vector3( + this.x / scalar, + this.y / scalar, + this.z / scalar + ); + } + lerp(other, t) { return new Vector3( this.x + (other.x - this.x) * t, @@ -137,6 +145,25 @@ export default class Vector3 { return localPos.rotate(parentRot.negate()); } + length() { + return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z); + } + + lengthSq() { + return this.x * this.x + this.y * this.y + this.z * this.z; + } + + normalize() { + const len = this.length(); + if (len === 0) return new Vector3(0, 0, 0); + + return new Vector3( + this.x / len, + this.y / len, + this.z / len + ); + } + negate() { return new Vector3(-this.x, -this.y, -this.z); }