2024-06-12 23:05:45 -04:00
|
|
|
/**
|
|
|
|
* @typedef {Object} Vector3 A representation of a position in 3D space
|
2024-06-13 01:08:44 -04:00
|
|
|
* @property {Float32} f32 x coordinate
|
|
|
|
* @property {Float32} f32 y coordinate
|
|
|
|
* @property {Float32} f32 z coordinate
|
2024-06-12 23:05:45 -04:00
|
|
|
*/
|
2024-06-02 09:42:35 -04:00
|
|
|
class Vector3 {
|
|
|
|
/**
|
|
|
|
* x coordinate
|
2024-06-12 23:05:45 -04:00
|
|
|
* @return {Float32} gets the value of x
|
2024-06-02 09:42:35 -04:00
|
|
|
*/
|
|
|
|
get x() {
|
|
|
|
return this._data.getFloat32(0, true);
|
|
|
|
}
|
2024-06-12 23:05:45 -04:00
|
|
|
/**
|
|
|
|
* x coordinate
|
|
|
|
* @param {Float32} sets the value of x
|
|
|
|
*/
|
2024-06-02 09:42:35 -04:00
|
|
|
set x(v) {
|
|
|
|
return this._data.setFloat32(0, v, true);
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* y coordinate
|
2024-06-12 23:05:45 -04:00
|
|
|
* @return {Float32} gets the value of y
|
2024-06-02 09:42:35 -04:00
|
|
|
*/
|
|
|
|
get y() {
|
|
|
|
return this._data.getFloat32(4, true);
|
|
|
|
}
|
2024-06-12 23:05:45 -04:00
|
|
|
/**
|
|
|
|
* y coordinate
|
|
|
|
* @param {Float32} sets the value of y
|
|
|
|
*/
|
2024-06-02 09:42:35 -04:00
|
|
|
set y(v) {
|
|
|
|
return this._data.setFloat32(4, v, true);
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* z coordinate
|
2024-06-12 23:05:45 -04:00
|
|
|
* @return {Float32} gets the value of z
|
2024-06-02 09:42:35 -04:00
|
|
|
*/
|
|
|
|
get z() {
|
|
|
|
return this._data.getFloat32(8, true);
|
|
|
|
}
|
2024-06-12 23:05:45 -04:00
|
|
|
/**
|
|
|
|
* z coordinate
|
|
|
|
* @param {Float32} sets the value of z
|
|
|
|
*/
|
2024-06-02 09:42:35 -04:00
|
|
|
set z(v) {
|
|
|
|
return this._data.setFloat32(8, v, true);
|
|
|
|
}
|
|
|
|
/**
|
2024-06-12 23:05:45 -04:00
|
|
|
* Constructs a new Vector3
|
|
|
|
*
|
|
|
|
* @param {{x: Float32, y: Float32, z: Float32, }} init The arguments to construct the object.
|
2024-06-13 01:08:44 -04:00
|
|
|
* @param {Uint8Array} ptr The pointer to the C struct.
|
2024-06-02 09:42:35 -04:00
|
|
|
*/
|
|
|
|
constructor(init = {}, ptr = undefined) {
|
|
|
|
this._size = 12;
|
2024-06-13 01:08:44 -04:00
|
|
|
this._ptr = ptr || new Uint8Array(this._size);
|
|
|
|
this._data = new DataView(this._ptr.buffer);
|
2024-06-02 09:42:35 -04:00
|
|
|
|
|
|
|
for (const key of Object.keys(init)) {
|
|
|
|
this[key] = init[key];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default Vector3
|