Search in sources :

Example 6 with ReadOnlyVector2

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

the class Foundation method ensureIncludesChildren.

private void ensureIncludesChildren(final Vector3 p, final int index) {
    if (children.isEmpty()) {
        return;
    }
    useOrgPoints = true;
    final List<Vector2> insidePoints = new ArrayList<Vector2>(children.size() * 2);
    for (final HousePart part : children) {
        if (part.children.size() > 2 && part.getPoints().size() > 1) {
            final Vector3 p0 = part.getAbsPoint(0);
            final Vector3 p2 = part.getAbsPoint(2);
            insidePoints.add(new Vector2(p0.getX(), p0.getY()));
            insidePoints.add(new Vector2(p2.getX(), p2.getY()));
        } else {
            // if the child is a solar panel, a rack, or a mirror
            final Vector3 p0 = part.getAbsPoint(0);
            insidePoints.add(new Vector2(p0.getX(), p0.getY()));
        }
    }
    final Vector3 p0 = getAbsPoint(0);
    final Vector3 p1 = getAbsPoint(1);
    final Vector3 p2 = getAbsPoint(2);
    final ReadOnlyVector2 p0_2d = new Vector2(p0.getX(), p0.getY());
    final ReadOnlyVector2 p1_2d = new Vector2(p1.getX(), p1.getY());
    final ReadOnlyVector2 p2_2d = new Vector2(p2.getX(), p2.getY());
    useOrgPoints = false;
    double uScaleMin = Double.MAX_VALUE;
    double uScaleMax = -Double.MAX_VALUE;
    double vScaleMin = Double.MAX_VALUE;
    double vScaleMax = -Double.MAX_VALUE;
    for (final Vector2 insidePoint : insidePoints) {
        final double uScale = Util.projectPointOnLineScale(insidePoint, p0_2d, p2_2d);
        if (uScaleMin > uScale) {
            uScaleMin = uScale;
        }
        if (uScaleMax < uScale) {
            uScaleMax = uScale;
        }
        final double vScale = Util.projectPointOnLineScale(insidePoint, p0_2d, p1_2d);
        if (vScaleMin > vScale) {
            vScaleMin = vScale;
        }
        if (vScaleMax < vScale) {
            vScaleMax = vScale;
        }
    }
    final double uScaleP = Util.projectPointOnLineScale(new Vector2(p.getX(), p.getY()), p0_2d, p2_2d);
    final double vScaleP = Util.projectPointOnLineScale(new Vector2(p.getX(), p.getY()), p0_2d, p1_2d);
    final double uScaleP0 = Util.projectPointOnLineScale(new Vector2(points.get(0).getX(), points.get(0).getY()), p0_2d, p2_2d);
    final double uScaleP2 = Util.projectPointOnLineScale(new Vector2(points.get(2).getX(), points.get(2).getY()), p0_2d, p2_2d);
    final double vScaleP0 = Util.projectPointOnLineScale(new Vector2(points.get(0).getX(), points.get(0).getY()), p0_2d, p1_2d);
    final double vScaleP1 = Util.projectPointOnLineScale(new Vector2(points.get(1).getX(), points.get(1).getY()), p0_2d, p1_2d);
    final boolean isOnRight = uScaleP2 >= uScaleP0 && (index == 2 || index == 3);
    final boolean isOnTop = vScaleP1 >= vScaleP0 && (index == 1 || index == 3);
    final double uScale;
    if (isOnRight && uScaleP < uScaleMax) {
        uScale = uScaleMax;
    } else if (!isOnRight && uScaleP > uScaleMin) {
        uScale = uScaleMin;
    } else {
        uScale = uScaleP;
    }
    final double vScale;
    if (isOnTop && vScaleP < vScaleMax) {
        vScale = vScaleMax;
    } else if (!isOnTop && vScaleP > vScaleMin) {
        vScale = vScaleMin;
    } else {
        vScale = vScaleP;
    }
    final Vector3 u = p2.subtract(p0, null);
    final Vector3 v = p1.subtract(p0, null);
    p.set(p0).addLocal(u.multiplyLocal(uScale)).addLocal(v.multiplyLocal(vScale));
}
Also used : ReadOnlyVector2(com.ardor3d.math.type.ReadOnlyVector2) ReadOnlyVector2(com.ardor3d.math.type.ReadOnlyVector2) Vector2(com.ardor3d.math.Vector2) ArrayList(java.util.ArrayList) ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) Vector3(com.ardor3d.math.Vector3)

Example 7 with ReadOnlyVector2

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

the class Roof method snapToWallsPolygon.

protected void snapToWallsPolygon(final Vector3 p) {
    if (!insideWallsPolygon(p)) {
        final ReadOnlyVector2 p2D = Util.snapToPolygon(p, wallUpperPoints, wallNormals);
        p.set(p2D.getX(), p2D.getY(), p.getZ());
    }
}
Also used : ReadOnlyVector2(com.ardor3d.math.type.ReadOnlyVector2)

Aggregations

ReadOnlyVector2 (com.ardor3d.math.type.ReadOnlyVector2)7 ReadOnlyVector3 (com.ardor3d.math.type.ReadOnlyVector3)6 Vector3 (com.ardor3d.math.Vector3)5 ArrayList (java.util.ArrayList)5 Vector2 (com.ardor3d.math.Vector2)4 CullHint (com.ardor3d.scenegraph.hint.CullHint)3 TPoint (org.poly2tri.triangulation.point.TPoint)3 FloatBuffer (java.nio.FloatBuffer)2 PolygonPoint (org.poly2tri.geometry.polygon.PolygonPoint)2 TriangulationPoint (org.poly2tri.triangulation.TriangulationPoint)2 BoundingBox (com.ardor3d.bounding.BoundingBox)1 Canvas (com.ardor3d.framework.Canvas)1 Texture (com.ardor3d.image.Texture)1 KeyboardState (com.ardor3d.input.KeyboardState)1 MouseState (com.ardor3d.input.MouseState)1 InputTrigger (com.ardor3d.input.logical.InputTrigger)1 KeyHeldCondition (com.ardor3d.input.logical.KeyHeldCondition)1 KeyPressedCondition (com.ardor3d.input.logical.KeyPressedCondition)1 KeyReleasedCondition (com.ardor3d.input.logical.KeyReleasedCondition)1 MouseButtonClickedCondition (com.ardor3d.input.logical.MouseButtonClickedCondition)1