Updated Vector3
+Added various Vector3 methods - divide (by scalar), length, lengthSq, normalize
This commit is contained in:
parent
87b2091333
commit
5d9a9f3769
@ -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);
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user