Search in sources :

Example 31 with Vector3

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

the class FoundationPolygon method complete.

@Override
public void complete() {
    // remove unnecessary points
    int n = points.size() / 2;
    final Vector3 v1 = new Vector3();
    final Vector3 v2 = new Vector3();
    for (int i = 0; i < n; i++) {
        points.get((i + 1) % n).subtract(points.get(i), v1).normalizeLocal();
        points.get((i + 2) % n).subtract(points.get((i + 1) % n), v2).normalizeLocal();
        if (v1.dot(v2) > 0.995) {
            points.remove((i + 1) % n);
            points.remove(points.size() - 1);
            i--;
            n--;
        }
    }
    super.complete();
}
Also used : Vector3(com.ardor3d.math.Vector3) CullHint(com.ardor3d.scenegraph.hint.CullHint)

Example 32 with Vector3

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

the class FoundationPolygon method setPreviewPoint.

@Override
public void setPreviewPoint(final int x, final int y) {
    final PickedHousePart pick = SelectUtil.pickPart(x, y, container);
    Vector3 p;
    if (pick != null) {
        p = pick.getPoint().clone();
        p.setZ(container.getHeight());
        final Vector3 relativeP = toRelative(p);
        final int n = points.size() / 2;
        if (editPointIndex < n) {
            points.get(editPointIndex).set(relativeP);
        } else {
            if (SelectUtil.getCurrentEditPointMesh() != null) {
                SelectUtil.getCurrentEditPointMesh().setDefaultColor(ColorRGBA.WHITE);
            }
            editPointIndex -= n;
            final Mesh editPointShape = getEditPointShape(editPointIndex);
            SelectUtil.setCurrentEditPointMesh(editPointShape);
            editPointShape.setDefaultColor(ColorRGBA.RED);
            points.add(editPointIndex, relativeP);
            points.add(new Vector3());
            setEditPointsVisible(true);
        }
        draw();
    }
}
Also used : Mesh(com.ardor3d.scenegraph.Mesh) Vector3(com.ardor3d.math.Vector3) CullHint(com.ardor3d.scenegraph.hint.CullHint)

Example 33 with Vector3

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

the class FoundationPolygon method getBounds.

public double[] getBounds() {
    double xmin = Double.MAX_VALUE;
    double xmax = -Double.MAX_VALUE;
    double ymin = Double.MAX_VALUE;
    double ymax = -Double.MAX_VALUE;
    final int n = points.size() / 2;
    for (int i = 0; i < n; i++) {
        // use only the first half of the vertices from the polygon
        final Vector3 p = getAbsPoint(i);
        if (xmin > p.getX()) {
            xmin = p.getX();
        }
        if (xmax < p.getX()) {
            xmax = p.getX();
        }
        if (ymin > p.getY()) {
            ymin = p.getY();
        }
        if (ymax < p.getY()) {
            ymax = p.getY();
        }
    }
    return new double[] { xmin, xmax, ymin, ymax };
}
Also used : Vector3(com.ardor3d.math.Vector3) CullHint(com.ardor3d.scenegraph.hint.CullHint)

Example 34 with Vector3

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

the class HipRoof 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) {
        pickContainer(x, y, Wall.class);
        recalculateEditPoints = true;
    } else if (editPointIndex == 0) {
        final ReadOnlyVector3 base = getCenter();
        final Vector3 p = Util.closestPoint(base, Vector3.UNIT_Z, x, y);
        if (p != null) {
            snapToGrid(p, getAbsPoint(editPointIndex), getGridSize());
            height = Math.max(0, p.getZ() - base.getZ());
        }
    } else if (editPointIndex == 1 || editPointIndex == 2) {
        final Vector3 hipDirection = container.getAbsPoint(2).subtractLocal(container.getAbsPoint(0)).normalizeLocal();
        final Vector3 p = Util.closestPoint(getAbsPoint(0), hipDirection, x, y);
        if (p != null) {
            // snapToGrid(p, getAbsPoint(editPointIndex), getGridSize(), false);
            if (insideWallsPolygon(p)) {
                points.get(editPointIndex).set(toRelative(p));
            }
        }
    }
    postEdit(editState);
}
Also used : ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) Vector3(com.ardor3d.math.Vector3)

