Search in sources :

Example 11 with ReadOnlyVector3

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

the class HousePart method toRelative.

public Vector3 toRelative(final ReadOnlyVector3 p) {
    final HousePart container = getContainerRelative();
    if (container == null) {
        return p.clone();
    }
    final Vector3 p0 = container.getAbsPoint(0);
    final Vector3 p1 = container.getAbsPoint(1);
    final Vector3 p2 = container.getAbsPoint(2);
    final Vector2 p_2d = new Vector2(p.getX(), p.getY());
    final Vector2 p0_2d = new Vector2(p0.getX(), p0.getY());
    final double uScale = Util.projectPointOnLineScale(p_2d, p0_2d, new Vector2(p2.getX(), p2.getY()));
    final double vScale;
    final boolean relativeToHorizontal = getContainerRelative().isHorizontal();
    if (relativeToHorizontal) {
        vScale = Util.projectPointOnLineScale(p_2d, p0_2d, new Vector2(p1.getX(), p1.getY()));
        return new Vector3(uScale, vScale, p.getZ());
    } else {
        vScale = Util.projectPointOnLineScale(new Vector2(0, p.getZ()), new Vector2(0, p0.getZ()), new Vector2(0, p1.getZ()));
        return new Vector3(uScale, 0.0, vScale);
    }
}
Also used : Vector2(com.ardor3d.math.Vector2) ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) Vector3(com.ardor3d.math.Vector3)

Example 12 with ReadOnlyVector3

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

the class HousePart method toAbsolute.

protected Vector3 toAbsolute(final ReadOnlyVector3 p, final Vector3 result) {
    final HousePart container = getContainerRelative();
    if (container == null) {
        return result == null ? new Vector3(p) : result.set(p);
    }
    final Vector3 u = Vector3.fetchTempInstance();
    final Vector3 v = Vector3.fetchTempInstance();
    final Vector3 p0 = Vector3.fetchTempInstance();
    Vector3 pointOnSpace;
    try {
        container.getAbsPoint(0, p0);
        container.getAbsPoint(2, u).subtract(p0, u);
        if (Util.isZero(u.length())) {
            u.set(MathUtils.ZERO_TOLERANCE, 0, 0);
        }
        container.getAbsPoint(1, v).subtract(p0, v);
        final boolean relativeToHorizontal = getContainerRelative().isHorizontal();
        if (Util.isZero(v.length())) {
            v.set(0, relativeToHorizontal ? MathUtils.ZERO_TOLERANCE : 0, relativeToHorizontal ? 0 : MathUtils.ZERO_TOLERANCE);
        }
        pointOnSpace = p0.add(u.multiply(p.getX(), u), u).add(v.multiply((relativeToHorizontal) ? p.getY() : p.getZ(), v), result);
        if (relativeToHorizontal) {
            pointOnSpace.setZ(pointOnSpace.getZ() + p.getZ());
        }
    } finally {
        Vector3.releaseTempInstance(u);
        Vector3.releaseTempInstance(v);
        Vector3.releaseTempInstance(p0);
    }
    /* do not round the result, otherwise neighboring walls won't have exact same edit points */
    return pointOnSpace;
}
Also used : ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) Vector3(com.ardor3d.math.Vector3)

Example 13 with ReadOnlyVector3

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

the class GambrelRoof method computeEditPoints.

private Vector3[] computeEditPoints(final Wall wall) {
    final Vector3 p1 = wall.getAbsPoint(1);
    final Vector3 p2 = wall.getAbsPoint(3);
    ReadOnlyVector3 p1_overhang = null;
    ReadOnlyVector3 p2_overhang = null;
    double minDistance = Double.MAX_VALUE;
    for (int i = 0; i < wallUpperPoints.size(); i++) {
        final ReadOnlyVector3 pi = wallUpperPoints.get(i);
        final ReadOnlyVector3 pi2 = wallUpperPoints.get((i + 1) % wallUpperPoints.size());
        final double distance1 = p1.distance(pi) + p2.distance(pi2);
        final double distance2 = p1.distance(pi2) + p2.distance(pi);
        if (distance1 < minDistance || distance2 < minDistance) {
            if (distance1 < distance2) {
                p1_overhang = pi;
                p2_overhang = pi2;
                minDistance = distance1;
            } else {
                p1_overhang = pi2;
                p2_overhang = pi;
                minDistance = distance2;
            }
        }
    }
    p1.set(p1_overhang);
    p2.set(p2_overhang);
    final Vector3 p1p2 = p2.subtractLocal(p1);
    final Vector3[] result = new Vector3[3];
    final Vector3 n = wall.getNormal().multiply(-0.1, null);
    result[0] = toRelative(p1p2.multiply(0.25, null).addLocal(p1).addLocal(n));
    result[1] = toRelative(p1p2.multiply(0.5, null).addLocal(p1).addLocal(n));
    result[2] = toRelative(p1p2.multiply(0.75, null).addLocal(p1).addLocal(n));
    return result;
}
Also used : ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) Vector3(com.ardor3d.math.Vector3)

