Search in sources :

Example 41 with Vector3

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

the class Human method setPreviewPoint.

@Override
public void setPreviewPoint(final int x, final int y) {
    final PickedHousePart pick = SelectUtil.pickPart(x, y, new Class<?>[] { Foundation.class, Floor.class, null });
    if (pick != null) {
        final Vector3 p = pick.getPoint().clone();
        snapToGrid(p, getAbsPoint(0), getGridSize(), false);
        points.get(0).set(toRelative(p));
        root.getSceneHints().setCullHint(CullHint.Never);
    }
    draw();
    setEditPointsVisible(true);
}
Also used : Vector3(com.ardor3d.math.Vector3)

Example 42 with Vector3

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

the class FoundationPolygon method getIntersectingPoints.

public List<Point2D.Double> getIntersectingPoints(final Vector3 v1, final Vector3 v2) {
    final List<Point2D.Double> intersections = new ArrayList<Point2D.Double>();
    final int n = points.size() / 2;
    Vector3 p1, p2;
    for (int i = 0; i < n - 1; i++) {
        // use only the first half of the vertices from the polygon
        p1 = getAbsPoint(i);
        p2 = getAbsPoint(i + 1);
        final Point2D.Double pd = Util.segmentIntersects(p1.getX(), p1.getY(), p2.getX(), p2.getY(), v1.getX(), v1.getY(), v2.getX(), v2.getY());
        if (pd != null) {
            intersections.add(pd);
        }
    }
    p1 = getAbsPoint(n - 1);
    p2 = getAbsPoint(0);
    final Point2D.Double pd = Util.segmentIntersects(p1.getX(), p1.getY(), p2.getX(), p2.getY(), v1.getX(), v1.getY(), v2.getX(), v2.getY());
    if (pd != null) {
        intersections.add(pd);
    }
    return intersections;
}
Also used : Point2D(java.awt.geom.Point2D) ArrayList(java.util.ArrayList) Vector3(com.ardor3d.math.Vector3) CullHint(com.ardor3d.scenegraph.hint.CullHint)

Example 43 with Vector3

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

the class FresnelReflector method checkCopyOverlap.

private double checkCopyOverlap(final boolean inWidth) {
    // copy only in the direction of module width
    final double w1 = (inWidth ? moduleWidth : length) / Scene.getInstance().getAnnotationScale();
    final Vector3 center = getAbsCenter();
    for (final HousePart p : Scene.getInstance().getParts()) {
        if (p.container == container && p != this) {
            if (p instanceof FresnelReflector) {
                final FresnelReflector s2 = (FresnelReflector) p;
                final double w2 = (inWidth ? s2.moduleWidth : s2.length) / Scene.getInstance().getAnnotationScale();
                final double distance = p.getAbsCenter().distance(center);
                if (distance < (w1 + w2) * 0.499) {
                    return distance;
                }
            }
        }
    }
    return -1;
}
Also used : ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) Vector3(com.ardor3d.math.Vector3)

Example 44 with Vector3

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

the class FresnelReflector method move.

@Override
public void move(final Vector3 v, final double steplength) {
    if (lockEdit) {
        return;
    }
    v.normalizeLocal().multiplyLocal(steplength);
    final Vector3 v_rel = toRelativeVector(v);
    points.get(0).addLocal(v_rel);
    draw();
    if (outOfBound()) {
        if (oldReflectorCenter != null) {
            points.get(0).set(oldReflectorCenter);
        }
    } else {
        oldReflectorCenter = points.get(0).clone();
    }
}
Also used : ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) Vector3(com.ardor3d.math.Vector3)

Example 45 with Vector3

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

the class FresnelReflector method isPositionLegal.

private boolean isPositionLegal(final FresnelReflector reflector, final Foundation foundation) {
    final Vector3 p0 = foundation.getAbsPoint(0);
    final Vector3 p1 = foundation.getAbsPoint(1);
    final Vector3 p2 = foundation.getAbsPoint(2);
    final double a = -Math.toRadians(relativeAzimuth) * Math.signum(p2.subtract(p0, null).getX() * p1.subtract(p0, null).getY());
    final Vector3 v = new Vector3(Math.cos(Math.PI / 2 + a), Math.sin(Math.PI / 2 + a), 0);
    double len;
    double s;
    boolean inWidth = true;
    final FresnelReflector nearest = foundation.getNearestFresnelReflector(this);
    if (nearest != null) {
        // use the nearest reflector as the reference to infer next position
        final Vector3 d = getAbsCenter().subtractLocal(nearest.getAbsCenter());
        len = d.length();
        if (moduleWidth > len * Scene.getInstance().getAnnotationScale()) {
            inWidth = false;
        }
        if (len > Math.min(moduleWidth, length) * 5 / Scene.getInstance().getAnnotationScale()) {
            len = (1 + copyLayoutGap) * moduleWidth / Scene.getInstance().getAnnotationScale();
            s = Math.signum(foundation.getAbsCenter().subtractLocal(Scene.getInstance().getOriginalCopy().getAbsCenter()).dot(v));
        } else {
            final double vx = v.getX();
            final double vy = v.getY();
            if (Math.abs(d.getX()) > Math.abs(d.getY())) {
                if (Math.abs(vx) < Math.abs(vy)) {
                    v.setX(vy);
                    v.setY(vx);
                }
            } else {
                if (Math.abs(vx) > Math.abs(vy)) {
                    v.setX(vy);
                    v.setY(vx);
                }
            }
            s = Math.signum(d.dot(v));
        }
    } else {
        len = (1 + copyLayoutGap) * moduleWidth / Scene.getInstance().getAnnotationScale();
        s = Math.signum(foundation.getAbsCenter().subtractLocal(Scene.getInstance().getOriginalCopy().getAbsCenter()).dot(v));
    }
    final double tx = len / p0.distance(p2);
    final double ty = len / p0.distance(p1);
    final double lx = s * v.getX() * tx;
    final double ly = s * v.getY() * ty;
    final double newX = points.get(0).getX() + lx;
    if (newX > 1 - tx || newX < tx) {
        return false;
    }
    final double newY = points.get(0).getY() + ly;
    if (newY > 1 - ty || newY < ty) {
        return false;
    }
    reflector.points.get(0).setX(newX);
    reflector.points.get(0).setY(newY);
    final double o = reflector.checkCopyOverlap(inWidth);
    if (o >= 0) {
        JOptionPane.showMessageDialog(MainFrame.getInstance(), "Sorry, your new reflector is too close to an existing one (" + o + ").", "Error", JOptionPane.ERROR_MESSAGE);
        return false;
    }
    return true;
}
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