Search in sources :

Example 66 with Vector3

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

the class Roof method flattenQuadTriangle.

private void flattenQuadTriangle(final Node roofPartNode, final double flattenTime) {
    final ReadOnlyVector3 normal = (ReadOnlyVector3) roofPartNode.getUserData();
    final double angleZ = Util.angleBetween(new Vector3(normal.getX(), normal.getY(), 0).normalizeLocal(), Vector3.NEG_UNIT_Y, Vector3.UNIT_Z);
    final Matrix3 m1 = new Matrix3().fromAngles(0, 0, flattenTime * angleZ);
    final ReadOnlyVector3 normal2 = m1.applyPost(normal, null);
    final double angleX = Util.angleBetween(normal2, Vector3.NEG_UNIT_Y, Vector3.UNIT_X);
    final Matrix3 m2 = new Matrix3().fromAngles(flattenTime * angleX, 0, 0);
    final Matrix3 matrix = m2.multiplyLocal(m1);
    final Boolean isVertical = roofPartPrintVerticalMap.get(roofPartNode);
    if (isVertical != null && isVertical) {
        new Matrix3().fromAngles(0, -Math.PI / 2.0 * flattenTime, 0).multiply(matrix, matrix);
    }
    roofPartNode.setRotation(matrix);
    ReadOnlyVector3 orgCenter = orgCenters.get(roofPartNode);
    if (orgCenter == null) {
        orgCenter = Vector3.ZERO;
    }
    final Vector3 targetPrintCenter = ((UserData) roofPartNode.getChild(0).getUserData()).getPrintCenter();
    if (!targetPrintCenter.equals(Vector3.ZERO)) {
        roofPartNode.setTranslation(targetPrintCenter.subtract(orgCenter, null).multiplyLocal(flattenTime));
    }
}
Also used : ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) Vector3(com.ardor3d.math.Vector3) Matrix3(com.ardor3d.math.Matrix3)

Example 67 with Vector3

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

the class Roof method fits.

@Override
protected boolean fits(final HousePart window) {
    for (final Spatial roofPart : roofPartsRoot.getChildren()) {
        if (roofPart.getSceneHints().getCullHint() != CullHint.Always) {
            final Mesh mesh = (Mesh) ((Node) roofPart).getChild(0);
            final ArrayList<ReadOnlyVector3> outlinePoints = MeshLib.computeOutline(mesh.getMeshData().getVertexBuffer());
            boolean allInside = true;
            boolean allOutside = true;
            for (int i = 0; i < window.getPoints().size(); i++) {
                final Vector3 p = window.getAbsPoint(i);
                roofPart.getWorldTransform().applyInverse(p);
                if (Util.insidePolygon(p, outlinePoints)) {
                    allOutside = false;
                } else {
                    allInside = false;
                }
            }
            if (!allInside && !allOutside) {
                return false;
            }
        }
    }
    return true;
}
Also used : ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) Spatial(com.ardor3d.scenegraph.Spatial) Mesh(com.ardor3d.scenegraph.Mesh) ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) Vector3(com.ardor3d.math.Vector3) CullHint(com.ardor3d.scenegraph.hint.CullHint) TPoint(org.poly2tri.triangulation.point.TPoint) TriangulationPoint(org.poly2tri.triangulation.TriangulationPoint) PolygonPoint(org.poly2tri.geometry.polygon.PolygonPoint)

Example 68 with Vector3

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

the class Roof method drawMesh.

@Override
protected void drawMesh() {
    // undo the effect of wall stretch on all walls if roof is moved to new walls
    if (previousContainer != container) {
        previousContainer = container;
        for (final Wall wall : walls) {
            wall.setRoof(null);
            wall.draw();
        }
    }
    dashPointsCache.clear();
    if (wallUpperPoints == null) {
        wallUpperPoints = new ArrayList<ReadOnlyVector3>();
    } else {
        wallUpperPoints.clear();
    }
    if (container != null) {
        initWallUpperPoints((Wall) container, walls, wallUpperPoints, wallNormals);
    }
    if (!isDrawable()) {
        roofPartsRoot.getSceneHints().setCullHint(CullHint.Always);
        setEditPointsVisible(false);
        return;
    }
    roofPartsRoot.getSceneHints().setCullHint(CullHint.Inherit);
    final ArrayList<Vector3> orgPoints = new ArrayList<Vector3>(points.size());
    for (final ReadOnlyVector3 p : points) {
        orgPoints.add(p.clone());
    }
    wallUpperPointsWithoutOverhang = new ArrayList<ReadOnlyVector3>(wallUpperPoints);
    drawRoof();
    switch(type) {
        case TRANSPARENT:
            for (final Spatial child : roofPartsRoot.getChildren()) {
                ((Mesh) ((Node) child).getChild(0)).getSceneHints().setCullHint(CullHint.Always);
                ((Mesh) ((Node) child).getChild(REAL_MESH_INDEX)).getSceneHints().setCullHint(CullHint.Always);
            }
            break;
        default:
            for (final Spatial child : roofPartsRoot.getChildren()) {
                ((Mesh) ((Node) child).getChild(0)).getSceneHints().setCullHint(CullHint.Inherit);
                ((Mesh) ((Node) child).getChild(REAL_MESH_INDEX)).getSceneHints().setCullHint(CullHint.Inherit);
            }
    }
    roofPartsRoot.updateWorldBound(true);
    drawOutline();
    if (Scene.getInstance().areDashedLinesOnRoofShown()) {
        drawDashLines();
    } else {
        for (final Spatial roofPart : roofPartsRoot.getChildren()) {
            if (roofPart.getSceneHints().getCullHint() != CullHint.Always) {
                final Mesh dashLinesMesh = (Mesh) ((Node) roofPart).getChild(5);
                dashLinesMesh.setVisible(false);
            }
        }
    }
}
Also used : ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) Spatial(com.ardor3d.scenegraph.Spatial) Node(com.ardor3d.scenegraph.Node) ArrayList(java.util.ArrayList) Mesh(com.ardor3d.scenegraph.Mesh) ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) Vector3(com.ardor3d.math.Vector3)

