refactor: BodyView renders vertices not aabb

This commit is contained in:
cha0s 2019-04-12 20:27:54 -05:00
parent 62ff586777
commit ae95193805

View File

@ -7,27 +7,36 @@ export class BodyView extends Renderable {
super(); super();
this.body = body; this.body = body;
this.primitives = new Primitives(); this.primitives = new Primitives();
this.redrawAabb(); this.redraw();
} }
get internal() { get internal() {
return this.primitives.internal; return this.primitives.internal;
} }
redrawAabb() { redraw() {
const aabb = this.body.aabb; const primitives = this.primitives;
this.primitives.clear(); const vertices = this.body.vertices;
const xMiddle = aabb[0] + (aabb[2] / 2); primitives.clear();
this.primitives.drawLine( let firstVertice;
[xMiddle, aabb[1]], let lastVertice;
[xMiddle, aabb[1] + (aabb[3] - 0.0001)], for (const vertice of vertices) {
Primitives.lineStyle(new Color(255, 255, 0), 0.5) if (!firstVertice) {
firstVertice = vertice;
}
if (lastVertice) {
primitives.drawLine(
lastVertice,
vertice,
Primitives.lineStyle(new Color(255, 255, 0), 0.5),
); );
const yMiddle = aabb[1] + (aabb[3] / 2); }
this.primitives.drawLine( lastVertice = vertice;
[aabb[0], yMiddle], }
[aabb[0] + (aabb[2] -0.0001), yMiddle], primitives.drawLine(
Primitives.lineStyle(new Color(255, 255, 0), 0.5) lastVertice,
firstVertice,
Primitives.lineStyle(new Color(255, 255, 0), 0.5),
); );
} }