Example 14 with ReadOnlyVector3

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

the class AngleAnnotation method draw.

@Override
public void draw() {
    final ReadOnlyVector3 a = new Vector3().set(p2).subtractLocal(mainPoint).normalizeLocal();
    final ReadOnlyVector3 b = new Vector3().set(p3).subtractLocal(mainPoint).normalizeLocal();
    final ReadOnlyVector3 axis = n.cross(Vector3.UNIT_Z, null).normalizeLocal();
    final Matrix3 toFlat = new Matrix3().fromAngleAxis(Util.angleBetween(n, Vector3.UNIT_Z, n.cross(Vector3.UNIT_Z, null).normalizeLocal()), axis);
    final ReadOnlyVector3 aFlat = toFlat.applyPost(a, null);
    final ReadOnlyVector3 bFlat = toFlat.applyPost(b, null);
    double start, angle;
    if (Util.angleBetween(aFlat, bFlat, Vector3.UNIT_Z) >= 0) {
        start = Util.angleBetween(Vector3.UNIT_X, aFlat, Vector3.UNIT_Z);
        angle = Util.angleBetween(aFlat, bFlat, Vector3.UNIT_Z);
    } else {
        start = Util.angleBetween(Vector3.UNIT_X, bFlat, Vector3.UNIT_Z);
        angle = Util.angleBetween(bFlat, aFlat, Vector3.UNIT_Z);
    }
    double end = start + angle;
    final long angleDegrees = Math.round(Math.toDegrees(end - start));
    final double radius = customRadius > 0 ? customRadius : (end == start ? 0.0 : 3.0 / Math.sqrt(end - start));
    if (angleDegrees == 90) {
        final ReadOnlyVector3[] p = new ReadOnlyVector3[3];
        p[0] = a.normalize(null).multiplyLocal(2.0);
        p[1] = a.normalize(null).addLocal(b.normalize(null)).multiplyLocal(2.0);
        p[2] = b.normalize(null).multiplyLocal(2.0);
        final FloatBuffer buf = mesh.getMeshData().getVertexBuffer();
        buf.rewind();
        buf.limit(9);
        mesh.getMeshData().updateVertexCount();
        buf.rewind();
        for (final ReadOnlyVector3 v : p) {
            buf.put(v.getXf()).put(v.getYf()).put(v.getZf());
        }
        mesh.setRotation(new Matrix3());
        detachChild(label);
    } else {
        boolean special = false;
        if ("A".equals(customText) && Util.isEqual(start, Math.PI / 2)) {
            // special case for azimuth
            angle = angle - Math.PI * 2;
            if (Util.isEqual(Math.abs(angle), 2 * Math.PI)) {
                angle = 0;
            }
            end = start + angle;
            label.setText("A=" + (angleDegrees == 0 ? 0 : (360 - angleDegrees)) + "\u00B0");
            special = true;
        } else {
            label.setText((customText != null ? customText + "=" : "") + angleDegrees + "\u00B0");
        }
        ((Arc) mesh).set(radius, start, end);
        mesh.setRotation(toFlat.invertLocal());
        final double start360 = start < 0 ? MathUtils.TWO_PI + start : start;
        final double angle360 = angle < 0 ? MathUtils.TWO_PI + angle : angle;
        final double end360 = start360 + angle360;
        final Matrix3 rotMatrix = toFlat.multiplyLocal(new Matrix3().fromAngles(-Math.PI / 2, 0, (special ? Math.PI / 2 : -Math.PI / 2) + (start360 + end360) / 2));
        label.setRotation(rotMatrix);
        final Vector3 trans = new Vector3(0, 0, radius / 1.7);
        label.setTranslation(rotMatrix.applyPost(trans, trans));
        attachChild(label);
    }
    mesh.updateModelBound();
    this.setTranslation(mainPoint);
}
Also used : ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) Vector3(com.ardor3d.math.Vector3) FloatBuffer(java.nio.FloatBuffer) Matrix3(com.ardor3d.math.Matrix3)

Example 15 with ReadOnlyVector3

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

the class SizeAnnotation method draw.

