use of com.ardor3d.math.Vector2 in project energy3d by concord-consortium.
the class Wall method snapToFoundation.
private boolean snapToFoundation(final Vector3 current) {
if (container == null) {
return false;
}
ReadOnlyVector3 snapPoint = null;
double snapDistance = Double.MAX_VALUE;
final int[] indices = new int[] { 0, 2, 3, 1, 0 };
for (int i = 0; i < indices.length - 1; i++) {
final Vector3 p1 = container.getAbsPoint(indices[i]);
final Vector3 p2 = container.getAbsPoint(indices[i + 1]);
final Vector2 p2D = Util.projectPointOnLine(new Vector2(current.getX(), current.getY()), new Vector2(p1.getX(), p1.getY()), new Vector2(p2.getX(), p2.getY()), true);
final Vector3 p = new Vector3(p2D.getX(), p2D.getY(), current.getZ());
final double d = p.distance(current);
if (d < snapDistance) {
snapDistance = d;
snapPoint = p;
}
}
if (snapDistance < getGridSize() / 2) {
current.set(snapPoint.getX(), snapPoint.getY(), current.getZ());
return true;
} else {
return false;
}
}
use of com.ardor3d.math.Vector2 in project energy3d by concord-consortium.
the class Roof method insideWalls.
public boolean insideWalls(final double x, final double y, final boolean init) {
if (walls.isEmpty()) {
return false;
}
if (init) {
if (underlyingWallVerticesOnFoundation == null) {
underlyingWallVerticesOnFoundation = new ArrayList<Vector2>();
} else {
underlyingWallVerticesOnFoundation.clear();
}
walls.get(0).visitNeighbors(new WallVisitor() {
@Override
public void visit(final Wall currentWall, final Snap prev, final Snap next) {
int pointIndex = 0;
if (next != null) {
pointIndex = next.getSnapPointIndexOf(currentWall);
}
pointIndex++;
addUnderlyingWallVertex(currentWall.getAbsPoint(pointIndex == 1 ? 3 : 1));
addUnderlyingWallVertex(currentWall.getAbsPoint(pointIndex));
}
private void addUnderlyingWallVertex(final ReadOnlyVector3 v3) {
final Vector2 v2 = new Vector2(v3.getX(), v3.getY());
boolean b = false;
for (final Vector2 x : underlyingWallVerticesOnFoundation) {
if (Util.isEqual(x, v2)) {
b = true;
break;
}
}
if (!b) {
underlyingWallVerticesOnFoundation.add(v2);
}
}
});
if (underlyingWallPath == null) {
underlyingWallPath = new Path2D.Double();
} else {
underlyingWallPath.reset();
}
final Vector2 v0 = underlyingWallVerticesOnFoundation.get(0);
underlyingWallPath.moveTo(v0.getX(), v0.getY());
for (int i = 1; i < underlyingWallVerticesOnFoundation.size(); i++) {
final Vector2 v = underlyingWallVerticesOnFoundation.get(i);
underlyingWallPath.lineTo(v.getX(), v.getY());
}
underlyingWallPath.lineTo(v0.getX(), v0.getY());
underlyingWallPath.closePath();
}
return underlyingWallPath != null ? underlyingWallPath.contains(x, y) : false;
}
use of com.ardor3d.math.Vector2 in project energy3d by concord-consortium.
the class CustomRoof method setPreviewPoint.
@Override
public void setPreviewPoint(final int x, final int y) {
final Foundation foundation = getTopContainer();
if (foundation != null && foundation.getLockEdit()) {
return;
}
final EditState editState = new EditState();
if (editPointIndex == -1) {
recalculateEditPoints = true;
pickContainer(x, y, Wall.class);
} else if (editPointIndex == 0) {
final ReadOnlyVector3 base = getCenter();
final Vector3 p = Util.closestPoint(base, Vector3.UNIT_Z, x, y);
if (p == null) {
return;
}
snapToGrid(p, getAbsPoint(editPointIndex), getGridSize());
height = Math.max(0, p.getZ() - container.getPoints().get(1).getZ());
final double z = container.getPoints().get(1).getZ() + height;
for (final Vector3 v : points) {
v.setZ(z);
}
} else {
final Ray3 pickRay = SceneManager.getInstance().getCamera().getPickRay(new Vector2(x, y), false, null);
final Vector3 p = new Vector3();
if (pickRay.intersectsPlane(new Plane(Vector3.UNIT_Z, points.get(0).getZ()), p)) {
snapToGrid(p, getAbsPoint(editPointIndex), getGridSize(), false);
snapToWallsPolygon(p);
points.get(editPointIndex).set(toRelative(p));
}
}
postEdit(editState);
}
Aggregations