Search in sources :

Example 1 with ReadOnlyVector3

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

the class CustomRoof method processRoofEditPoints.

@Override
protected void processRoofEditPoints(final List<? extends ReadOnlyVector3> wallUpperPoints) {
    if (recalculateEditPoints) {
        recalculateEditPoints = false;
        points.clear();
        points.add(toRelative(getCenter()));
        // add or update edit points
        final int n = wallUpperPoints.size();
        for (int i = 0; i < n; i++) {
            final ReadOnlyVector3 p1 = wallUpperPoints.get(i);
            final ReadOnlyVector3 p2 = wallUpperPoints.get((i + 1) % n);
            // middle of wall = (p1 + p2) / 2
            final Vector3 v = new Vector3(p1.getX() + p2.getX(), p1.getY() + p2.getY(), 0).multiplyLocal(0.5);
            // add -normal*0.2 to middle point of wall
            final HousePart wall = findGableWall(p1, p2);
            if (wall != null) {
                final ReadOnlyVector3 normal = wall.getNormal();
                v.addLocal(normal.multiply(0.2, null).negateLocal());
            }
            v.set(toRelative(v));
            points.add(v);
        }
        computeHeight(wallUpperPoints);
        applyHeight();
    } else {
        applyHeight();
    }
}
Also used : ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) Vector3(com.ardor3d.math.Vector3) ArdorVector3PolygonPoint(org.poly2tri.triangulation.point.ardor3d.ArdorVector3PolygonPoint)

Example 2 with ReadOnlyVector3

use of com.ardor3d.math.type.ReadOnlyVector3 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 3 with ReadOnlyVector3

use of com.ardor3d.math.type.ReadOnlyVector3 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 4 with ReadOnlyVector3

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

the class Foundation method updateLabel.

@Override
public void updateLabel() {
    String text = "";
    if (labelCustom && labelCustomText != null) {
        text += labelCustomText;
    }
    if (labelId) {
        text += (text.equals("") ? "" : "\n") + "#" + id;
    }
    if (labelPowerTowerHeight) {
        text += (text.equals("") ? "" : "\n") + EnergyPanel.NO_DECIMAL.format(getSolarReceiverHeight(0) * Scene.getInstance().getAnnotationScale()) + " m";
    }
    if (labelPowerTowerOutput) {
        final double output = getPowerTowerOutputToday();
        text += (text.equals("") ? "" : "\n") + (Util.isZero(output) ? "Output" : EnergyPanel.NO_DECIMAL.format(output) + " kWh");
    }
    if (labelNumberOfMirrors) {
        final int n = getNumberOfTargetingHeliostats();
        text += n == 0 ? "" : "\n" + n + " Heliostats";
    }
    if (labelNumberOfFresnelReflectors) {
        final int n = getNumberOfTargetingFresnelReflectors();
        text += n == 0 ? "" : "\n" + n + " Fresnel Reflectors";
    }
    if (labelFresnelReflectorOutput) {
        final double output = getFresnelAbsorberOutputToday();
        text += (text.equals("") ? "" : "\n") + (Util.isZero(output) ? "Output" : EnergyPanel.NO_DECIMAL.format(output) + " kWh");
    }
    if (labelBuildingEnergy) {
        final String s = totalEnergyToday > 100 ? EnergyPanel.NO_DECIMAL.format(totalEnergyToday) : EnergyPanel.ONE_DECIMAL.format(totalEnergyToday);
        text += (text.equals("") ? "" : "\n") + (Util.isZero(totalEnergyToday) ? "Building Energy" : s + " kWh");
    }
    if (labelNumberOfSolarPanels) {
        final int n = getNumberOfSolarPanels();
        text += n == 0 ? "" : "\n" + n + " Solar Panels";
    }
    if (labelPvEnergy) {
        final String s = photovoltaicToday > 100 ? EnergyPanel.NO_DECIMAL.format(photovoltaicToday) : EnergyPanel.ONE_DECIMAL.format(photovoltaicToday);
        text += (text.equals("") ? "" : "\n") + (Util.isZero(photovoltaicToday) ? "PV Output" : s + " kWh");
    }
    if (labelSolarPotential) {
        final String s = solarPotentialToday > 100 ? EnergyPanel.NO_DECIMAL.format(solarPotentialToday) : EnergyPanel.ONE_DECIMAL.format(solarPotentialToday);
        text += (text.equals("") ? "" : "\n") + (Util.isZero(solarPotentialToday) ? "Solar Potential" : s + " kWh");
    }
    if (!text.equals("")) {
        label.setText(text);
        final ReadOnlyVector3 center = getCenter();
        label.setTranslation(center.getX(), center.getY(), boundingHeight + height + 10);
        label.setVisible(true);
    } else {
        label.setVisible(false);
    }
}
Also used : ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) CullHint(com.ardor3d.scenegraph.hint.CullHint)

