use of spacegraph.space2d.phys.fracture.PolygonFixture in project narchy by automenta.
the class PhyWall method drawBody.
private void drawBody(Body2D body, GL2 gl) {
if (body.data() instanceof PhyWindow.WallBody) {
// its rendered already via its Surface
return;
}
if (body instanceof Consumer) {
// HACK make better custom enderer interface
((Consumer) body).accept(gl);
return;
}
// boolean active = body.isActive();
boolean awake = body.isAwake();
gl.glColor4f(0.5f, 0.5f, 0.5f, awake ? 0.75f : 0.65f);
// List<PolygonFixture> generalPolygons = new FasterList<>();
for (Fixture f = body.fixtures; f != null; f = f.next) {
PolygonFixture pg = f.polygon;
if (pg != null) {
// generalPolygons.add(pg);
} else {
Shape shape = f.shape();
switch(shape.m_type) {
case POLYGON:
Draw.poly(body, gl, (PolygonShape) shape);
break;
case CIRCLE:
CircleShape circle = (CircleShape) shape;
float r = circle.radius;
v2 v = new v2();
body.getWorldPointToOut(circle.center, v);
// Point p = getPoint(v);
// int wr = (int) (r * zoom);
// g.fillOval(p.x - wr, p.y - wr, wr * 2, wr * 2);
Draw.circle(gl, v, true, r, 9);
break;
case EDGE:
EdgeShape edge = (EdgeShape) shape;
Tuple2f p1 = edge.m_vertex1;
Tuple2f p2 = edge.m_vertex2;
gl.glLineWidth(4f);
Draw.line(gl, p1.x, p1.y, p2.x, p2.y);
break;
}
}
}
// if (generalPolygons.size() != 0) {
// PolygonFixture[] polygonArray = generalPolygons.toArray(new PolygonFixture[generalPolygons.size()]);
// for (PolygonFixture poly : polygonArray) {
// int n = poly.size();
// int x[] = new int[n];
// int y[] = new int[n];
// for (int i = 0; i < n; ++i) {
// body.getWorldPointToOut(poly.get(i), v);
// Point p = getPoint(v);
// x[i] = p.x;
// y[i] = p.y;
// }
// g.fillPolygon(x, y, n);
// }
}
use of spacegraph.space2d.phys.fracture.PolygonFixture in project narchy by automenta.
the class Box2DTests method drawBody.
private void drawBody(Body2D body) {
if (body.getType() == BodyType.DYNAMIC) {
g.setColor(Color.LIGHT_GRAY);
} else {
g.setColor(Color.GRAY);
}
Tuple2f v = new Vec2();
MyList<PolygonFixture> generalPolygons = new MyList<>();
for (Fixture f = body.fixtures; f != null; f = f.next) {
PolygonFixture pg = f.polygon;
if (pg != null) {
if (!generalPolygons.contains(pg)) {
generalPolygons.add(pg);
}
} else {
Shape shape = f.shape();
switch(shape.m_type) {
case POLYGON:
PolygonShape poly = (PolygonShape) shape;
for (int i = 0; i < poly.vertices; ++i) {
body.getWorldPointToOut(poly.vertex[i], v);
Point p = getPoint(v);
x[i] = p.x;
y[i] = p.y;
}
g.fillPolygon(x, y, poly.vertices);
break;
case CIRCLE:
CircleShape circle = (CircleShape) shape;
float r = circle.radius;
body.getWorldPointToOut(circle.center, v);
Point p = getPoint(v);
int wr = (int) (r * zoom);
g.fillOval(p.x - wr, p.y - wr, wr * 2, wr * 2);
break;
case EDGE:
EdgeShape edge = (EdgeShape) shape;
Tuple2f v1 = edge.m_vertex1;
Tuple2f v2 = edge.m_vertex2;
Point p1 = getPoint(v1);
Point p2 = getPoint(v2);
g.drawLine(p1.x, p1.y, p2.x, p2.y);
break;
}
}
}
if (generalPolygons.size() != 0) {
PolygonFixture[] polygonArray = generalPolygons.toArray(new PolygonFixture[generalPolygons.size()]);
for (PolygonFixture poly : polygonArray) {
int n = poly.size();
int[] x = new int[n];
int[] y = new int[n];
for (int i = 0; i < n; ++i) {
body.getWorldPointToOut(poly.get(i), v);
Point p = getPoint(v);
x[i] = p.x;
y[i] = p.y;
}
g.fillPolygon(x, y, n);
}
}
}
Aggregations