Search in sources :

Example 76 with Vector3

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

the class Roof method computeArea.

@Override
protected void computeArea() {
    this.area = 0;
    if (container == null) {
        return;
    }
    if (areaByPartWithOverhang == null) {
        areaByPartWithOverhang = new HashMap<Mesh, Double>();
    } else {
        areaByPartWithOverhang.clear();
    }
    if (areaByPartWithoutOverhang == null) {
        areaByPartWithoutOverhang = new HashMap<Mesh, Double>();
    } else {
        areaByPartWithoutOverhang.clear();
    }
    for (final Spatial roofPart : roofPartsRoot.getChildren()) {
        if (roofPart.getSceneHints().getCullHint() != CullHint.Always) {
            final Node roofPartNode = (Node) roofPart;
            final Mesh roofPartMesh = (Mesh) roofPartNode.getChild(REAL_MESH_INDEX);
            areaByPartWithOverhang.put(roofPartMesh, Util.computeArea(roofPartMesh));
            final FloatBuffer vertexBuffer = roofPartMesh.getMeshData().getVertexBuffer();
            final Vector3 p = new Vector3();
            if (overhangLength <= OVERHANG_MIN) {
                final double a = Util.computeArea(roofPartMesh);
                areaByPartWithoutOverhang.put(roofPartMesh, a);
                area += a;
            } else {
                final List<ReadOnlyVector3> result = computeDashPoints(roofPartMesh);
                if (result.isEmpty()) {
                    vertexBuffer.rewind();
                    p.set(vertexBuffer.get(), vertexBuffer.get(), vertexBuffer.get());
                    final double a;
                    if (Util.insidePolygon(p, wallUpperPointsWithoutOverhang)) {
                        a = Util.computeArea(roofPartMesh);
                    } else {
                        a = 0;
                    }
                    areaByPartWithoutOverhang.put(roofPartMesh, a);
                    area += a;
                } else {
                    // if (roofPartsRoot.getNumberOfChildren() > 1) {
                    double highPointZ = Double.NEGATIVE_INFINITY;
                    vertexBuffer.rewind();
                    while (vertexBuffer.hasRemaining()) {
                        p.set(vertexBuffer.get(), vertexBuffer.get(), vertexBuffer.get());
                        if (p.getZ() > highPointZ) {
                            highPointZ = p.getZ();
                        }
                    }
                    final List<ReadOnlyVector3> highPoints = new ArrayList<ReadOnlyVector3>();
                    vertexBuffer.rewind();
                    while (vertexBuffer.hasRemaining()) {
                        p.set(vertexBuffer.get(), vertexBuffer.get(), vertexBuffer.get());
                        if (p.getZ() >= highPointZ - MathUtils.ZERO_TOLERANCE && Util.insidePolygon(p, wallUpperPointsWithoutOverhang)) {
                            highPoints.add(new Vector3(p));
                        }
                    }
                    if (highPoints.size() == 1) {
                        result.add(highPoints.get(0));
                    } else {
                        final ReadOnlyVector3 lastPoint = result.get(result.size() - 1);
                        while (!highPoints.isEmpty()) {
                            double shortestDistance = Double.MAX_VALUE;
                            ReadOnlyVector3 nearestPoint = null;
                            for (final ReadOnlyVector3 hp : highPoints) {
                                final double distance = hp.distance(lastPoint);
                                if (distance < shortestDistance) {
                                    shortestDistance = distance;
                                    nearestPoint = hp;
                                }
                            }
                            result.add(nearestPoint);
                            highPoints.remove(nearestPoint);
                        }
                    }
                    result.add(result.get(0));
                    final double annotationScale = Scene.getInstance().getAnnotationScale();
                    final double a = Util.area3D_Polygon(result, (ReadOnlyVector3) roofPart.getUserData()) * annotationScale * annotationScale;
                    areaByPartWithoutOverhang.put(roofPartMesh, a);
                    this.area += a;
                }
            }
        }
    }
}
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) FloatBuffer(java.nio.FloatBuffer) ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) Vector3(com.ardor3d.math.Vector3)

