Search in sources :

Example 6 with Vector3

use of com.ardor3d.math.Vector3 in project energy3d by concord-consortium.

the class Floor method setPreviewPoint.

@Override
public void setPreviewPoint(final int x, final int y) {
    final Foundation foundation = getTopContainer();
    if (foundation != null && foundation.getLockEdit()) {
        return;
    }
    pickContainer(x, y, Wall.class);
    if (container != null) {
        final ReadOnlyVector3 base = getCenter();
        final Vector3 p = Util.closestPoint(base, Vector3.UNIT_Z, x, y);
        if (p == null) {
            return;
        }
        snapToGrid(p, base, getGridSize());
        final double zMin = container.getAbsPoint(0).getZ() + 0.5;
        final double zmax = container.getAbsPoint(1).getZ();
        height = Math.min(zmax, Math.max(zMin, p.getZ()));
    }
    draw();
    setEditPointsVisible(container != null);
    final Foundation f = getTopContainer();
    if (f != null) {
        f.draw();
        // need to redraw the walls when the floor is part of a balcony
        f.drawChildren();
    }
}
Also used : ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) Vector3(com.ardor3d.math.Vector3)

Example 7 with Vector3

use of com.ardor3d.math.Vector3 in project energy3d by concord-consortium.

the class Floor method drawAnnotations.

@Override
public void drawAnnotations() {
    if (container == null) {
        return;
    }
    int annotCounter = 0;
    for (int i = 0; i < wallUpperPoints.size(); i++) {
        PolygonPoint p = wallUpperPoints.get(i);
        final Vector3 a = new Vector3(p.getX(), p.getY(), p.getZ());
        p = wallUpperPoints.get((i + 1) % wallUpperPoints.size());
        final Vector3 b = new Vector3(p.getX(), p.getY(), p.getZ());
        final SizeAnnotation sizeAnnot = fetchSizeAnnot(annotCounter++);
        sizeAnnot.setRange(a, b, getCenter(), getNormal(), original == null, Align.Center, true, false, Scene.isDrawAnnotationsInside());
        sizeAnnot.setLineWidth(original == null ? 1f : 2f);
    }
}
Also used : PolygonPoint(org.poly2tri.geometry.polygon.PolygonPoint) ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) Vector3(com.ardor3d.math.Vector3) SizeAnnotation(org.concord.energy3d.shapes.SizeAnnotation) CullHint(com.ardor3d.scenegraph.hint.CullHint) PolygonPoint(org.poly2tri.geometry.polygon.PolygonPoint) TPoint(org.poly2tri.triangulation.point.TPoint)

Example 8 with Vector3

use of com.ardor3d.math.Vector3 in project energy3d by concord-consortium.

the class Foundation method moveAllWithinPolygon.

public void moveAllWithinPolygon(final Vector3 direction) {
    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);
        }
    }
    // final RemoveMultiplePartsCommand c = new RemoveMultiplePartsCommand(selectedParts);
    double steplength = 0;
    for (final HousePart part : selectedParts) {
        if (part instanceof SolarCollector) {
            if (steplength == 0) {
                steplength = part.getGridSize();
            }
            ((SolarCollector) part).move(direction, steplength);
            part.draw();
        }
    }
    foundationPolygon.move(direction, steplength);
    foundationPolygon.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)

Example 9 with Vector3

use of com.ardor3d.math.Vector3 in project energy3d by concord-consortium.

the class Foundation method drawSideMesh.

