Updated Vector3

+Added various Vector3 methods - divide (by scalar), length, lengthSq, normalize
This commit is contained in:
izawartka 2025-07-19 12:27:21 +02:00
parent 87b2091333
commit 5d9a9f3769

View File

@ -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) { lerp(other, t) {
return new Vector3( return new Vector3(
this.x + (other.x - this.x) * t, this.x + (other.x - this.x) * t,
@ -137,6 +145,25 @@ export default class Vector3 {
return localPos.rotate(parentRot.negate()); 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() { negate() {
return new Vector3(-this.x, -this.y, -this.z); return new Vector3(-this.x, -this.y, -this.z);
} }