refactor: BodyView renders vertices not aabb
This commit is contained in:
parent
62ff586777
commit
ae95193805
|
@ -7,27 +7,36 @@ export class BodyView extends Renderable {
|
|||
super();
|
||||
this.body = body;
|
||||
this.primitives = new Primitives();
|
||||
this.redrawAabb();
|
||||
this.redraw();
|
||||
}
|
||||
|
||||
get internal() {
|
||||
return this.primitives.internal;
|
||||
}
|
||||
|
||||
redrawAabb() {
|
||||
const aabb = this.body.aabb;
|
||||
this.primitives.clear();
|
||||
const xMiddle = aabb[0] + (aabb[2] / 2);
|
||||
this.primitives.drawLine(
|
||||
[xMiddle, aabb[1]],
|
||||
[xMiddle, aabb[1] + (aabb[3] - 0.0001)],
|
||||
Primitives.lineStyle(new Color(255, 255, 0), 0.5)
|
||||
);
|
||||
const yMiddle = aabb[1] + (aabb[3] / 2);
|
||||
this.primitives.drawLine(
|
||||
[aabb[0], yMiddle],
|
||||
[aabb[0] + (aabb[2] -0.0001), yMiddle],
|
||||
Primitives.lineStyle(new Color(255, 255, 0), 0.5)
|
||||
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), 0.5),
|
||||
);
|
||||
}
|
||||
lastVertice = vertice;
|
||||
}
|
||||
primitives.drawLine(
|
||||
lastVertice,
|
||||
firstVertice,
|
||||
Primitives.lineStyle(new Color(255, 255, 0), 0.5),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user