Search in sources :

Example 36 with Vector3

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

the class HousePart method getAbsCenter.

public Vector3 getAbsCenter() {
    double x = 0, y = 0, z = 0;
    final int n = points.size();
    for (int i = 0; i < n; i++) {
        final Vector3 v = getAbsPoint(i);
        x += v.getX();
        y += v.getY();
        z += v.getZ();
    }
    final double invert = 1.0 / n;
    return new Vector3(x * invert, y * invert, z * invert);
}
Also used : ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) Vector3(com.ardor3d.math.Vector3) CullHint(com.ardor3d.scenegraph.hint.CullHint)

Example 37 with Vector3

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

the class HousePart method flatten.

public void flatten(final double flattenTime) {
    if (isPrintable()) {
        if (isPrintVertical) {
            root.setRotation(new Matrix3().fromAngles(0, -Math.PI / 2.0 * flattenTime, 0).multiply(root.getRotation(), null));
        }
        final Vector3 targetCenter = new Vector3(((UserData) mesh.getUserData()).getPrintCenter());
        root.setTranslation(targetCenter.subtractLocal(flattenCenter).multiplyLocal(flattenTime));
        root.updateGeometricState(0);
    }
}
Also used : ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) Vector3(com.ardor3d.math.Vector3) Matrix3(com.ardor3d.math.Matrix3)

Example 38 with Vector3

use of com.ardor3d.math.Vector3 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 39 with Vector3

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

the class HousePart method updateEditShapes.

public void updateEditShapes() {
    final Vector3 p = Vector3.fetchTempInstance();
    try {
        for (int i = 0; i < points.size(); i++) {
            getAbsPoint(i, p);
            if (!Double.isFinite(p.getZ())) {
                p.setZ(1000);
            }
            getEditPointShape(i).setTranslation(p);
        }
        for (int i = 0; i < pointsRoot.getNumberOfChildren(); i++) {
            final Camera camera = SceneManager.getInstance().getCamera();
            if (camera != null && camera.getProjectionMode() != ProjectionMode.Parallel) {
                final double distance = camera.getLocation().distance(getEditPointShape(i).getTranslation());
                getEditPointShape(i).setScale(distance > 0.1 ? distance / 10 : 0.01);
            } else {
                getEditPointShape(i).setScale(camera.getFrustumTop() / 4);
            }
        }
    } finally {
        Vector3.releaseTempInstance(p);
    }
// /* remove remaining edit shapes */
// for (int i = points.size(); i < pointsRoot.getNumberOfChildren(); i++) {
// pointsRoot.detachChildAt(points.size());
// }
}
Also used : ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) Vector3(com.ardor3d.math.Vector3) Camera(com.ardor3d.renderer.Camera) CullHint(com.ardor3d.scenegraph.hint.CullHint)

Example 40 with Vector3

use of com.ardor3d.math.Vector3 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)

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