Search in sources :

Example 86 with ReadOnlyVector3

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

the class Wall method drawRails.

private void drawRails(final double distance, final boolean fence) {
    rails.setDefaultColor(getColor());
    final FloatBuffer vertexBuffer = rails.getMeshData().getVertexBuffer();
    final FloatBuffer normalBuffer = rails.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 v = getAbsPoint(1).subtract(o, null);
    final int cols = (int) Math.max(2, u.length() / distance);
    if (fence) {
        Vector3 dir = v.clone().normalizeLocal().multiplyLocal(railRadius * 2);
        final Vector3 p10 = v.clone();
        final Vector3 p32 = getAbsPoint(3).subtractLocal(getAbsPoint(2));
        p10.multiplyLocal(1, 1, 0.3);
        p32.multiplyLocal(1, 1, 0.3);
        Util.addPointToQuad(normal, getAbsPoint(0).addLocal(p10), getAbsPoint(2).addLocal(p32), dir, vertexBuffer, normalBuffer);
        Util.addPointToQuad(normal, getAbsPoint(1).subtractLocal(p10), getAbsPoint(3).subtractLocal(p32), dir, vertexBuffer, normalBuffer);
        dir = new Vector3(u).normalizeLocal().multiplyLocal(railRadius);
        final Vector3 dir5 = new Vector3(u).normalizeLocal().multiplyLocal(railRadius * 3);
        // v.multiplyLocal(1.2);
        final Vector3 p = new Vector3();
        for (int col = 0; col <= cols; col++) {
            u.multiply((double) col / cols, p).addLocal(o.getX(), o.getY(), o.getZ());
            Util.addPointToQuad(normal, p, p.add(v, null), col % 10 == 0 ? dir5 : dir, vertexBuffer, normalBuffer);
        }
    } else {
        floor = getFloor();
        if (floor == null) {
            visitNeighbors(new WallVisitor() {

                @Override
                public void visit(final Wall currentWall, final Snap prev, final Snap next) {
                    final Floor f = currentWall.getFloor();
                    if (f != null) {
                        floor = f;
                    }
                }
            });
        }
        if (floor == null) {
            Vector3 dir = v.clone().normalizeLocal().multiplyLocal(railRadius * 3);
            final double heightRatio = 0.33;
            final Vector3 p10 = v.clone();
            final Vector3 p32 = getAbsPoint(3).subtractLocal(getAbsPoint(2));
            p10.multiplyLocal(1, 1, heightRatio);
            p32.multiplyLocal(1, 1, heightRatio);
            Util.addPointToQuad(normal, getAbsPoint(0).addLocal(p10), getAbsPoint(2).addLocal(p32), dir, vertexBuffer, normalBuffer);
            dir = new Vector3(u).normalizeLocal().multiplyLocal(railRadius);
            v.multiplyLocal(heightRatio);
            final Vector3 p = new Vector3();
            for (int col = 0; col <= cols; col++) {
                u.multiply((double) col / cols, p).addLocal(o.getX(), o.getY(), o.getZ());
                Util.addPointToQuad(normal, p, p.add(v, null), dir, vertexBuffer, normalBuffer);
            }
        } else {
            final double z0 = floor.getAbsPoint(0).getZ();
            Vector3 dir = new Vector3(v).normalizeLocal().multiplyLocal(railRadius * 3);
            Util.addPointToQuad(normal, getAbsPoint(1), getAbsPoint(3), dir, vertexBuffer, normalBuffer);
            dir = new Vector3(u).normalizeLocal().multiplyLocal(railRadius);
            Vector3 q = getAbsPoint(1);
            Util.addPointToQuad(normal, q, new Vector3(q.getX(), q.getY(), z0), dir, vertexBuffer, normalBuffer);
            q = getAbsPoint(3);
            Util.addPointToQuad(normal, q, new Vector3(q.getX(), q.getY(), z0), dir, vertexBuffer, normalBuffer);
            q = new Vector3(0, 0, q.getZ() - z0);
            final Vector3 p = new Vector3();
            for (int col = 1; col < cols; col++) {
                u.multiply((double) col / cols, p).addLocal(o.getX(), o.getY(), z0);
                Util.addPointToQuad(normal, p, p.add(q, null), dir, vertexBuffer, normalBuffer);
            }
        }
    }
    vertexBuffer.limit(vertexBuffer.position());
    normalBuffer.limit(normalBuffer.position());
    rails.getMeshData().updateVertexCount();
    rails.updateModelBound();
}
Also used : WallVisitor(org.concord.energy3d.util.WallVisitor) 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) 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 87 with ReadOnlyVector3

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

