use of jcog.list.FasterList in project narchy by automenta.
the class AutoSurface method start.
@Override
public void start(@Nullable SurfaceBase parent) {
synchronized (this) {
seen.clear();
ons = new Ons();
List<Surface> l = new FasterList();
collect(obj, l, 0);
super.start(parent);
set(l);
}
}
use of jcog.list.FasterList in project narchy by automenta.
the class ShapeHull method buildHull.
public boolean buildHull(float margin) {
v3 norm = new v3();
int numSampleDirections = NUM_UNITSPHERE_POINTS;
int numPDA = shape.getNumPreferredPenetrationDirections();
if (numPDA != 0) {
for (int i = 0; i < numPDA; i++) {
shape.getPreferredPenetrationDirection(i, norm);
// return array[index];
unitSpherePoints.get(numSampleDirections).set(norm);
numSampleDirections++;
}
}
FasterList<v3> supportPoints = new FasterList<>();
MiscUtil.resize(supportPoints, NUM_UNITSPHERE_POINTS + ConvexShape.MAX_PREFERRED_PENETRATION_DIRECTIONS * 2, v3.class);
for (int i = 0; i < numSampleDirections; i++) {
// return array[index];
// return array[index];
shape.localGetSupportingVertex(unitSpherePoints.get(i), supportPoints.get(i));
}
HullDesc hd = new HullDesc();
hd.flags = HullFlags.TRIANGLES;
hd.vcount = numSampleDirections;
// #ifdef BT_USE_DOUBLE_PRECISION
// hd.mVertices = &supportPoints[0];
// hd.mVertexStride = sizeof(btVector3);
// #else
hd.vertices = supportPoints;
// hd.vertexStride = 3 * 4;
// #endif
HullLibrary hl = new HullLibrary();
HullResult hr = new HullResult();
if (!hl.createConvexHull(hd, hr)) {
return false;
}
MiscUtil.resize(vertices, hr.numOutputVertices, v3.class);
for (int i = 0; i < hr.numOutputVertices; i++) {
// return array[index];
// return array[index];
vertices.get(i).set(hr.outputVertices.get(i));
}
numIndices = hr.numIndices;
MiscUtil.resize(indices, numIndices, 0);
for (int i = 0; i < numIndices; i++) {
indices.set(i, hr.indices.get(i));
}
// free temporary hull result that we just copied
HullLibrary.releaseResult(hr);
return true;
}
use of jcog.list.FasterList in project narchy by automenta.
the class OsmSpace method compile.
protected Consumer<GL2> compile() {
List<Consumer<GL2>> draw = new FasterList();
Osm osm = id;
for (OsmWay way : osm.ways) {
Map<String, String> tags = way.tags;
String building, building_part, landuse, natural, route, highway;
if (!tags.isEmpty()) {
building = tags.get("building");
building_part = tags.get("building:part");
landuse = tags.get("landuse");
natural = tags.get("natural");
route = tags.get("route");
highway = tags.get("highway");
} else {
building = building_part = landuse = natural = route = highway = null;
}
boolean isPolygon = false;
boolean isClosed = way.isClosed();
float r, g, b, a;
float lw;
short ls;
if (building != null || building_part != null) {
r = 0f;
g = 1f;
b = 1f;
a = 1f;
lw = 1f;
ls = (short) 0xFFFF;
isPolygon = !wireframe && isClosed;
} else if ("forest".equals(landuse) || "grass".equals(landuse) || "wood".equals(natural)) {
r = 0f;
g = 1f;
b = 0f;
a = 1f;
lw = 1f;
ls = (short) 0xFFFF;
isPolygon = !wireframe && isClosed;
} else if ("water".equals(natural)) {
r = 0f;
g = 0f;
b = 1f;
a = 1f;
lw = 1f;
ls = (short) 0xFFFF;
isPolygon = !wireframe && isClosed;
} else if ("pedestrian".equals(highway)) {
r = 0f;
g = 0.5f;
b = 0f;
a = 1f;
lw = 2f;
ls = (short) 0xFFFF;
} else if ("motorway".equals(highway)) {
r = 1f;
g = 0.5f;
b = 0f;
a = 1f;
lw = 5f;
ls = (short) 0xFFFF;
} else if (highway != null) {
r = 1f;
g = 1f;
b = 1f;
a = 1f;
lw = 3f;
ls = (short) 0xFFFF;
} else if ("road".equals(route)) {
r = 1f;
g = 1f;
b = 1f;
a = 1f;
lw = 1f;
ls = (short) 0xFFFF;
} else if ("train".equals(route)) {
r = 1f;
g = 1f;
b = 1f;
a = 1f;
lw = 5f;
ls = (short) 0xF0F0;
} else {
r = 0.5f;
g = 0f;
b = 0.5f;
a = 1f;
lw = 1f;
ls = (short) 0xFFFF;
}
if (isPolygon) {
List<OsmNode> nn = way.getOsmNodes();
double[][] coord = new double[nn.size()][7];
for (int i = 0, nnSize = nn.size(); i < nnSize; i++) {
OsmNode node = nn.get(i);
double[] ci = coord[i];
project(node.geoCoordinate, ci);
ci[3] = r;
ci[4] = g;
ci[5] = b;
ci[6] = a;
}
draw.add((gl) -> {
gl.glColor4f(r * 0.5f, g * .5f, b * 0.5f, a);
gl.glLineWidth(lw);
gl.glLineStipple(1, ls);
GLU.gluTessBeginPolygon(tobj, null);
GLU.gluTessBeginContour(tobj);
for (int i = 0, nnSize = nn.size(); i < nnSize; i++) {
double[] ci = coord[i];
GLU.gluTessVertex(tobj, ci, 0, ci);
}
GLU.gluTessEndContour(tobj);
GLU.gluTessEndPolygon(tobj);
});
} else {
List<OsmNode> ways = way.getOsmNodes();
int ws = ways.size();
double[] c3 = new double[3 * ws];
for (int i = 0, waysSize = ws; i < waysSize; i++) {
project(ways.get(i).geoCoordinate, c3, i * 3);
}
draw.add((gl) -> {
gl.glColor4f(r, g, b, a);
gl.glLineWidth(lw);
gl.glLineStipple(1, ls);
gl.glBegin(GL_LINE_STRIP);
for (int i = 0; i < c3.length / 3; i++) {
gl.glVertex3dv(c3, i * 3);
}
gl.glEnd();
});
}
}
for (OsmNode node : osm.nodes) {
Map<String, String> tags = node.tags;
if (tags.isEmpty())
continue;
String highway = tags.get("highway");
String natural = tags.get("natural");
float pointSize;
float r, g, b, a;
if ("bus_stop".equals(highway)) {
pointSize = 3;
r = g = b = 1f;
a = 0.7f;
} else if ("traffic_signals".equals(highway)) {
pointSize = 3;
r = g = 1f;
b = 0f;
a = 0.7f;
} else if ("tree".equals(natural)) {
pointSize = 3;
g = 1f;
r = b = 0f;
a = 0.7f;
} else {
pointSize = 3;
r = 1f;
g = b = 0f;
a = 0.7f;
}
double[] c3 = new double[3];
project(node.geoCoordinate, c3);
draw.add((gl) -> {
gl.glPointSize(pointSize);
gl.glBegin(GL_POINTS);
gl.glColor4f(r, g, b, a);
gl.glVertex3d(c3[0], c3[1], c3[2]);
gl.glEnd();
});
}
return (v) -> draw.forEach(d -> d.accept(v));
}
use of jcog.list.FasterList in project narchy by automenta.
the class Simplify2D method douglasPeuckerSimplify.
// / <summary>
// / Ramer-Douglas-Peucker polygon simplification algorithm. This is the
// general recursive version that does not use the
// / speed-up technique by using the Melkman convex hull.
// /
// / If you pass in 0, it will remove all collinear points
// / </summary>
// / <returns>The simplified polygon</returns>
public static FasterList<v2> douglasPeuckerSimplify(FasterList<v2> vertices, float distanceTolerance) {
// _distanceTolerance = distanceTolerance;
int n = vertices.size();
MetalBitSet usePt = MetalBitSet.bits(n);
usePt.setAll();
simplifySection(usePt, distanceTolerance, vertices, 0, n - 1);
FasterList<v2> result = new FasterList<v2>();
for (int i = 0; i < n; i++) if (usePt.get(i))
result.add(vertices.get(i));
return result;
}
use of jcog.list.FasterList in project narchy by automenta.
the class VerletTest method init.
@Override
public void init(Dynamics2D w) {
// physics.addBehavior(new GravityBehavior2D(new Vec2D(0,0.1)));
// physics.setWorldBounds(new Rect(0,0,width,height));
List<Body2D> particles = new FasterList();
for (int y = 0, idx = 0; y < DIM; y++) {
for (int x = 0; x < DIM; x++) {
Body2D p = w.addBody(new BodyDef(BodyType.DYNAMIC), new FixtureDef(new CircleShape(REST_LENGTH / 4f), 0.1f, 0f));
p.setTransform(new v2(x * REST_LENGTH, y * REST_LENGTH), 0);
particles.add(p);
if (x > 0) {
spring(w, p, particles.get(idx - 1), STRENGTH, REST_LENGTH);
}
if (y > 0) {
spring(w, p, particles.get(idx - DIM), STRENGTH, REST_LENGTH);
}
idx++;
}
}
spring(w, particles.get(0), particles.get(particles.size() - 1), INNER_STRENGTH, (float) sqrt(sqr(REST_LENGTH * (DIM - 1)) * 2));
spring(w, particles.get(DIM - 1), particles.get(particles.size() - DIM), INNER_STRENGTH, (float) sqrt(sqr(REST_LENGTH * (DIM - 1)) * 2));
// head=physics.particles.get((DIM-1)/2);
// head.lock();
}
Aggregations