Search in sources :

Example 26 with Vector3

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);
}
Also used : Path2D(java.awt.geom.Path2D) ArrayList(java.util.ArrayList) ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) Vector3(com.ardor3d.math.Vector3) CullHint(com.ardor3d.scenegraph.hint.CullHint) RemoveMultiplePartsCommand(org.concord.energy3d.undo.RemoveMultiplePartsCommand)

Example 27 with Vector3

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();
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : Spatial(com.ardor3d.scenegraph.Spatial) Node(com.ardor3d.scenegraph.Node) Mesh(com.ardor3d.scenegraph.Mesh) ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) Vector3(com.ardor3d.math.Vector3) CullHint(com.ardor3d.scenegraph.hint.CullHint) Matrix3(com.ardor3d.math.Matrix3)

Example 28 with Vector3

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);
    }
}
Also used : ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) Vector3(com.ardor3d.math.Vector3) CullHint(com.ardor3d.scenegraph.hint.CullHint) Matrix3(com.ardor3d.math.Matrix3)

Example 29 with Vector3

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());
            }
        }
    }
}
Also used : ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) Vector3(com.ardor3d.math.Vector3) Matrix3(com.ardor3d.math.Matrix3)

Example 30 with Vector3

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);
}
Also used : ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) Vector3(com.ardor3d.math.Vector3) CullHint(com.ardor3d.scenegraph.hint.CullHint)

Aggregations

Vector3 (com.ardor3d.math.Vector3)284 ReadOnlyVector3 (com.ardor3d.math.type.ReadOnlyVector3)258 CullHint (com.ardor3d.scenegraph.hint.CullHint)106 FloatBuffer (java.nio.FloatBuffer)69 TPoint (org.poly2tri.triangulation.point.TPoint)41 Point (org.poly2tri.geometry.primitives.Point)35 ArrayList (java.util.ArrayList)34 PolygonPoint (org.poly2tri.geometry.polygon.PolygonPoint)32 Matrix3 (com.ardor3d.math.Matrix3)30 Mesh (com.ardor3d.scenegraph.Mesh)25 Spatial (com.ardor3d.scenegraph.Spatial)24 PickingHint (com.ardor3d.scenegraph.hint.PickingHint)22 Foundation (org.concord.energy3d.model.Foundation)22 Node (com.ardor3d.scenegraph.Node)20 HousePart (org.concord.energy3d.model.HousePart)20 ArdorVector3Point (org.poly2tri.triangulation.point.ardor3d.ArdorVector3Point)20 Ray3 (com.ardor3d.math.Ray3)15 PickResults (com.ardor3d.intersection.PickResults)13 PrimitivePickResults (com.ardor3d.intersection.PrimitivePickResults)13 Vector2 (com.ardor3d.math.Vector2)12