WIP
This commit is contained in:
parent
24cc572e47
commit
345e183e34
1 changed files with 614 additions and 173 deletions
61
frontend/src/scripts/physics/containers/bounding-box-base.ts
Normal file
61
frontend/src/scripts/physics/containers/bounding-box-base.ts
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
import { vec2 } from 'gl-matrix';
|
||||
import { IPrimitive } from '../../drawing/drawables/primitives/i-primitive';
|
||||
|
||||
export abstract class BoundingBoxBase {
|
||||
constructor(
|
||||
public readonly value: IPrimitive,
|
||||
protected _xMin: number,
|
||||
protected _xMax: number,
|
||||
protected _yMin: number,
|
||||
protected _yMax: number
|
||||
) {}
|
||||
|
||||
public get 0(): number {
|
||||
return this._xMin;
|
||||
}
|
||||
|
||||
public get 1(): number {
|
||||
return this._xMax;
|
||||
}
|
||||
|
||||
public get 2(): number {
|
||||
return this._yMin;
|
||||
}
|
||||
|
||||
public get 3(): number {
|
||||
return this._yMax;
|
||||
}
|
||||
|
||||
public get xMin(): number {
|
||||
return this._xMin;
|
||||
}
|
||||
|
||||
public get xMax(): number {
|
||||
return this._xMax;
|
||||
}
|
||||
|
||||
public get yMin(): number {
|
||||
return this._yMin;
|
||||
}
|
||||
|
||||
public get yMax(): number {
|
||||
return this._yMax;
|
||||
}
|
||||
|
||||
public get topLeft(): vec2 {
|
||||
return vec2.fromValues(this._xMin, this._yMax);
|
||||
}
|
||||
|
||||
public get size(): vec2 {
|
||||
return vec2.fromValues(this._xMax - this._xMin, this._yMax - this._yMin);
|
||||
}
|
||||
|
||||
public intersects(other: BoundingBoxBase): boolean {
|
||||
return (
|
||||
this._xMin < other._xMax &&
|
||||
this._xMax > other._xMin &&
|
||||
this._yMin < other._yMax &&
|
||||
this._yMax > other._yMin
|
||||
);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue