ts-game-engine
Version:
Simple WebGL game/render engine written in TypeScript
42 lines (41 loc) • 1.71 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const gl_matrix_1 = require("gl-matrix");
class BoundingBox {
constructor() {
this.min = gl_matrix_1.vec3.create();
this.max = gl_matrix_1.vec3.create();
}
GetPoints() {
let p1 = gl_matrix_1.vec3.fromValues(this.min[0], this.min[1], this.min[2]);
let p2 = gl_matrix_1.vec3.fromValues(this.max[0], this.min[1], this.min[2]);
let p3 = gl_matrix_1.vec3.fromValues(this.min[0], this.min[1], this.max[2]);
let p4 = gl_matrix_1.vec3.fromValues(this.max[0], this.min[1], this.max[2]);
let p5 = gl_matrix_1.vec3.fromValues(this.min[0], this.max[1], this.min[2]);
let p6 = gl_matrix_1.vec3.fromValues(this.max[0], this.max[1], this.min[2]);
let p7 = gl_matrix_1.vec3.fromValues(this.min[0], this.max[1], this.max[2]);
let p8 = gl_matrix_1.vec3.fromValues(this.max[0], this.max[1], this.max[2]);
return [p1, p2, p3, p4, p5, p6, p7, p8];
}
GetPositiveVertexFromPlane(plane) {
let p = gl_matrix_1.vec3.clone(this.min);
if (plane.Normal[0] >= 0)
p[0] = this.max[0];
if (plane.Normal[1] >= 0)
p[1] = this.max[1];
if (plane.Normal[2] >= 0)
p[2] = this.max[2];
return p;
}
GetNegativeVertexFromPlane(plane) {
let n = gl_matrix_1.vec3.clone(this.max);
if (plane.Normal[0] >= 0)
n[0] = this.min[0];
if (plane.Normal[1] >= 0)
n[1] = this.min[1];
if (plane.Normal[2] >= 0)
n[2] = this.min[2];
return n;
}
}
exports.BoundingBox = BoundingBox;