Search in sources :

Example 36 with ReadOnlyVector3

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

the class Wall method drawHeatFlux.

@Override
public void drawHeatFlux() {
    if (type != SOLID_WALL) {
        return;
    }
    double zmax = -Double.MAX_VALUE;
    final List<Vector3> wallPolygonPoints = getWallPolygonPoints();
    for (final Vector3 a : wallPolygonPoints) {
        if (a.getZ() > zmax) {
            zmax = a.getZ();
        }
    }
    final Path2D.Double path = new Path2D.Double();
    path.moveTo(0, 0);
    final Vector3 v1 = new Vector3();
    final Vector3 v2 = new Vector3();
    wallPolygonPoints.get(1).subtract(wallPolygonPoints.get(0), v1);
    wallPolygonPoints.get(2).subtract(wallPolygonPoints.get(0), v2);
    if (Util.isZero(v1.getX()) && Util.isZero(v2.getX())) {
        path.moveTo(v1.getY(), v1.getZ());
        path.lineTo(v2.getY(), v2.getZ());
        for (int i = 3; i < wallPolygonPoints.size(); i++) {
            wallPolygonPoints.get(i).subtract(wallPolygonPoints.get(0), v2);
            path.lineTo(v2.getY(), v2.getZ());
        }
    } else {
        // always use the Y plane unless it is a X plane as above
        path.moveTo(v1.getX(), v1.getZ());
        path.lineTo(v2.getX(), v2.getZ());
        for (int i = 3; i < wallPolygonPoints.size(); i++) {
            wallPolygonPoints.get(i).subtract(wallPolygonPoints.get(0), v2);
            path.lineTo(v2.getX(), v2.getZ());
        }
    }
    path.lineTo(0, 0);
    path.closePath();
    heatFlux.getSceneHints().setCullHint(CullHint.Inherit);
    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, zmax / 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();
        final Vector3 a = new Vector3();
        double g, h;
        for (int j = 0; j < cols; j++) {
            h = j + 0.5;
            for (int i = 0; i < rows - 1; 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() + g * zmax / rows);
                a.subtract(wallPolygonPoints.get(0), v1);
                if (Util.isZero(v1.getX())) {
                    if (!path.contains(v1.getY(), v1.getZ())) {
                        break;
                    }
                } else {
                    if (!path.contains(v1.getX(), v1.getZ())) {
                        break;
                    }
                }
                drawArrow(a, normal, arrowsVertices, heat);
            }
        }
        heatFlux.getMeshData().updateVertexCount();
        heatFlux.updateModelBound();
    }
    updateHeatFluxVisibility();
}
Also used : ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) Path2D(java.awt.geom.Path2D) ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) Vector3(com.ardor3d.math.Vector3) FloatBuffer(java.nio.FloatBuffer) CullHint(com.ardor3d.scenegraph.hint.CullHint) PolygonPoint(org.poly2tri.geometry.polygon.PolygonPoint) ArdorVector3Point(org.poly2tri.triangulation.point.ardor3d.ArdorVector3Point) PickingHint(com.ardor3d.scenegraph.hint.PickingHint) TPoint(org.poly2tri.triangulation.point.TPoint) Point(org.poly2tri.geometry.primitives.Point)

Example 37 with ReadOnlyVector3

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

the class Wall method drawVerticalEdges.

private void drawVerticalEdges(final double size) {
    columns.setDefaultColor(getColor());
    final FloatBuffer vertexBuffer = columns.getMeshData().getVertexBuffer();
    final FloatBuffer normalBuffer = columns.getMeshData().getNormalBuffer();
    vertexBuffer.rewind();
    normalBuffer.rewind();
    vertexBuffer.limit(vertexBuffer.capacity());
    normalBuffer.limit(normalBuffer.capacity());
    final ReadOnlyVector3 o = getAbsPoint(0);
    final ReadOnlyVector3 u = getAbsPoint(2).subtract(o, null);
    final Vector3 dir = new Vector3(u).normalizeLocal().multiplyLocal(size);
    Util.addPointToQuad(normal, o, getAbsPoint(1), dir, vertexBuffer, normalBuffer);
    Util.addPointToQuad(normal, getAbsPoint(2), getAbsPoint(3), dir, vertexBuffer, normalBuffer);
    vertexBuffer.limit(vertexBuffer.position());
    normalBuffer.limit(normalBuffer.position());
    columns.getMeshData().updateVertexCount();
    columns.updateModelBound();
}
Also used : ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) FloatBuffer(java.nio.FloatBuffer) ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) Vector3(com.ardor3d.math.Vector3)

