49 lines
1.0 KiB
JavaScript
49 lines
1.0 KiB
JavaScript
class Vector3 {
|
|
/**
|
|
* x coordinate
|
|
*/
|
|
get x() {
|
|
return this._data.getFloat32(0, true);
|
|
}
|
|
set x(v) {
|
|
return this._data.setFloat32(0, v, true);
|
|
}
|
|
/**
|
|
* y coordinate
|
|
*/
|
|
get y() {
|
|
return this._data.getFloat32(4, true);
|
|
}
|
|
set y(v) {
|
|
return this._data.setFloat32(4, v, true);
|
|
}
|
|
/**
|
|
* z coordinate
|
|
*/
|
|
get z() {
|
|
return this._data.getFloat32(8, true);
|
|
}
|
|
set z(v) {
|
|
return this._data.setFloat32(8, v, true);
|
|
}
|
|
/**
|
|
* get the struct representation of the object
|
|
*/
|
|
get bytes() {
|
|
return new Uint8Array(this._ptr);
|
|
}
|
|
/**
|
|
* constructor
|
|
*/
|
|
constructor(init = {}, ptr = undefined) {
|
|
this._size = 12;
|
|
this._ptr = ptr.buffer || new ArrayBuffer(this._size);
|
|
this._data = new DataView(this._ptr);
|
|
|
|
for (const key of Object.keys(init)) {
|
|
this[key] = init[key];
|
|
}
|
|
}
|
|
}
|
|
|
|
export default Vector3 |