Example 5 with ReadOnlyVector3

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

the class Foundation method drawHeatFlux.

/**
 * Draw the heat flux through the floor area on the foundation
 */
@Override
public void drawHeatFlux() {
    FloatBuffer arrowsVertices = heatFlux.getMeshData().getVertexBuffer();
    final int cols = (int) Math.max(2, getAbsPoint(0).distance(getAbsPoint(2)) / Scene.getInstance().getHeatVectorGridSize());
    final int rows = (int) Math.max(2, getAbsPoint(0).distance(getAbsPoint(1)) / Scene.getInstance().getHeatVectorGridSize());
    arrowsVertices = BufferUtils.createVector3Buffer(rows * cols * 6);
    heatFlux.getMeshData().setVertexBuffer(arrowsVertices);
    final double heat = calculateHeatVector();
    if (heat != 0) {
        final ReadOnlyVector3 o = getAbsPoint(0);
        final ReadOnlyVector3 u = getAbsPoint(2).subtract(o, null);
        final ReadOnlyVector3 v = getAbsPoint(1).subtract(o, null);
        final ReadOnlyVector3 normal = getNormal().negate(null);
        final Vector3 a = new Vector3();
        double g, h;
        boolean init = true;
        final Building building = new Building(this);
        for (int j = 0; j < cols; j++) {
            h = j + 0.5;
            for (int i = 0; i < rows; i++) {
                g = i + 0.5;
                a.setX(o.getX() + g * v.getX() / rows + h * u.getX() / cols);
                a.setY(o.getY() + g * v.getY() / rows + h * u.getY() / cols);
                if (building.contains(a.getX(), a.getY(), init)) {
                    a.setZ(o.getZ());
                    drawArrow(a, normal, arrowsVertices, heat);
                }
                if (init) {
                    init = false;
                }
            }
        }
        heatFlux.getMeshData().updateVertexCount();
        heatFlux.updateModelBound();
    }
    updateHeatFluxVisibility();
}
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)

Aggregations

ReadOnlyVector3 (com.ardor3d.math.type.ReadOnlyVector3)125 Vector3 (com.ardor3d.math.Vector3)88 CullHint (com.ardor3d.scenegraph.hint.CullHint)60 FloatBuffer (java.nio.FloatBuffer)45 TPoint (org.poly2tri.triangulation.point.TPoint)44 Point (org.poly2tri.geometry.primitives.Point)34 PolygonPoint (org.poly2tri.geometry.polygon.PolygonPoint)32 Mesh (com.ardor3d.scenegraph.Mesh)25 Spatial (com.ardor3d.scenegraph.Spatial)25 ArrayList (java.util.ArrayList)23 Node (com.ardor3d.scenegraph.Node)18 PickingHint (com.ardor3d.scenegraph.hint.PickingHint)18 Ray3 (com.ardor3d.math.Ray3)16 PickResults (com.ardor3d.intersection.PickResults)15 PrimitivePickResults (com.ardor3d.intersection.PrimitivePickResults)15 ArdorVector3Point (org.poly2tri.triangulation.point.ardor3d.ArdorVector3Point)15 TriangulationPoint (org.poly2tri.triangulation.TriangulationPoint)13 Matrix3 (com.ardor3d.math.Matrix3)10 CancellationException (java.util.concurrent.CancellationException)10 Vector2 (com.ardor3d.math.Vector2)9