From 5d9a9f37694f6bf178debf265012fd01a903bced Mon Sep 17 00:00:00 2001 From: izawartka <59137928+izawartka@users.noreply.github.com> Date: Sat, 19 Jul 2025 12:27:21 +0200 Subject: [PATCH] Updated Vector3 +Added various Vector3 methods - divide (by scalar), length, lengthSq, normalize --- src/model/vector3.js | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) 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); }