Search in sources :

Example 16 with ReadOnlyVector3

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

the class Rack method findRotationMatrix.

private Matrix3 findRotationMatrix(final ReadOnlyVector3 v1, final ReadOnlyVector3 v2) {
    final double angle = v1.smallestAngleBetween(v2);
    final Vector3 axis = v1.cross(v2, null).normalizeLocal();
    final Matrix3 matrix = new Matrix3().fromAngleAxis(angle, axis);
    return matrix;
}
Also used : ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) Vector3(com.ardor3d.math.Vector3) Matrix3(com.ardor3d.math.Matrix3)

Example 17 with ReadOnlyVector3

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

the class Rack method setPreviewPoint.

@Override
public void setPreviewPoint(final int x, final int y) {
    if (lockEdit) {
        return;
    }
    if (moveStartPoint == null) {
        initSolarPanelsForMove();
    }
    if (editPointIndex <= 0) {
        // isBaseZ = true;
        final PickedHousePart picked = pickContainer(x, y, new Class<?>[] { Foundation.class, Roof.class, Wall.class, Floor.class });
        if (picked != null && picked.getUserData() != null) {
            // when the user data is null, it picks the land
            final Vector3 p = picked.getPoint().clone();
            // isBaseZ = Util.isEqual(p.getZ(), baseZ);
            final UserData ud = picked.getUserData();
            if (ud.getHousePart() instanceof Foundation && ud.isImported() && ud.getNodeIndex() >= 0 && ud.getMeshIndex() >= 0) {
                // if this rack rests on an imported mesh, store its info and don't snap to grid (as imported meshes do not sit on grid)
                meshLocator = new MeshLocator((Foundation) ud.getHousePart(), ud.getNodeIndex(), ud.getMeshIndex());
            } else {
                snapToGrid(p, getAbsPoint(0), getGridSize(), container instanceof Wall);
                meshLocator = null;
            }
            points.get(0).set(toRelative(p));
            pickedNormal = ud.getRotatedNormal() == null ? ud.getNormal() : ud.getRotatedNormal();
        } else {
            pickedNormal = null;
        }
        if (outOfBound()) {
            if (oldRackCenter != null && !oldRackCenter.equals(new Vector3())) {
                // TODO: Need to find a better way to do this
                points.get(0).set(oldRackCenter);
            }
        } else {
            oldRackCenter = points.get(0).clone();
        }
        if (container != null) {
            moveSolarPanels(getPoints().get(0).clone().subtractLocal(moveStartPoint), solarOrgPoints);
        }
    } else {
        final ReadOnlyVector3 pEdit = getEditPointShape(editPointIndex).getTranslation();
        final Vector3 p;
        if (editPointIndex % 2 == 0) {
            final ReadOnlyVector3 p1 = getEditPointShape(editPointIndex == 2 ? 4 : 2).getTranslation();
            p = Util.closestPoint(pEdit, pEdit.subtract(p1, null).normalizeLocal(), x, y);
            if (p != null) {
                final double rw = p.distance(p1) * Scene.getInstance().getAnnotationScale();
                final double pw = sampleSolarPanel.isRotated() ? sampleSolarPanel.getPanelHeight() : sampleSolarPanel.getPanelWidth();
                if (rw > pw) {
                    final Vector3 delta = toRelativeVector(p.subtract(pEdit, null)).multiplyLocal(0.5);
                    points.get(0).addLocal(delta);
                    getEditPointShape(editPointIndex).setTranslation(p);
                    setRackWidth(rw);
                    if (outOfBound()) {
                        if (oldRackCenter != null) {
                            points.get(0).set(oldRackCenter);
                        }
                        setRackWidth(oldRackWidth);
                    } else {
                        oldRackCenter = points.get(0).clone();
                        oldRackWidth = rackWidth;
                    }
                }
            }
        } else {
            final ReadOnlyVector3 p1 = getEditPointShape(editPointIndex == 1 ? 3 : 1).getTranslation();
            p = Util.closestPoint(pEdit, pEdit.subtract(p1, null).normalizeLocal(), x, y);
            if (p != null) {
                final double rh = p.distance(p1) * Scene.getInstance().getAnnotationScale();
                final double ph = sampleSolarPanel.isRotated() ? sampleSolarPanel.getPanelWidth() : sampleSolarPanel.getPanelHeight();
                if (rh > ph) {
                    final Vector3 delta = toRelativeVector(p.subtract(pEdit, null)).multiplyLocal(0.5);
                    points.get(0).addLocal(delta);
                    getEditPointShape(editPointIndex).setTranslation(p);
                    setRackHeight(rh);
                    if (outOfBound()) {
                        if (oldRackCenter != null) {
                            points.get(0).set(oldRackCenter);
                        }
                        setRackHeight(oldRackHeight);
                    } else {
                        oldRackCenter = points.get(0).clone();
                        oldRackHeight = rackHeight;
                    }
                }
            }
        }
    }
    if (container != null) {
        draw();
        drawChildren();
        setEditPointsVisible(true);
        setHighlight(!isDrawable());
    }
}
Also used : ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) Vector3(com.ardor3d.math.Vector3)