Example 77 with Vector3

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

the class Sensor method setPreviewPoint.

@Override
public void setPreviewPoint(final int x, final int y) {
    final PickedHousePart picked = pickContainer(x, y, new Class<?>[] { Roof.class, Wall.class, Foundation.class });
    if (picked != null && picked.getUserData() != null) {
        // when the user data is null, it picks the land
        final Vector3 p = picked.getPoint().clone();
        snapToGrid(p, getAbsPoint(0), getGridSize(), false);
        points.get(0).set(toRelative(p));
    }
    if (container != null) {
        draw();
        setEditPointsVisible(true);
        setHighlight(!isDrawable());
    }
}
Also used : ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) Vector3(com.ardor3d.math.Vector3)

Example 78 with Vector3

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

the class Sensor method drawMesh.

@Override
protected void drawMesh() {
    if (container == null) {
        return;
    }
    if (container instanceof Roof) {
        final PickResults pickResults = new PrimitivePickResults();
        final Ray3 ray = new Ray3(getAbsPoint(0).addLocal(0, 0, 1000), Vector3.NEG_UNIT_Z);
        PickingUtil.findPick(container.getRoot(), ray, pickResults, false);
        if (pickResults.getNumber() != 0) {
            final PickData pickData = pickResults.getPickData(0);
            final Vector3 p = pickData.getIntersectionRecord().getIntersectionPoint(0);
            points.get(0).setZ(p.getZ());
            final UserData userData = (UserData) ((Spatial) pickData.getTarget()).getUserData();
            final int roofPartIndex = userData.getEditPointIndex();
            normal = (ReadOnlyVector3) ((Roof) container).getRoofPartsRoot().getChild(roofPartIndex).getUserData();
        }
    } else {
        normal = container.getNormal();
    }
    updateEditShapes();
    final double annotationScale = Scene.getInstance().getAnnotationScale();
    // last arg sets close to zero so the sensor doesn't cast shadow
    surround.setData(Vector3.ZERO, WIDTH / 2.0 / annotationScale, HEIGHT / 2.0 / annotationScale, 0.02);
    surround.updateModelBound();
    final FloatBuffer boxVertexBuffer = surround.getMeshData().getVertexBuffer();
    final FloatBuffer vertexBuffer = mesh.getMeshData().getVertexBuffer();
    final FloatBuffer textureBuffer = mesh.getMeshData().getTextureBuffer(0);
    final FloatBuffer outlineBuffer = outlineMesh.getMeshData().getVertexBuffer();
    vertexBuffer.rewind();
    outlineBuffer.rewind();
    textureBuffer.rewind();
    int i = 8 * 3;
    vertexBuffer.put(boxVertexBuffer.get(i)).put(boxVertexBuffer.get(i + 1)).put(boxVertexBuffer.get(i + 2));
    textureBuffer.put(1).put(0);
    outlineBuffer.put(boxVertexBuffer.get(i)).put(boxVertexBuffer.get(i + 1)).put(boxVertexBuffer.get(i + 2));
    i += 3;
    vertexBuffer.put(boxVertexBuffer.get(i)).put(boxVertexBuffer.get(i + 1)).put(boxVertexBuffer.get(i + 2));
    textureBuffer.put(0).put(0);
    outlineBuffer.put(boxVertexBuffer.get(i)).put(boxVertexBuffer.get(i + 1)).put(boxVertexBuffer.get(i + 2));
    outlineBuffer.put(boxVertexBuffer.get(i)).put(boxVertexBuffer.get(i + 1)).put(boxVertexBuffer.get(i + 2));
    i += 3;
    vertexBuffer.put(boxVertexBuffer.get(i)).put(boxVertexBuffer.get(i + 1)).put(boxVertexBuffer.get(i + 2));
    vertexBuffer.put(boxVertexBuffer.get(i)).put(boxVertexBuffer.get(i + 1)).put(boxVertexBuffer.get(i + 2));
    textureBuffer.put(0).put(1);
    textureBuffer.put(0).put(1);
    outlineBuffer.put(boxVertexBuffer.get(i)).put(boxVertexBuffer.get(i + 1)).put(boxVertexBuffer.get(i + 2));
    outlineBuffer.put(boxVertexBuffer.get(i)).put(boxVertexBuffer.get(i + 1)).put(boxVertexBuffer.get(i + 2));
    i += 3;
    vertexBuffer.put(boxVertexBuffer.get(i)).put(boxVertexBuffer.get(i + 1)).put(boxVertexBuffer.get(i + 2));
    textureBuffer.put(1).put(1);
    outlineBuffer.put(boxVertexBuffer.get(i)).put(boxVertexBuffer.get(i + 1)).put(boxVertexBuffer.get(i + 2));
    outlineBuffer.put(boxVertexBuffer.get(i)).put(boxVertexBuffer.get(i + 1)).put(boxVertexBuffer.get(i + 2));
    i = 8 * 3;
    vertexBuffer.put(boxVertexBuffer.get(i)).put(boxVertexBuffer.get(i + 1)).put(boxVertexBuffer.get(i + 2));
    textureBuffer.put(1).put(0);
    outlineBuffer.put(boxVertexBuffer.get(i)).put(boxVertexBuffer.get(i + 1)).put(boxVertexBuffer.get(i + 2));
    mesh.updateModelBound();
    outlineMesh.updateModelBound();
    mesh.setTranslation(getAbsPoint(0));
    if (normal != null) {
        // FIXME: Sometimes normal is null
        if (Util.isEqual(normal, Vector3.UNIT_Z)) {
            mesh.setRotation(new Matrix3());
        } else {
            mesh.setRotation(new Matrix3().lookAt(normal, Vector3.UNIT_Z));
        }
    }
    surround.setTranslation(mesh.getTranslation());
    surround.setRotation(mesh.getRotation());
    outlineMesh.setTranslation(mesh.getTranslation());
    outlineMesh.setRotation(mesh.getRotation());
    final ReadOnlyVector3 translation = mesh.getTranslation();
    label.setText("" + getId());
    if (normal != null) {
        final double labelOffset = 1.0;
        label.setTranslation(translation.getX() + labelOffset * normal.getX(), translation.getY() + labelOffset * normal.getY(), translation.getZ() + labelOffset * normal.getZ());
    }
}
Also used : PrimitivePickResults(com.ardor3d.intersection.PrimitivePickResults) ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) PrimitivePickResults(com.ardor3d.intersection.PrimitivePickResults) PickResults(com.ardor3d.intersection.PickResults) ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) Vector3(com.ardor3d.math.Vector3) FloatBuffer(java.nio.FloatBuffer) PickData(com.ardor3d.intersection.PickData) Ray3(com.ardor3d.math.Ray3) Matrix3(com.ardor3d.math.Matrix3)

Example 79 with Vector3

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

the class Sensor method move.

@Override
public void move(final Vector3 v, final double steplength) {
    if (lockEdit) {
        return;
    }
    v.normalizeLocal().multiplyLocal(steplength);
    final Vector3 p = getAbsPoint(0).addLocal(v);
    points.get(0).set(toRelative(p));
}
Also used : ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) Vector3(com.ardor3d.math.Vector3)

Example 80 with Vector3

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

the class Wall method applyXYTransform.

public void applyXYTransform(final List<Vector3> hole) {
    if (toXY == null) {
        computeNormalAndXYTransform();
    }
    for (final Vector3 p : hole) {
        final Point point = new ArdorVector3Point(p);
        toXY.transform(point);
        p.set(point.getX(), point.getY(), point.getZ());
    }
}
Also used : ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) Vector3(com.ardor3d.math.Vector3) PolygonPoint(org.poly2tri.geometry.polygon.PolygonPoint) ArdorVector3Point(org.poly2tri.triangulation.point.ardor3d.ArdorVector3Point) TPoint(org.poly2tri.triangulation.point.TPoint) Point(org.poly2tri.geometry.primitives.Point) ArdorVector3Point(org.poly2tri.triangulation.point.ardor3d.ArdorVector3Point)

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