use of spacegraph.util.math.Tuple2f in project narchy by automenta.
the class SingletonVD method sort.
/**
* Zotriedi vrcholy v polygone podla uhlu
*
* @param indexPolygon
*/
private void sort(int indexPolygon) {
int size = vCount[indexPolygon];
if (size != 0) {
polygon = voronoi[indexPolygon];
Tuple2f focus = ar[indexPolygon];
for (int i = 0; i != size; ++i) {
comparer[i] = angle(points[polygon[i]], focus);
}
quicksortPoly(0, size - 1);
}
}
use of spacegraph.util.math.Tuple2f in project narchy by automenta.
the class Box2DTests method drawJoint.
private void drawJoint(Joint joint) {
g.setColor(Color.GREEN);
Tuple2f v1 = new Vec2();
Tuple2f v2 = new Vec2();
switch(joint.getType()) {
case DISTANCE:
DistanceJoint dj = (DistanceJoint) joint;
v1 = joint.getBodyA().getWorldPoint(dj.getLocalAnchorA());
v2 = joint.getBodyB().getWorldPoint(dj.getLocalAnchorB());
break;
case MOUSE:
MouseJoint localMj = (MouseJoint) joint;
localMj.getAnchorA(v1);
localMj.getAnchorB(v2);
break;
}
Point p1 = getPoint(v1);
Point p2 = getPoint(v2);
g.drawLine(p1.x, p1.y, p2.x, p2.y);
}
use of spacegraph.util.math.Tuple2f in project narchy by automenta.
the class Box2DTests method initMouse.
private void initMouse() {
addMouseWheelListener((MouseWheelEvent e) -> {
if (e.getWheelRotation() < 0) {
zoom *= 1.25f * -e.getWheelRotation();
} else {
zoom /= 1.25f * e.getWheelRotation();
}
zoom = Math.min(zoom, 100);
zoom = Math.max(zoom, 0.1f);
repaint();
});
addMouseMotionListener(new MouseMotionListener() {
@Override
public void mouseDragged(MouseEvent e) {
Point p = e.getPoint();
mousePosition = getPoint(p);
if (clickedPoint != null) {
p.x -= clickedPoint.x;
p.y -= clickedPoint.y;
center.x = startCenter.x - p.x / zoom;
center.y = startCenter.y + p.y / zoom;
} else {
if (mj != null) {
mj.setTarget(mousePosition);
}
}
if (!running) {
repaint();
}
}
@Override
public void mouseMoved(MouseEvent e) {
Point p = e.getPoint();
mousePosition = getPoint(p);
if (!running) {
repaint();
}
}
});
addMouseListener(new MouseListener() {
@Override
public void mouseClicked(MouseEvent e) {
}
@Override
public void mousePressed(MouseEvent e) {
int x = e.getX();
int y = e.getY();
Point p = new Point(x, y);
switch(e.getButton()) {
case 3:
startCenter.set(center);
clickedPoint = p;
break;
case 1:
Tuple2f v = getPoint(p);
/*synchronized(Tests.this)*/
{
w.bodies(b -> {
for (Fixture f = b.fixtures(); f != null; f = f.next) {
if (f.testPoint(v)) {
MouseJointDef def = new MouseJointDef();
def.bodyA = ground;
def.bodyB = b;
def.collideConnected = true;
def.target.set(v);
def.maxForce = 500f * b.getMass();
def.dampingRatio = 0;
mjdef = def;
return;
}
}
});
}
break;
}
}
@Override
public void mouseReleased(MouseEvent e) {
// synchronized (Tests.this) {
switch(e.getButton()) {
case 3:
clickedPoint = null;
break;
case 1:
if (mj != null) {
destroyMj = true;
}
break;
}
// }
}
@Override
public void mouseEntered(MouseEvent e) {
}
@Override
public void mouseExited(MouseEvent e) {
}
});
}
use of spacegraph.util.math.Tuple2f in project narchy by automenta.
the class Box2DTests method drawParticles.
private void drawParticles() {
Tuple2f[] vec = w.getParticlePositionBuffer();
if (vec == null) {
return;
}
g.setColor(Color.MAGENTA);
float radius = w.getParticleRadius();
int size = w.getParticleCount();
for (int i = 0; i < size; i++) {
Tuple2f vx = vec[i];
Point pp = getPoint(vx);
float r = radius * zoom;
if (r < 0.5f) {
// ak je zoom priliz maly, tak by kvapalinu nezobrazilo
g.drawLine(pp.x, pp.y, pp.x, pp.y);
} else {
// int radInt = Math.round(r * 2);
g.fillOval(pp.x - (int) r, pp.y - (int) r, (int) (r * 2), (int) (r * 2));
}
}
}
use of spacegraph.util.math.Tuple2f 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