Search in sources :

Example 21 with Vector2

use of com.ardor3d.math.Vector2 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 22 with Vector2

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

the class Roof method insideWalls.

public boolean insideWalls(final double x, final double y, final boolean init) {
    if (walls.isEmpty()) {
        return false;
    }
    if (init) {
        if (underlyingWallVerticesOnFoundation == null) {
            underlyingWallVerticesOnFoundation = new ArrayList<Vector2>();
        } else {
            underlyingWallVerticesOnFoundation.clear();
        }
        walls.get(0).visitNeighbors(new WallVisitor() {

            @Override
            public void visit(final Wall currentWall, final Snap prev, final Snap next) {
                int pointIndex = 0;
                if (next != null) {
                    pointIndex = next.getSnapPointIndexOf(currentWall);
                }
                pointIndex++;
                addUnderlyingWallVertex(currentWall.getAbsPoint(pointIndex == 1 ? 3 : 1));
                addUnderlyingWallVertex(currentWall.getAbsPoint(pointIndex));
            }

            private void addUnderlyingWallVertex(final ReadOnlyVector3 v3) {
                final Vector2 v2 = new Vector2(v3.getX(), v3.getY());
                boolean b = false;
                for (final Vector2 x : underlyingWallVerticesOnFoundation) {
                    if (Util.isEqual(x, v2)) {
                        b = true;
                        break;
                    }
                }
                if (!b) {
                    underlyingWallVerticesOnFoundation.add(v2);
                }
            }
        });
        if (underlyingWallPath == null) {
            underlyingWallPath = new Path2D.Double();
        } else {
            underlyingWallPath.reset();
        }
        final Vector2 v0 = underlyingWallVerticesOnFoundation.get(0);
        underlyingWallPath.moveTo(v0.getX(), v0.getY());
        for (int i = 1; i < underlyingWallVerticesOnFoundation.size(); i++) {
            final Vector2 v = underlyingWallVerticesOnFoundation.get(i);
            underlyingWallPath.lineTo(v.getX(), v.getY());
        }
        underlyingWallPath.lineTo(v0.getX(), v0.getY());
        underlyingWallPath.closePath();
    }
    return underlyingWallPath != null ? underlyingWallPath.contains(x, y) : false;
}
Also used : WallVisitor(org.concord.energy3d.util.WallVisitor) ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) ReadOnlyVector2(com.ardor3d.math.type.ReadOnlyVector2) Vector2(com.ardor3d.math.Vector2) Path2D(java.awt.geom.Path2D) CullHint(com.ardor3d.scenegraph.hint.CullHint) TPoint(org.poly2tri.triangulation.point.TPoint) TriangulationPoint(org.poly2tri.triangulation.TriangulationPoint) PolygonPoint(org.poly2tri.geometry.polygon.PolygonPoint)

Example 23 with Vector2

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

the class CustomRoof method setPreviewPoint.

@Override
public void setPreviewPoint(final int x, final int y) {
    final Foundation foundation = getTopContainer();
    if (foundation != null && foundation.getLockEdit()) {
        return;
    }
    final EditState editState = new EditState();
    if (editPointIndex == -1) {
        recalculateEditPoints = true;
        pickContainer(x, y, Wall.class);
    } else if (editPointIndex == 0) {
        final ReadOnlyVector3 base = getCenter();
        final Vector3 p = Util.closestPoint(base, Vector3.UNIT_Z, x, y);
        if (p == null) {
            return;
        }
        snapToGrid(p, getAbsPoint(editPointIndex), getGridSize());
        height = Math.max(0, p.getZ() - container.getPoints().get(1).getZ());
        final double z = container.getPoints().get(1).getZ() + height;
        for (final Vector3 v : points) {
            v.setZ(z);
        }
    } else {
        final Ray3 pickRay = SceneManager.getInstance().getCamera().getPickRay(new Vector2(x, y), false, null);
        final Vector3 p = new Vector3();
        if (pickRay.intersectsPlane(new Plane(Vector3.UNIT_Z, points.get(0).getZ()), p)) {
            snapToGrid(p, getAbsPoint(editPointIndex), getGridSize(), false);
            snapToWallsPolygon(p);
            points.get(editPointIndex).set(toRelative(p));
        }
    }
    postEdit(editState);
}
Also used : ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) Vector2(com.ardor3d.math.Vector2) Plane(com.ardor3d.math.Plane) ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) Vector3(com.ardor3d.math.Vector3) Ray3(com.ardor3d.math.Ray3)

Aggregations

Vector2 (com.ardor3d.math.Vector2)23 ReadOnlyVector3 (com.ardor3d.math.type.ReadOnlyVector3)15 Vector3 (com.ardor3d.math.Vector3)12 ReadOnlyVector2 (com.ardor3d.math.type.ReadOnlyVector2)10 Ray3 (com.ardor3d.math.Ray3)9 CullHint (com.ardor3d.scenegraph.hint.CullHint)8 TPoint (org.poly2tri.triangulation.point.TPoint)7 PolygonPoint (org.poly2tri.geometry.polygon.PolygonPoint)6 Point (org.poly2tri.geometry.primitives.Point)6 ArrayList (java.util.ArrayList)5 PickingHint (com.ardor3d.scenegraph.hint.PickingHint)4 HousePart (org.concord.energy3d.model.HousePart)4 PickedHousePart (org.concord.energy3d.model.PickedHousePart)4 PickResults (com.ardor3d.intersection.PickResults)3 PrimitivePickResults (com.ardor3d.intersection.PrimitivePickResults)3 Mesh (com.ardor3d.scenegraph.Mesh)3 Node (com.ardor3d.scenegraph.Node)3 Spatial (com.ardor3d.scenegraph.Spatial)3 FloatBuffer (java.nio.FloatBuffer)3 Canvas (com.ardor3d.framework.Canvas)2