Example 38 with ReadOnlyVector3

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

the class Wall method computeInsideDirectionOfAttachedWalls.

public void computeInsideDirectionOfAttachedWalls(final boolean drawNeighborWalls) {
    if (this.thicknessNormal != null) {
        return;
    }
    final ArrayList<Wall> walls;
    if (drawNeighborWalls) {
        walls = new ArrayList<Wall>();
    } else {
        walls = null;
    }
    final double[] side = new double[] { 0.0 };
    Wall.clearVisits();
    visitNeighbors(new WallVisitor() {

        @Override
        public void visit(final Wall wall, final Snap prev, final Snap next) {
            if (next != null) {
                final int indexP2 = next.getSnapPointIndexOf(wall);
                final ReadOnlyVector3 p1 = wall.getAbsPoint(indexP2 == 0 ? 2 : 0);
                final ReadOnlyVector3 p2 = wall.getAbsPoint(indexP2);
                final ReadOnlyVector3 p3 = next.getNeighborOf(wall).getAbsPoint(next.getSnapPointIndexOfNeighborOf(wall) == 0 ? 2 : 0);
                final ReadOnlyVector3 p1_p2 = p2.subtract(p1, null).normalizeLocal();
                final ReadOnlyVector3 p2_p3 = p3.subtract(p2, null).normalizeLocal();
                side[0] += Util.angleBetween(p1_p2, p2_p3, Vector3.UNIT_Z);
            }
            if (drawNeighborWalls && wall != Wall.this && !walls.contains(wall)) {
                walls.add(wall);
            }
        }
    });
    Wall.clearVisits();
    visitNeighbors(new WallVisitor() {

        @Override
        public void visit(final Wall wall, final Snap prev, final Snap next) {
            if (next != null) {
                final int indexP2 = next.getSnapPointIndexOf(wall);
                final Vector3 p1 = wall.getAbsPoint(indexP2 == 0 ? 2 : 0);
                final Vector3 p2 = wall.getAbsPoint(indexP2);
                final Vector3 p1_p2 = p2.subtract(p1, null);
                wall.thicknessNormal = p1_p2.cross(Vector3.UNIT_Z, null).normalizeLocal().multiplyLocal(wall.getThickness());
                if (side[0] > 0) {
                    wall.thicknessNormal.negateLocal();
                }
            } else if (prev != null) {
                final int indexP2 = prev.getSnapPointIndexOf(wall);
                final Vector3 p2 = wall.getAbsPoint(indexP2);
                final Vector3 p3 = wall.getAbsPoint(indexP2 == 0 ? 2 : 0);
                final Vector3 p2_p3 = p3.subtract(p2, null);
                wall.thicknessNormal = p2_p3.cross(Vector3.UNIT_Z, null).normalizeLocal().multiplyLocal(wall.getThickness());
                if (side[0] > 0) {
                    wall.thicknessNormal.negateLocal();
                }
            }
        }
    });
    if (drawNeighborWalls) {
        for (final HousePart wall : walls) {
            wall.draw();
            wall.drawChildren();
        }
    }
}
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) CullHint(com.ardor3d.scenegraph.hint.CullHint) PolygonPoint(org.poly2tri.geometry.polygon.PolygonPoint) ArdorVector3Point(org.poly2tri.triangulation.point.ardor3d.ArdorVector3Point) PickingHint(com.ardor3d.scenegraph.hint.PickingHint) TPoint(org.poly2tri.triangulation.point.TPoint) Point(org.poly2tri.geometry.primitives.Point)

Example 39 with ReadOnlyVector3

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

the class Wall method flatten.