private void drawSideMesh() {
    final FloatBuffer vertexBuffer0 = sideMesh[0].getMeshData().getVertexBuffer();
    final FloatBuffer vertexBuffer1 = sideMesh[1].getMeshData().getVertexBuffer();
    final FloatBuffer vertexBuffer2 = sideMesh[2].getMeshData().getVertexBuffer();
    final FloatBuffer vertexBuffer3 = sideMesh[3].getMeshData().getVertexBuffer();
    vertexBuffer0.rewind();
    vertexBuffer1.rewind();
    vertexBuffer2.rewind();
    vertexBuffer3.rewind();
    final Vector3 p0 = getAbsPoint(0);
    final Vector3 p1 = getAbsPoint(1);
    final Vector3 p2 = getAbsPoint(2);
    final Vector3 p3 = getAbsPoint(3);
    vertexBuffer0.put(p0.getXf()).put(p0.getYf()).put((float) height);
    vertexBuffer0.put(p0.getXf()).put(p0.getYf()).put(0f);
    vertexBuffer0.put(p2.getXf()).put(p2.getYf()).put(0f);
    vertexBuffer0.put(p2.getXf()).put(p2.getYf()).put(0f);
    vertexBuffer0.put(p2.getXf()).put(p2.getYf()).put((float) height);
    vertexBuffer0.put(p0.getXf()).put(p0.getYf()).put((float) height);
    vertexBuffer1.put(p2.getXf()).put(p2.getYf()).put((float) height);
    vertexBuffer1.put(p2.getXf()).put(p2.getYf()).put(0f);
    vertexBuffer1.put(p3.getXf()).put(p3.getYf()).put(0f);
    vertexBuffer1.put(p3.getXf()).put(p3.getYf()).put(0f);
    vertexBuffer1.put(p3.getXf()).put(p3.getYf()).put((float) height);
    vertexBuffer1.put(p2.getXf()).put(p2.getYf()).put((float) height);
    vertexBuffer2.put(p3.getXf()).put(p3.getYf()).put((float) height);
    vertexBuffer2.put(p3.getXf()).put(p3.getYf()).put(0f);
    vertexBuffer2.put(p1.getXf()).put(p1.getYf()).put(0f);
    vertexBuffer2.put(p1.getXf()).put(p1.getYf()).put(0f);
    vertexBuffer2.put(p1.getXf()).put(p1.getYf()).put((float) height);
    vertexBuffer2.put(p3.getXf()).put(p3.getYf()).put((float) height);
    vertexBuffer3.put(p1.getXf()).put(p1.getYf()).put((float) height);
    vertexBuffer3.put(p1.getXf()).put(p1.getYf()).put(0f);
    vertexBuffer3.put(p0.getXf()).put(p0.getYf()).put(0f);
    vertexBuffer3.put(p0.getXf()).put(p0.getYf()).put(0f);
    vertexBuffer3.put(p0.getXf()).put(p0.getYf()).put((float) height);
    vertexBuffer3.put(p1.getXf()).put(p1.getYf()).put((float) height);
    final FloatBuffer normalBuffer0 = sideMesh[0].getMeshData().getNormalBuffer();
    final FloatBuffer normalBuffer1 = sideMesh[1].getMeshData().getNormalBuffer();
    final FloatBuffer normalBuffer2 = sideMesh[2].getMeshData().getNormalBuffer();
    final FloatBuffer normalBuffer3 = sideMesh[3].getMeshData().getNormalBuffer();
    normalBuffer0.rewind();
    normalBuffer1.rewind();
    normalBuffer2.rewind();
    normalBuffer3.rewind();
    final ReadOnlyVector3 n1 = p0.subtract(p1, null).normalizeLocal();
    final ReadOnlyVector3 n2 = p2.subtract(p0, null).normalizeLocal();
    ReadOnlyVector3 normal = n1;
    ((UserData) sideMesh[0].getUserData()).setNormal(normal);
    for (int i = 0; i < 6; i++) {
        normalBuffer0.put(normal.getXf()).put(normal.getYf()).put(normal.getZf());
    }
    normal = n2;
    ((UserData) sideMesh[1].getUserData()).setNormal(normal);
    for (int i = 0; i < 6; i++) {
        normalBuffer1.put(normal.getXf()).put(normal.getYf()).put(normal.getZf());
    }
    normal = n1.negate(null);
    ((UserData) sideMesh[2].getUserData()).setNormal(normal);
    for (int i = 0; i < 6; i++) {
        normalBuffer2.put(normal.getXf()).put(normal.getYf()).put(normal.getZf());
    }
    normal = n2.negate(null);
    ((UserData) sideMesh[3].getUserData()).setNormal(normal);
    for (int i = 0; i < 6; i++) {
        normalBuffer3.put(normal.getXf()).put(normal.getYf()).put(normal.getZf());
    }
    for (int i = 0; i < 4; i++) {
        sideMesh[i].updateModelBound();
        CollisionTreeManager.INSTANCE.removeCollisionTree(sideMesh[i]);
    }
}
Also used : ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) FloatBuffer(java.nio.FloatBuffer) ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) Vector3(com.ardor3d.math.Vector3) CullHint(com.ardor3d.scenegraph.hint.CullHint)

