2017-11-24 01:00:56 +00:00
|
|
|
import {vec3} from '../tsm/vec3';
|
|
|
|
|
|
|
|
|
|
export class Vector3 extends vec3
|
|
|
|
|
{
|
2017-11-24 17:45:34 +00:00
|
|
|
static getZero(): Vector3
|
|
|
|
|
{
|
|
|
|
|
return new Vector3();
|
|
|
|
|
}
|
2017-11-24 01:00:56 +00:00
|
|
|
|
2017-11-24 17:45:34 +00:00
|
|
|
constructor(buf?: Buffer | number[], pos?: number, double?: boolean)
|
|
|
|
|
{
|
|
|
|
|
if (double === undefined)
|
|
|
|
|
{
|
|
|
|
|
double = false;
|
|
|
|
|
}
|
|
|
|
|
if (buf !== undefined && pos !== undefined && buf instanceof Buffer)
|
|
|
|
|
{
|
|
|
|
|
if (!double)
|
|
|
|
|
{
|
|
|
|
|
const x = buf.readFloatLE(pos);
|
|
|
|
|
const y = buf.readFloatLE(pos + 4);
|
|
|
|
|
const z = buf.readFloatLE(pos + 8);
|
|
|
|
|
super([x, y, z]);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
const x = buf.readDoubleLE(pos);
|
|
|
|
|
const y = buf.readDoubleLE(pos + 8);
|
|
|
|
|
const z = buf.readDoubleLE(pos + 16);
|
|
|
|
|
super([x, y, z]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (buf !== undefined && Array.isArray(buf))
|
|
|
|
|
{
|
|
|
|
|
super(buf);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
super();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
writeToBuffer(buf: Buffer, pos: number, double: boolean)
|
|
|
|
|
{
|
|
|
|
|
if (double)
|
|
|
|
|
{
|
|
|
|
|
buf.writeDoubleLE(this.x, pos);
|
|
|
|
|
buf.writeDoubleLE(this.y, pos + 8);
|
2017-11-30 04:11:59 +00:00
|
|
|
buf.writeDoubleLE(this.z, pos + 16);
|
2017-11-24 17:45:34 +00:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
buf.writeFloatLE(this.x, pos);
|
|
|
|
|
buf.writeFloatLE(this.y, pos + 4);
|
2017-11-30 04:11:59 +00:00
|
|
|
buf.writeFloatLE(this.z, pos + 8);
|
2017-11-24 17:45:34 +00:00
|
|
|
}
|
|
|
|
|
}
|
2017-11-24 01:00:56 +00:00
|
|
|
}
|