Example 69 with Vector3

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

the class Roof method drawHeatFlux.

@Override
public void drawHeatFlux() {
    FloatBuffer arrowsVertices = heatFlux.getMeshData().getVertexBuffer();
    final Foundation foundation = getTopContainer();
    final int cols = (int) Math.max(2, foundation.getAbsPoint(0).distance(foundation.getAbsPoint(2)) / Scene.getInstance().getHeatVectorGridSize());
    final int rows = (int) Math.max(2, foundation.getAbsPoint(0).distance(foundation.getAbsPoint(1)) / Scene.getInstance().getHeatVectorGridSize());
    arrowsVertices = BufferUtils.createVector3Buffer(rows * cols * 6);
    heatFlux.getMeshData().setVertexBuffer(arrowsVertices);
    final ReadOnlyVector3 o = foundation.getAbsPoint(0);
    final ReadOnlyVector3 u = foundation.getAbsPoint(2).subtract(o, null);
    final ReadOnlyVector3 v = foundation.getAbsPoint(1).subtract(o, null);
    final Vector3 a = new Vector3();
    double g, h;
    boolean init = true;
    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);
            a.setZ(o.getZ());
            if (insideWalls(a.getX(), a.getY(), init)) {
                ReadOnlyVector3 b = null;
                Node node = null;
                Mesh mesh = null;
                for (final Spatial child : roofPartsRoot.getChildren()) {
                    if (child.getSceneHints().getCullHint() != CullHint.Always) {
                        node = (Node) child;
                        mesh = (Mesh) node.getChild(REAL_MESH_INDEX);
                        b = findRoofIntersection(mesh, a);
                        if (b != null) {
                            break;
                        }
                    }
                }
                if (b != null) {
                    final ReadOnlyVector3 normal = (ReadOnlyVector3) node.getUserData();
                    final double heat = calculateHeatVector(mesh);
                    drawArrow(b, normal, arrowsVertices, heat);
                }
            }
            if (init) {
                init = false;
            }
        }
        heatFlux.getMeshData().updateVertexCount();
        heatFlux.updateModelBound();
    }
    updateHeatFluxVisibility();
}
Also used : ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) Spatial(com.ardor3d.scenegraph.Spatial) Node(com.ardor3d.scenegraph.Node) Mesh(com.ardor3d.scenegraph.Mesh) FloatBuffer(java.nio.FloatBuffer) ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) Vector3(com.ardor3d.math.Vector3) CullHint(com.ardor3d.scenegraph.hint.CullHint) TPoint(org.poly2tri.triangulation.point.TPoint) TriangulationPoint(org.poly2tri.triangulation.TriangulationPoint) PolygonPoint(org.poly2tri.geometry.polygon.PolygonPoint)

Example 70 with Vector3

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

the class Roof method initWallUpperPoints.

private void initWallUpperPoints(final Wall startWall, final List<Wall> walls, final List<ReadOnlyVector3> wallUpperPoints, final List<ReadOnlyVector3> wallNormals) {
    walls.clear();
    wallUpperPoints.clear();
    wallNormals.clear();
    startWall.visitNeighbors(new WallVisitor() {

        @Override
        public void visit(final Wall currentWall, final Snap prevSnap, final Snap nextSnap) {
            if (currentWall.isFirstPointInserted()) {
                walls.add(currentWall);
                currentWall.setRoof(Roof.this);
                final int pointIndex2 = nextSnap != null ? nextSnap.getSnapPointIndexOf(currentWall) + 1 : 1;
                final int pointIndex1 = pointIndex2 == 1 ? 3 : 1;
                final Vector3 p1 = currentWall.getAbsPoint(pointIndex1);
                final Vector3 p2 = currentWall.getAbsPoint(pointIndex2);
                final ReadOnlyVector3 normal = currentWall.getNormal();
                addPointToPolygon(p1, normal, wallUpperPoints, wallNormals);
                addPointToPolygon(p2, normal, wallUpperPoints, wallNormals);
            }
        }
    });
}
Also used : WallVisitor(org.concord.energy3d.util.WallVisitor) ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) Vector3(com.ardor3d.math.Vector3)

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