Search in sources :

Example 16 with Vector3

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

the class Foundation method drawSolarReceiver.

public void drawSolarReceiver() {
    if (solarReceiver == null) {
        return;
    }
    int countHeliostats = 0;
    for (final HousePart p : Scene.getInstance().getParts()) {
        if (p instanceof Mirror) {
            final Mirror m = (Mirror) p;
            if (m.getReceiver() == this) {
                countHeliostats++;
            }
        }
    }
    int countFresnelReflectors = 0;
    for (final HousePart p : Scene.getInstance().getParts()) {
        if (p instanceof FresnelReflector) {
            final FresnelReflector r = (FresnelReflector) p;
            if (r.getReceiver() == this) {
                countFresnelReflectors++;
            }
        }
    }
    solarReceiver.setVisible(countHeliostats > 0 || countFresnelReflectors > 0);
    if (solarReceiver.isVisible()) {
        if (bloomRenderPass == null) {
            bloomRenderPass = new BloomRenderPass(SceneManager.getInstance().getCamera(), 10);
            // bloomRenderPass.setNrBlurPasses(1);
            SceneManager.getInstance().getPassManager().add(bloomRenderPass);
        }
        if (!bloomRenderPass.contains(solarReceiver)) {
            bloomRenderPass.add(solarReceiver);
        }
        double rx = 0;
        double ry = 0;
        final Vector3 center = getAbsCenter();
        double xmin = center.getX();
        double xmax = center.getX();
        double ymin = center.getY();
        double ymax = center.getY();
        double lmax = -1;
        int count = 0;
        for (final HousePart p : children) {
            if (p instanceof Wall) {
                final Wall wall = (Wall) p;
                final Vector3 c = p.getAbsCenter();
                rx += c.getX();
                ry += c.getY();
                if (xmin > c.getX()) {
                    xmin = c.getX();
                } else if (xmax < c.getX()) {
                    xmax = c.getX();
                }
                if (ymin > c.getY()) {
                    ymin = c.getY();
                } else if (ymax < c.getY()) {
                    ymax = c.getY();
                }
                count++;
                final double wallLength = wall.getAbsPoint(0).distance(wall.getAbsPoint(2));
                if (wallLength > lmax) {
                    lmax = wallLength;
                }
            }
        }
        if (countHeliostats > 0) {
            bloomRenderPass.setBlurIntensityMultiplier(Math.min(0.01f * countHeliostats, 0.8f));
            solarReceiver.setHeight(getSolarReceiverHeight(0.1) * 0.15);
            Vector3 o;
            if (count == 0) {
                o = getAbsCenter();
                o.setZ(getSolarReceiverHeight(0.1) - solarReceiver.getHeight() * 0.5);
                solarReceiver.setRadius(10);
            } else {
                o = new Vector3(rx / count, ry / count, getSolarReceiverHeight(0.1) - solarReceiver.getHeight() * 0.5);
                final double r1 = Math.max((xmax - xmin), (ymax - ymin)) / 2;
                final double r2 = Math.max(r1 * 0.4, 4);
                solarReceiver.setRadius(r1 + r2);
            }
            solarReceiver.setTranslation(o);
        } else if (countFresnelReflectors > 0) {
            bloomRenderPass.setBlurIntensityMultiplier(Math.min(0.1f * countFresnelReflectors, 0.8f));
            solarReceiver.setRadius(1);
            solarReceiver.setHeight(lmax);
            final double az = getAzimuth();
            final Matrix3 rotateAroundZ = new Matrix3().applyRotationZ(Math.toRadians(-az));
            final Matrix3 rotateAroundX = new Matrix3().applyRotationX(Math.PI * 0.5);
            solarReceiver.setRotation(rotateAroundZ.multiplyLocal(rotateAroundX));
            final Vector3 o = new Vector3((xmin + xmax) * 0.5, (ymin + ymax) * 0.5, getSolarReceiverHeight(solarReceiver.getRadius() * 1.2));
            solarReceiver.setTranslation(o);
        }
    }
}
Also used : ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) Vector3(com.ardor3d.math.Vector3) CullHint(com.ardor3d.scenegraph.hint.CullHint) BloomRenderPass(com.ardor3d.extension.effect.bloom.BloomRenderPass) Matrix3(com.ardor3d.math.Matrix3)

Example 17 with Vector3

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

the class Foundation method updateImportedNodePositionsAfterMove.

private void updateImportedNodePositionsAfterMove() {
    if (importedNodeStates != null) {
        final double az = Math.toRadians(getAzimuth());
        final Vector3 ac = getAbsCenter();
        if (Util.isZero(az)) {
            for (final NodeState ns : importedNodeStates) {
                ns.setAbsolutePosition(ac.addLocal(ns.getRelativePosition()));
            }
        } else {
            // why -az?
            final Matrix3 matrix = new Matrix3().fromAngles(0, 0, -az);
            for (final NodeState ns : importedNodeStates) {
                ns.setAbsolutePosition(ac.addLocal(matrix.applyPost(ns.getRelativePosition(), null)));
            }
        }
    }
}
Also used : ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) Vector3(com.ardor3d.math.Vector3) Matrix3(com.ardor3d.math.Matrix3)

Example 18 with Vector3

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

the class Foundation method getAbsCenter.

@Override
public Vector3 getAbsCenter() {
    double x = 0, y = 0, z = 0;
    for (int i = 0; i < 4; i++) {
        final Vector3 v = getAbsPoint(i);
        x += v.getX();
        y += v.getY();
        z += v.getZ();
    }
    return new Vector3(x / 4, y / 4, z / 4);
}
Also used : ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) Vector3(com.ardor3d.math.Vector3) CullHint(com.ardor3d.scenegraph.hint.CullHint)

Example 19 with Vector3

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

the class Foundation method drawOutline.

private void drawOutline(final Mesh mesh, final float height) {
    final FloatBuffer buf = mesh.getMeshData().getVertexBuffer();
    buf.rewind();
    final Vector3 p0 = getAbsPoint(0);
    final Vector3 p1 = getAbsPoint(1);
    final Vector3 p2 = getAbsPoint(2);
    final Vector3 p3 = getAbsPoint(3);
    putOutlinePoint(buf, p0);
    putOutlinePoint(buf, p2);
    putOutlinePoint(buf, p2);
    putOutlinePoint(buf, p3);
    putOutlinePoint(buf, p3);
    putOutlinePoint(buf, p1);
    putOutlinePoint(buf, p1);
    putOutlinePoint(buf, p0);
    putOutlinePoint(buf, p0, height);
    putOutlinePoint(buf, p2, height);
    putOutlinePoint(buf, p2, height);
    putOutlinePoint(buf, p3, height);
    putOutlinePoint(buf, p3, height);
    putOutlinePoint(buf, p1, height);
    putOutlinePoint(buf, p1, height);
    putOutlinePoint(buf, p0, height);
    putOutlinePoint(buf, p0);
    putOutlinePoint(buf, p0, height);
    putOutlinePoint(buf, p2);
    putOutlinePoint(buf, p2, height);
    putOutlinePoint(buf, p3);
    putOutlinePoint(buf, p3, height);
    putOutlinePoint(buf, p1);
    putOutlinePoint(buf, p1, height);
    mesh.updateModelBound();
}
Also used : FloatBuffer(java.nio.FloatBuffer) ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) Vector3(com.ardor3d.math.Vector3)

Example 20 with Vector3

use of com.ardor3d.math.Vector3 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

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