2019-03-24 18:58:32 -05:00
|
|
|
import {Color, Primitives, Renderable} from '@avocado/graphics';
|
|
|
|
import {Rectangle, Vector} from '@avocado/math';
|
|
|
|
|
|
|
|
export class BodyView extends Renderable {
|
|
|
|
|
|
|
|
constructor(body) {
|
|
|
|
super();
|
|
|
|
this.body = body;
|
|
|
|
this.primitives = new Primitives();
|
2019-04-12 20:27:54 -05:00
|
|
|
this.redraw();
|
2019-03-24 18:58:32 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
get internal() {
|
|
|
|
return this.primitives.internal;
|
|
|
|
}
|
|
|
|
|
2019-04-12 20:27:54 -05:00
|
|
|
redraw() {
|
|
|
|
const primitives = this.primitives;
|
|
|
|
const vertices = this.body.vertices;
|
|
|
|
primitives.clear();
|
|
|
|
let firstVertice;
|
|
|
|
let lastVertice;
|
|
|
|
for (const vertice of vertices) {
|
|
|
|
if (!firstVertice) {
|
|
|
|
firstVertice = vertice;
|
|
|
|
}
|
|
|
|
if (lastVertice) {
|
|
|
|
primitives.drawLine(
|
|
|
|
lastVertice,
|
|
|
|
vertice,
|
2019-04-20 02:15:04 -05:00
|
|
|
Primitives.lineStyle(new Color(255, 255, 0), 1),
|
2019-04-12 20:27:54 -05:00
|
|
|
);
|
|
|
|
}
|
|
|
|
lastVertice = vertice;
|
|
|
|
}
|
|
|
|
primitives.drawLine(
|
|
|
|
lastVertice,
|
|
|
|
firstVertice,
|
2019-04-20 02:15:04 -05:00
|
|
|
Primitives.lineStyle(new Color(255, 255, 0), 1),
|
2019-03-24 18:58:32 -05:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|