Example 18 with ReadOnlyVector3

use of com.ardor3d.math.type.ReadOnlyVector3 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 19 with ReadOnlyVector3

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

the class Roof method drawOutline.

protected void drawOutline() {
    if (container == null) {
        return;
    }
    for (final Spatial roofPart : roofPartsRoot.getChildren()) {
        if (roofPart.getSceneHints().getCullHint() != CullHint.Always) {
            final Node roofPartNode = (Node) roofPart;
            final Mesh outlineMesh = (Mesh) roofPartNode.getChild(4);
            final Mesh mesh = (Mesh) roofPartNode.getChild(0);
            final ArrayList<ReadOnlyVector3> outlinePoints = MeshLib.computeOutline(mesh.getMeshData().getVertexBuffer());
            int totalVertices = outlinePoints.size();
            for (final HousePart part : children) {
                if (part instanceof Window) {
                    totalVertices += 8;
                }
            }
            final FloatBuffer buf;
            if (outlineMesh.getMeshData().getVertexBuffer().capacity() >= totalVertices * 2 * 3) {
                buf = outlineMesh.getMeshData().getVertexBuffer();
                buf.limit(buf.capacity());
                buf.rewind();
            } else {
                buf = BufferUtils.createVector3Buffer(totalVertices * 2);
                outlineMesh.getMeshData().setVertexBuffer(buf);
            }
            // draw roof outline
            for (int i = 0; i < outlinePoints.size(); i++) {
                final ReadOnlyVector3 p1 = outlinePoints.get(i);
                final ReadOnlyVector3 p2 = outlinePoints.get((i + 1) % outlinePoints.size());
                buf.put(p1.getXf()).put(p1.getYf()).put(p1.getZf());
                buf.put(p2.getXf()).put(p2.getYf()).put(p2.getZf());
            }
            // draw skylights outline
            final int[] windowIndices = new int[] { 0, 2, 3, 1 };
            for (final HousePart part : children) {
                if (part instanceof Window && part.isDrawable() && ((Window) part).getRoofIndex() == ((UserData) mesh.getUserData()).getEditPointIndex()) {
                    for (int i = 0; i < part.getPoints().size(); i++) {
                        final ReadOnlyVector3 p1 = part.getAbsPoint(windowIndices[i]);
                        final ReadOnlyVector3 p2 = part.getAbsPoint(windowIndices[(i + 1) % part.getPoints().size()]);
                        buf.put(p1.getXf()).put(p1.getYf()).put(p1.getZf());
                        buf.put(p2.getXf()).put(p2.getYf()).put(p2.getZf());
                    }
                }
            }
            buf.limit(buf.position());
            outlineMesh.getMeshData().updateVertexCount();
            outlineMesh.updateModelBound();
        }
    }
}
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) CullHint(com.ardor3d.scenegraph.hint.CullHint) TPoint(org.poly2tri.triangulation.point.TPoint) TriangulationPoint(org.poly2tri.triangulation.TriangulationPoint) PolygonPoint(org.poly2tri.geometry.polygon.PolygonPoint)

Example 20 with ReadOnlyVector3

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

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