use of com.ardor3d.math.Vector3 in project energy3d by concord-consortium.
the class Foundation method removeAllWithinPolygon.
public void removeAllWithinPolygon() {
if (foundationPolygon == null || !foundationPolygon.isVisible()) {
return;
}
final Path2D.Double path = new Path2D.Double();
final int n = foundationPolygon.points.size();
Vector3 v = foundationPolygon.getAbsPoint(0);
path.moveTo(v.getX(), v.getY());
for (int i = 1; i < n / 2; i++) {
// use only the first half of the vertices from the polygon
v = foundationPolygon.getAbsPoint(i);
path.lineTo(v.getX(), v.getY());
}
path.closePath();
final List<HousePart> selectedParts = new ArrayList<HousePart>();
for (final HousePart child : children) {
final Vector3 center = child.getAbsCenter();
if (path.contains(center.getX(), center.getY())) {
selectedParts.add(child);
}
}
if (selectedParts.isEmpty()) {
JOptionPane.showMessageDialog(MainFrame.getInstance(), "There is no object to remove.", "No Object", JOptionPane.INFORMATION_MESSAGE);
return;
}
if (JOptionPane.showConfirmDialog(MainFrame.getInstance(), "<html>Do you really want to remove all " + selectedParts.size() + " objects<br>within the white border line of the selected foundation?</html>", "Confirm", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE) != JOptionPane.YES_OPTION) {
return;
}
final RemoveMultiplePartsCommand c = new RemoveMultiplePartsCommand(selectedParts);
for (final HousePart part : selectedParts) {
Scene.getInstance().remove(part, false);
}
draw();
SceneManager.getInstance().getUndoManager().addEdit(c);
}
use of com.ardor3d.math.Vector3 in project energy3d by concord-consortium.
the class Foundation method drawImportedNodes.
public void drawImportedNodes() {
if (importedNodes != null) {
final int n = importedNodes.size();
if (n > 0) {
Node ni;
final Vector3 c = getAbsCenter();
// the absolute center is lifted to the center of the bounding box that includes walls when there are
c.setZ(height);
// FIXME: Why negate?
final Matrix3 matrix = new Matrix3().fromAngles(0, 0, -Math.toRadians(getAzimuth()));
for (int i = 0; i < n; i++) {
ni = importedNodes.get(i);
if (root.getChildren().contains(ni)) {
final Vector3 relativePosition = importedNodeStates.get(i).getRelativePosition();
if (relativePosition != null) {
final Vector3 vi = matrix.applyPost(relativePosition, null);
ni.setTranslation(c.add(vi, null));
ni.setRotation(matrix);
for (final Spatial s : ni.getChildren()) {
if (s instanceof Mesh) {
final Mesh m = (Mesh) s;
m.updateModelBound();
}
}
}
}
}
}
}
}
use of com.ardor3d.math.Vector3 in project energy3d by concord-consortium.
the class Foundation method rotate.
/**
* If center is null, use the center of this foundation. set update false if this is for rotating the coordinate system of this foundation for easier math
*/
public void rotate(final double angle, ReadOnlyVector3 center, final boolean update) {
final Matrix3 matrix = new Matrix3().fromAngles(0, 0, angle);
if (center == null) {
center = toRelative(getCenter().clone());
}
for (int i = 0; i < points.size(); i++) {
final Vector3 p = getAbsPoint(i);
final Vector3 op = p.subtract(center, null);
matrix.applyPost(op, op);
op.add(center, p);
points.get(i).set(toRelative(p));
}
if (update) {
if (SceneManager.getInstance().getSelectedPart() == this) {
drawAzimuthArrow();
}
clearSelectedMesh();
setRotatedNormalsForImportedMeshes();
updateImportedNodePositionsAfterRotate(matrix);
}
}
use of com.ardor3d.math.Vector3 in project energy3d by concord-consortium.
the class Foundation method keepImportedNodesAtSamePositions.
// while resizing the foundation, we don't want imported nodes to move. so fix them here
private void keepImportedNodesAtSamePositions() {
if (importedNodeStates != null) {
final Vector3 center = getAbsCenter();
final double az = Math.toRadians(getAzimuth());
if (Util.isZero(az)) {
for (final NodeState ns : importedNodeStates) {
final Vector3 r = ns.getAbsolutePosition().subtract(center, null);
ns.getRelativePosition().setX(r.getX());
ns.getRelativePosition().setY(r.getY());
}
} else {
final Matrix3 matrix = new Matrix3().fromAngles(0, 0, az);
for (final NodeState ns : importedNodeStates) {
Vector3 r = ns.getAbsolutePosition().subtract(center, null);
r = matrix.applyPost(r, null);
ns.getRelativePosition().setX(r.getX());
ns.getRelativePosition().setY(r.getY());
}
}
}
}
use of com.ardor3d.math.Vector3 in project energy3d by concord-consortium.
the class Foundation method rescale.
/**
* Rescale the building in the original X, Y, Z directions.
*/
public void rescale(final double scaleX, final double scaleY, final double scaleZ) {
final boolean currentOverlapAllowance = Scene.getInstance().getDisallowFoundationOverlap();
Scene.getInstance().setDisallowFoundationOverlap(false);
final double a = Math.toRadians(getAzimuth());
if (!Util.isZero(a)) {
rotate(a, null, false);
}
final Vector3 center = getAbsCenter().multiplyLocal(1, 1, 0);
move(center.negateLocal(), center.length());
for (int i = 0; i < points.size(); i++) {
points.get(i).multiplyLocal(scaleX, scaleY, 1);
}
if (!Util.isEqual(scaleZ, 1)) {
applyNewHeight(children, scaleZ, true);
final List<Roof> roofs = getRoofs();
for (final Roof r : roofs) {
r.setOverhangLength(r.getOverhangLength() * scaleZ);
}
}
move(center.negateLocal(), center.length());
if (!Util.isZero(a)) {
rotate(-a, null, false);
}
Scene.getInstance().setDisallowFoundationOverlap(currentOverlapAllowance);
}
Aggregations