Search in sources :

Example 1 with Matrix3

use of com.ardor3d.math.Matrix3 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 2 with Matrix3

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

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

use of com.ardor3d.math.Matrix3 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 5 with Matrix3

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

Aggregations

Matrix3 (com.ardor3d.math.Matrix3)38 ReadOnlyVector3 (com.ardor3d.math.type.ReadOnlyVector3)31 Vector3 (com.ardor3d.math.Vector3)30 FloatBuffer (java.nio.FloatBuffer)12 CullHint (com.ardor3d.scenegraph.hint.CullHint)10 BloomRenderPass (com.ardor3d.extension.effect.bloom.BloomRenderPass)6 Node (com.ardor3d.scenegraph.Node)5 Spatial (com.ardor3d.scenegraph.Spatial)5 Mesh (com.ardor3d.scenegraph.Mesh)4 BoundingBox (com.ardor3d.bounding.BoundingBox)3 ColladaImporter (com.ardor3d.extension.model.collada.jdom.ColladaImporter)3 ColladaStorage (com.ardor3d.extension.model.collada.jdom.data.ColladaStorage)3 ReadOnlyTransform (com.ardor3d.math.type.ReadOnlyTransform)3 DirectionalLight (com.ardor3d.light.DirectionalLight)2 BlendState (com.ardor3d.renderer.state.BlendState)2 LightState (com.ardor3d.renderer.state.LightState)2 BillboardNode (com.ardor3d.scenegraph.extension.BillboardNode)2 CameraNode (com.ardor3d.scenegraph.extension.CameraNode)2 Quad (com.ardor3d.scenegraph.shape.Quad)2 ResourceSource (com.ardor3d.util.resource.ResourceSource)2