avocado-old/packages/physics/body-view.js
2019-04-20 02:15:04 -05:00

44 lines
949 B
JavaScript

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();
this.redraw();
}
get internal() {
return this.primitives.internal;
}
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,
Primitives.lineStyle(new Color(255, 255, 0), 1),
);
}
lastVertice = vertice;
}
primitives.drawLine(
lastVertice,
firstVertice,
Primitives.lineStyle(new Color(255, 255, 0), 1),
);
}
}