@Override
public void flatten(final double flattenTime) {
    final ReadOnlyVector3 n = getNormal();
    double angle = n.smallestAngleBetween(Vector3.NEG_UNIT_Y);
    if (n.dot(Vector3.UNIT_X) < 0) {
        angle = -angle;
    }
    root.setRotation((new Matrix3().fromAngles(0, 0, -flattenTime * angle)));
    super.flatten(flattenTime);
    for (final HousePart part : children) {
        if (!part.isPrintable()) {
            part.getRoot().setTransform(root.getTransform());
            part.getRoot().updateGeometricState(0);
        }
    }
}
Also used : ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) Matrix3(com.ardor3d.math.Matrix3)

Example 40 with ReadOnlyVector3

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

the class Window method setPreviewPoint.

@Override
public void setPreviewPoint(final int x, final int y) {
    final Foundation foundation = getTopContainer();
    if (foundation != null && foundation.getLockEdit()) {
        return;
    }
    int index = editPointIndex;
    if (index == -1) {
        if (isFirstPointInserted()) {
            index = 3;
        } else {
            index = 0;
        }
    }
    final PickedHousePart pick = pickContainer(x, y, new Class[] { Wall.class, Roof.class });
    Vector3 p = points.get(index);
    if (pick != null && !(pick.getUserData().getHousePart() instanceof Roof && isNormalHorizontal(pick))) {
        p.set(pick.getPoint());
        snapToGrid(p, getAbsPoint(index), getGridSize(), false);
        p = toRelative(p);
        if (container instanceof Wall) {
            toAbsolute(p);
            p = enforceContraints(p);
        }
    } else {
        return;
    }
    final ArrayList<Vector3> orgPoints = new ArrayList<Vector3>(points.size());
    for (final Vector3 v : points) {
        orgPoints.add(v.clone());
    }
    points.get(index).set(p);
    if (container instanceof Roof) {
        computeNormalAndKeepOnSurface();
    }
    if (!isFirstPointInserted()) {
        points.get(1).set(p);
        if (container instanceof Roof) {
            normal = (ReadOnlyVector3) ((Roof) container).getRoofPartsRoot().getChild(pick.getUserData().getEditPointIndex()).getUserData();
        }
    } else if (container instanceof Wall) {
        if (index == 0 || index == 3) {
            points.get(1).set(points.get(0).getX(), 0, points.get(3).getZ());
            points.get(2).set(points.get(3).getX(), 0, points.get(0).getZ());
        } else {
            points.get(0).set(points.get(1).getX(), 0, points.get(2).getZ());
            points.get(3).set(points.get(2).getX(), 0, points.get(1).getZ());
        }
    } else {
        final boolean isFlat = MeshLib.isSameDirection(Vector3.UNIT_Z, normal);
        final ReadOnlyVector3 u = isFlat ? Vector3.UNIT_X : Vector3.UNIT_Z.cross(normal, null);
        final ReadOnlyVector3 v = isFlat ? Vector3.UNIT_Y : normal.cross(u, null);
        if (index == 0 || index == 3) {
            final Vector3 p0 = getAbsPoint(0);
            final Vector3 p3 = getAbsPoint(3);
            points.get(1).set(toRelative(Util.closestPoint(p0, v, p3, u)));
            points.get(2).set(toRelative(Util.closestPoint(p0, u, p3, v)));
        } else {
            final Vector3 p1 = getAbsPoint(1);
            final Vector3 p2 = getAbsPoint(2);
            points.get(0).set(toRelative(Util.closestPoint(p1, v, p2, u)));
            points.get(3).set(toRelative(Util.closestPoint(p1, u, p2, v)));
        }
    }
    if (isFirstPointInserted()) {
        if (container instanceof Wall && !((Wall) container).fits(this)) {
            for (int i = 0; i < points.size(); i++) {
                points.get(i).set(orgPoints.get(i));
            }
            return;
        }
    }
    if (container != null) {
        draw();
        setEditPointsVisible(true);
        container.draw();
    }
}
Also used : ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) ArrayList(java.util.ArrayList) 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