@fivem-ts/shared
Version:
FiveM Typescript wrapper shared part
94 lines (93 loc) • 3.22 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Vector4 = void 0;
const Vector_1 = require("./Vector");
class Vector4 extends Vector_1.Vector {
constructor(x, y, _z, _h) {
super(x, y);
this._z = _z;
this._h = _h;
}
get z() {
return this._z;
}
set z(value) {
this._z = value;
}
get h() {
return this._h;
}
set h(value) {
this._h = value;
}
get Length() {
return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z + this.h * this.h);
}
get normalize() {
const length = this.Length;
if (length === 0)
return new Vector4(0, 0, 0, 0);
const normalizedX = this.x / length;
const normalizedY = this.y / length;
const normalizedZ = this.z / length;
const normalizedH = this.h / length;
return new Vector4(normalizedX, normalizedY, normalizedZ, normalizedH);
}
clone() {
return new Vector4(this.x, this.y, this.z, this.h);
}
distanceSquared(vector) {
const dx = this.x - vector.x;
const dy = this.y - vector.y;
const dz = this.z - vector.z;
const dh = this.h - vector.h;
return dx * dx + dy * dy + dz * dz + dh * dh;
}
distance(vector) {
const dx = this.x - vector.x;
const dy = this.y - vector.y;
const dz = this.z - vector.z;
const dh = this.h - vector.h;
return Math.sqrt(dx * dx + dy * dy + dz * dz + dh * dh);
}
crossProduct(vector) {
const x = this.y * vector.z - this.z * vector.y;
const y = this.z * vector.x - this.x * vector.z;
const z = this.x * vector.y - this.y * vector.x;
return new Vector4(x, y, z, 0);
}
dotProduct(vector) {
return this.x * vector.x + this.y * vector.y + this.z * vector.z + this.h * vector.h;
}
add(vector) {
if (typeof vector === 'number') {
return new Vector4(this.x + vector, this.y + vector, this.z + vector, this.h + vector);
}
return new Vector4(this.x + vector.x, this.y + vector.y, this.z + vector.z, this.h + vector.h);
}
subtract(vector) {
if (typeof vector === 'number') {
return new Vector4(this.x - vector, this.y - vector, this.z - vector, this.h - vector);
}
return new Vector4(this.x - vector.x, this.y - vector.y, this.z - vector.z, this.h - vector.h);
}
multiply(vector) {
if (typeof vector === 'number') {
return new Vector4(this.x * vector, this.y * vector, this.z * vector, this.h * vector);
}
return new Vector4(this.x * vector.x, this.y * vector.y, this.z * vector.z, this.h * vector.h);
}
divide(vector) {
if (typeof vector === 'number') {
return new Vector4(this.x / vector, this.y / vector, this.z / vector, this.h / vector);
}
return new Vector4(this.x / vector.x, this.y / vector.y, this.z / vector.z, this.h / vector.h);
}
replace(vector) {
this.x = vector.x;
this.y = vector.y;
this.z = vector.z;
this.h = vector.h;
}
}
exports.Vector4 = Vector4;