@Override
public void draw() {
    final double C = 1.0;
    final Vector3 v = new Vector3();
    final Vector3 offset = new Vector3();
    if (front && !drawInside)
        offset.set(faceDirection).normalizeLocal().multiplyLocal(C).addLocal(0, 0, 0.05);
    else {
        offset.set(to).subtractLocal(from).normalizeLocal().crossLocal(faceDirection).multiplyLocal(C);
        if (autoFlipOffset) {
            v.set(from).subtractLocal(center).normalizeLocal();
            if (v.dot(offset) < 0)
                offset.negateLocal();
        }
    }
    if (drawInside)
        offset.negateLocal();
    final ReadOnlyVector3 dir = to.subtract(from, null).normalizeLocal();
    final int scale = upsideDownText ? -1 : 1;
    final Vector3 xdir = dir.multiply(scale, null);
    final Vector3 ydir = faceDirection.normalize(null);
    final Vector3 zdir = ydir.cross(xdir, null).normalizeLocal();
    zdir.cross(ydir, xdir);
    if (zdir.dot(Vector3.UNIT_Z) < 0) {
        zdir.negateLocal();
        xdir.negateLocal();
    }
    final Matrix3 matrix = new Matrix3().fromAxes(xdir, ydir, zdir);
    label.setRotation(matrix);
    FloatBuffer vertexBuffer = mesh.getMeshData().getVertexBuffer();
    vertexBuffer.rewind();
    // main line
    final Vector3 newFrom = new Vector3(from).addLocal(offset);
    final Vector3 newTo = new Vector3(to).addLocal(offset);
    final Vector3 middle = new Vector3(newFrom).addLocal(newTo).multiplyLocal(0.5);
    final Vector3 body = new Vector3(to).subtractLocal(from).multiplyLocal(0.5);
    label.setTranslation(middle);
    final DecimalFormat df = new DecimalFormat("#.##");
    double length = to.subtract(from, null).length() * Scene.getInstance().getAnnotationScale();
    switch(Scene.getInstance().getUnit()) {
        case InternationalSystemOfUnits:
            label.setText(df.format(length) + " m");
            break;
        case USCustomaryUnits:
            label.setText(df.format(length * 3.28084) + " ft");
            break;
    }
    label.setAlign(align);
    label.updateWorldTransform(true);
    label.updateWorldBound(true);
    vertexBuffer.put(newFrom.getXf()).put(newFrom.getYf()).put(newFrom.getZf());
    final double bankSpace = label.getWidth() * 0.70;
    final double blankSpaceFactor = Math.max(0, body.length() - bankSpace) / body.length();
    v.set(body).multiplyLocal(blankSpaceFactor).addLocal(newFrom);
    vertexBuffer.put(v.getXf()).put(v.getYf()).put(v.getZf());
    v.set(body).multiplyLocal(-blankSpaceFactor).addLocal(newTo);
    vertexBuffer.put(v.getXf()).put(v.getYf()).put(v.getZf());
    vertexBuffer.put(newTo.getXf()).put(newTo.getYf()).put(newTo.getZf());
    offset.multiplyLocal(0.5);
    // from End
    v.set(from);
    vertexBuffer.put(v.getXf()).put(v.getYf()).put(v.getZf());
    v.set(newFrom).addLocal(offset);
    vertexBuffer.put(v.getXf()).put(v.getYf()).put(v.getZf());
    // to End
    v.set(to);
    vertexBuffer.put(v.getXf()).put(v.getYf()).put(v.getZf());
    v.set(newTo).addLocal(offset);
    vertexBuffer.put(v.getXf()).put(v.getYf()).put(v.getZf());
    // arrow
    offset.multiplyLocal(0.5);
    body.set(to).subtractLocal(from).normalizeLocal().multiplyLocal(0.5);
    mesh.updateModelBound();
    vertexBuffer = arrows.getMeshData().getVertexBuffer();
    vertexBuffer.rewind();
    // arrow from
    v.set(newFrom);
    vertexBuffer.put(v.getXf()).put(v.getYf()).put(v.getZf());
    v.addLocal(offset).addLocal(body);
    vertexBuffer.put(v.getXf()).put(v.getYf()).put(v.getZf());
    v.set(newFrom).subtractLocal(offset).addLocal(body);
    vertexBuffer.put(v.getXf()).put(v.getYf()).put(v.getZf());
    // arrow to
    body.negateLocal();
    v.set(newTo);
    vertexBuffer.put(v.getXf()).put(v.getYf()).put(v.getZf());
    v.addLocal(offset).addLocal(body);
    vertexBuffer.put(v.getXf()).put(v.getYf()).put(v.getZf());
    v.set(newTo).subtractLocal(offset).addLocal(body);
    vertexBuffer.put(v.getXf()).put(v.getYf()).put(v.getZf());
    arrows.updateModelBound();
    updateWorldTransform(true);
    updateWorldBound(true);
}
Also used : ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) DecimalFormat(java.text.DecimalFormat) ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) Vector3(com.ardor3d.math.Vector3) FloatBuffer(java.nio.FloatBuffer) Matrix3(com.ardor3d.math.Matrix3)

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