Example 35 with Vector3

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

the class HousePart method drawArrow.

protected void drawArrow(final ReadOnlyVector3 o, final ReadOnlyVector3 normal, final FloatBuffer arrowsVertices, final double heat) {
    if (this instanceof Wall) {
        final Wall wall = (Wall) this;
        for (final HousePart x : wall.children) {
            if (x instanceof Window || x instanceof Door) {
                final Vector3 vo = x.toRelative(o);
                double xmin = 2;
                double zmin = 2;
                double xmax = -2;
                double zmax = -2;
                for (final Vector3 a : x.points) {
                    if (a.getX() > xmax) {
                        xmax = a.getX();
                    }
                    if (a.getZ() > zmax) {
                        zmax = a.getZ();
                    }
                    if (a.getX() < xmin) {
                        xmin = a.getX();
                    }
                    if (a.getZ() < zmin) {
                        zmin = a.getZ();
                    }
                }
                if (vo.getX() > xmin && vo.getZ() > zmin && vo.getX() < xmax && vo.getZ() < zmax) {
                    return;
                }
            }
        }
    }
    arrowsVertices.put(o.getXf()).put(o.getYf()).put(o.getZf());
    final Vector3 p = new Vector3();
    normal.multiply(Scene.getInstance().getHeatVectorLength() * Math.abs(heat), p);
    final Vector3 p2 = new Vector3();
    o.add(p, p2);
    arrowsVertices.put(p2.getXf()).put(p2.getYf()).put(p2.getZf());
    if (heat < 0) {
        p2.set(o);
    }
    if (heat != 0) {
        final float arrowLength = 0.5f;
        p.normalizeLocal();
        final double sign = Math.signum(heat);
        if (this instanceof Roof) {
            final float px = (float) (p.getX() * arrowLength * sign);
            final float py = (float) (p.getY() * arrowLength * sign);
            final float pz = (float) (p.getZ() * arrowLength * sign);
            final float yp = -pz;
            final float zp = py;
            arrowsVertices.put(p2.getXf()).put(p2.getYf()).put(p2.getZf());
            arrowsVertices.put(p2.getXf() - px).put(p2.getYf() - py + yp * 0.25f).put(p2.getZf() - pz + zp * 0.25f);
            arrowsVertices.put(p2.getXf()).put(p2.getYf()).put(p2.getZf());
            arrowsVertices.put(p2.getXf() - px).put(p2.getYf() - py - yp * 0.25f).put(p2.getZf() - pz - zp * 0.25f);
        } else if (this instanceof Foundation) {
            final float cos = (float) (p.dot(Vector3.UNIT_X) * sign);
            final float sin = (float) (p.dot(Vector3.UNIT_Z) * sign);
            arrowsVertices.put(p2.getXf()).put(p2.getYf()).put(p2.getZf());
            arrowsVertices.put(p2.getXf() - arrowLength * cos).put(p2.getYf() - arrowLength * 0.5f).put(p2.getZf() - arrowLength * sin);
            arrowsVertices.put(p2.getXf()).put(p2.getYf()).put(p2.getZf());
            arrowsVertices.put(p2.getXf() - arrowLength * cos).put(p2.getYf() + arrowLength * 0.5f).put(p2.getZf() - arrowLength * sin);
        } else {
            final float cos = (float) (p.dot(Vector3.UNIT_X) * sign);
            final float sin = (float) (p.dot(Vector3.UNIT_Y) * sign);
            arrowsVertices.put(p2.getXf()).put(p2.getYf()).put(p2.getZf());
            arrowsVertices.put(p2.getXf() - arrowLength * cos).put(p2.getYf() - arrowLength * sin).put(p2.getZf() - arrowLength * 0.5f);
            arrowsVertices.put(p2.getXf()).put(p2.getYf()).put(p2.getZf());
            arrowsVertices.put(p2.getXf() - arrowLength * cos).put(p2.getYf() - arrowLength * sin).put(p2.getZf() + arrowLength * 0.5f);
        }
    }
}
Also used : ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) Vector3(com.ardor3d.math.Vector3)

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