the class Wall method findRoofIntersection.

public ReadOnlyVector3 findRoofIntersection(final ReadOnlyVector3 p, final ReadOnlyVector3 direction, final double offset) {
    if (roof == null) {
        return p;
    }
    final Vector3 origin = new Vector3(p.getX(), p.getY(), direction.equals(Vector3.UNIT_Z) ? 0 : p.getZ());
    final PickResults pickResults = new PrimitivePickResults();
    PickingUtil.findPick(roof.getRoofPartsRoot(), new Ray3(origin, direction), pickResults, false);
    if (pickResults.getNumber() > 0) {
        return pickResults.getPickData(0).getIntersectionRecord().getIntersectionPoint(0).add(direction.multiply(roof.getOverhangLength() > 0.05 ? offset : 0, null), null);
    } else {
        return p;
    }
}
Also used : PrimitivePickResults(com.ardor3d.intersection.PrimitivePickResults) ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) Vector3(com.ardor3d.math.Vector3) PrimitivePickResults(com.ardor3d.intersection.PrimitivePickResults) PickResults(com.ardor3d.intersection.PickResults) Ray3(com.ardor3d.math.Ray3)

Example 88 with ReadOnlyVector3

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

the class Wall method drawGrids.

@Override
public void drawGrids(final double gridSize) {
    final ReadOnlyVector3 p0 = getAbsPoint(0);
    final ReadOnlyVector3 p2 = getAbsPoint(2);
    final ReadOnlyVector3 width = p2.subtract(p0, null);
    final ArrayList<ReadOnlyVector3> points = new ArrayList<ReadOnlyVector3>();
    final int cols = (int) (width.length() / gridSize);
    double gableHeight = height;
    ReadOnlyVector3 gablePeakBase = p0;
    for (int col = 1; col < cols; col++) {
        final ReadOnlyVector3 lineP1 = width.normalize(null).multiplyLocal(col * gridSize).addLocal(p0);
        points.add(lineP1);
        final ReadOnlyVector3 lineP2 = findRoofIntersection(new Vector3(lineP1.getX(), lineP1.getY(), height), Vector3.UNIT_Z, 0);
        points.add(lineP2);
        if (lineP2.getZ() > gableHeight) {
            gableHeight = lineP2.getZ();
            gablePeakBase = lineP1;
        }
    }
    final ReadOnlyVector3 height = getAbsPoint(1).subtractLocal(p0).normalizeLocal().multiplyLocal(gableHeight);
    final int rows = (int) (gableHeight / gridSize);
    for (int row = 1; row < rows; row++) {
        final ReadOnlyVector3 pMiddle = height.normalize(null).multiplyLocal(row * gridSize).addLocal(gablePeakBase);
        ReadOnlyVector3 lineP1 = new Vector3(p0.getX(), p0.getY(), pMiddle.getZ());
        ReadOnlyVector3 lineP2 = new Vector3(p2.getX(), p2.getY(), pMiddle.getZ());
        if (pMiddle.getZ() > this.height) {
            ReadOnlyVector3 tmp;
            tmp = findRoofIntersection(pMiddle, width.normalize(null), 0);
            if (tmp != pMiddle) {
                lineP1 = tmp;
            }
            tmp = findRoofIntersection(pMiddle, width.normalize(null).negateLocal(), 0);
            if (tmp != pMiddle) {
                lineP2 = tmp;
            }
        }
        points.add(lineP1);
        points.add(lineP2);
    }
    if (points.size() < 2) {
        return;
    }
    final FloatBuffer buf = BufferUtils.createVector3Buffer(points.size());
    for (final ReadOnlyVector3 p : points) {
        buf.put(p.getXf()).put(p.getYf()).put(p.getZf());
    }
    gridsMesh.getMeshData().setVertexBuffer(buf);
}
Also used : ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) ArrayList(java.util.ArrayList) 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 89 with ReadOnlyVector3

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