Example 10 with Vector3

use of com.ardor3d.math.Vector3 in project energy3d by concord-consortium.

the class Foundation method addCircularHeliostatArrays.

public int addCircularHeliostatArrays(final HeliostatCircularFieldLayout layout) {
    EnergyPanel.getInstance().updateRadiationHeatMap();
    final Class<?>[] clazz = new Class[] { Mirror.class };
    final AddArrayCommand command = new AddArrayCommand(removeChildrenOfClass(clazz), this, clazz);
    final double a = 0.5 * Math.min(getAbsPoint(0).distance(getAbsPoint(2)), getAbsPoint(0).distance(getAbsPoint(1)));
    final Vector3 center = getAbsCenter();
    final double w = (layout.getApertureWidth() + layout.getAzimuthalSpacing()) / Scene.getInstance().getAnnotationScale();
    final double h = (layout.getApertureHeight() + layout.getRadialSpacing()) / Scene.getInstance().getAnnotationScale();
    final double rows = a / h;
    final int nrows = (int) (rows > 2 ? rows - 2 : rows);
    final double roadHalfWidth = 0.5 * layout.getAxisRoadWidth() / Scene.getInstance().getAnnotationScale();
    switch(layout.getType()) {
        case EQUAL_AZIMUTHAL_SPACING:
            for (int r = nrows - 1; r >= 0; r--) {
                double b = a * (1.0 - r / rows);
                b += b * b * layout.getRadialSpacingIncrement();
                if (b > a) {
                    break;
                }
                final double roadAngle = Math.toDegrees(Math.atan(roadHalfWidth / b));
                final int n = (int) (2 * Math.PI * b / w);
                for (int i = 0; i < n; i++) {
                    final double theta = i * 2.0 * Math.PI / n;
                    final double az = Math.toDegrees(theta);
                    if (az >= layout.getStartAngle() && az < layout.getEndAngle()) {
                        if (!Util.isZero(roadAngle) && nearAxes(az, roadAngle)) {
                            continue;
                        }
                        final Vector3 p = new Vector3(center.getX() + b * Math.cos(theta), center.getY() + b * Math.sin(theta), 0);
                        addMirror(p, layout.getBaseHeight(), layout.getApertureWidth(), layout.getApertureHeight(), az);
                    }
                }
            }
            break;
        case // http://www.powerfromthesun.net/Book/chapter10/chapter10.html#10.1.3%20%20%20Field%20Layout
        RADIAL_STAGGER:
            final double rmin = a * (1.0 - (nrows - 5) / rows);
            final int n = (int) (rmin / layout.getApertureWidth() * Scene.getInstance().getAnnotationScale());
            for (int i = 0; i < n; i++) {
                double theta = i * 2.0 * Math.PI / n;
                double az = Math.toDegrees(theta);
                if (az >= layout.getStartAngle() && az < layout.getEndAngle()) {
                    for (int j = 0; j < nrows; j++) {
                        final double r = a * (1.0 - j / rows);
                        final Vector3 p = new Vector3(center.getX() + r * Math.cos(theta), center.getY() + r * Math.sin(theta), 0);
                        addMirror(p, layout.getBaseHeight(), layout.getApertureWidth(), layout.getApertureHeight(), az);
                    }
                }
                theta = (i + 0.5) * 2.0 * Math.PI / n;
                az = Math.toDegrees(theta);
                if (az >= layout.getStartAngle() && az < layout.getEndAngle()) {
                    for (int j = 0; j < nrows; j++) {
                        final double r = a * (1.0 - j / rows) - 0.5 * h;
                        final Vector3 p = new Vector3(center.getX() + r * Math.cos(theta), center.getY() + r * Math.sin(theta), 0);
                        addMirror(p, layout.getBaseHeight(), layout.getApertureWidth(), layout.getApertureHeight(), az);
                    }
                }
            }
            break;
    }
    SceneManager.getInstance().getUndoManager().addEdit(command);
    EventQueue.invokeLater(new Runnable() {

        @Override
        public void run() {
            EnergyPanel.getInstance().updateProperties();
        }
    });
    return countParts(Mirror.class);
}
Also used : ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) Vector3(com.ardor3d.math.Vector3) AddArrayCommand(org.concord.energy3d.undo.AddArrayCommand) 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