the class Wall method snapToFoundation.

private boolean snapToFoundation(final Vector3 current) {
    if (container == null) {
        return false;
    }
    ReadOnlyVector3 snapPoint = null;
    double snapDistance = Double.MAX_VALUE;
    final int[] indices = new int[] { 0, 2, 3, 1, 0 };
    for (int i = 0; i < indices.length - 1; i++) {
        final Vector3 p1 = container.getAbsPoint(indices[i]);
        final Vector3 p2 = container.getAbsPoint(indices[i + 1]);
        final Vector2 p2D = Util.projectPointOnLine(new Vector2(current.getX(), current.getY()), new Vector2(p1.getX(), p1.getY()), new Vector2(p2.getX(), p2.getY()), true);
        final Vector3 p = new Vector3(p2D.getX(), p2D.getY(), current.getZ());
        final double d = p.distance(current);
        if (d < snapDistance) {
            snapDistance = d;
            snapPoint = p;
        }
    }
    if (snapDistance < getGridSize() / 2) {
        current.set(snapPoint.getX(), snapPoint.getY(), current.getZ());
        return true;
    } else {
        return false;
    }
}
Also used : ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) Vector2(com.ardor3d.math.Vector2) 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 90 with ReadOnlyVector3

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

the class Wall method drawOutline.

private void drawOutline(final List<List<Vector3>> wallAndWindowsPoints) {
    final List<Vector3> wallPolygonPoints = wallAndWindowsPoints.get(0);
    FloatBuffer outlineVertexBuffer = outlineMesh.getMeshData().getVertexBuffer();
    final int requiredSize = 2 * (wallPolygonPoints.size() + (wallAndWindowsPoints.size() - 1) * 4);
    if (outlineVertexBuffer.capacity() / 3 < requiredSize) {
        outlineVertexBuffer = BufferUtils.createVector3Buffer(requiredSize);
        outlineMesh.getMeshData().setVertexBuffer(outlineVertexBuffer);
    } else {
        outlineVertexBuffer.rewind();
        outlineVertexBuffer.limit(outlineVertexBuffer.capacity());
    }
    outlineVertexBuffer.rewind();
    ReadOnlyVector3 prev = wallPolygonPoints.get(wallPolygonPoints.size() - 1);
    for (final ReadOnlyVector3 point : wallPolygonPoints) {
        outlineVertexBuffer.put(prev.getXf()).put(prev.getYf()).put(prev.getZf());
        prev = point;
        outlineVertexBuffer.put(point.getXf()).put(point.getYf()).put(point.getZf());
    }
    for (int i = 1; i < wallAndWindowsPoints.size(); i++) {
        final List<Vector3> windowHolePoints = wallAndWindowsPoints.get(i);
        prev = windowHolePoints.get(3);
        for (int j = 0; j < 4; j++) {
            final ReadOnlyVector3 point = windowHolePoints.get(j);
            outlineVertexBuffer.put(prev.getXf()).put(prev.getYf()).put(prev.getZf());
            prev = point;
            outlineVertexBuffer.put(point.getXf()).put(point.getYf()).put(point.getZf());
        }
    }
    outlineVertexBuffer.limit(outlineVertexBuffer.position());
    outlineMesh.getMeshData().updateVertexCount();
    outlineMesh.updateModelBound();
    outlineMesh.setTranslation(getNormal().multiply(0.001, null));
}
Also used : ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) 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)

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