Search in sources :

Example 56 with Vector3

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

the class Heliodon method drawSunRegion.

private void drawSunRegion() {
    final FloatBuffer buf = sunRegion.getMeshData().getVertexBuffer();
    buf.limit(buf.capacity());
    buf.rewind();
    final double declinationStep = 2.0 * TILT_ANGLE / DECLINATION_DIVISIONS;
    final double hourStep = MathUtils.TWO_PI / HOUR_DIVISIONS;
    int limit = 0;
    for (double declinationAngle = -TILT_ANGLE; declinationAngle < TILT_ANGLE - declinationStep / 2.0; declinationAngle += declinationStep) {
        for (double hourAngle = -Math.PI; hourAngle < Math.PI - hourStep / 2.0; hourAngle += hourStep) {
            double hourAngle2 = hourAngle + hourStep;
            double declinationAngle2 = declinationAngle + declinationStep;
            if (hourAngle2 > Math.PI) {
                hourAngle2 = Math.PI;
            }
            if (declinationAngle2 > TILT_ANGLE) {
                declinationAngle2 = TILT_ANGLE;
            }
            final Vector3 v1 = computeSunLocation(hourAngle, declinationAngle, latitude);
            final Vector3 v2 = computeSunLocation(hourAngle2, declinationAngle, latitude);
            final Vector3 v3 = computeSunLocation(hourAngle2, declinationAngle2, latitude);
            final Vector3 v4 = computeSunLocation(hourAngle, declinationAngle2, latitude);
            if (v1.getZ() >= 0 || v2.getZ() >= 0 || v3.getZ() >= 0 || v4.getZ() >= 0) {
                buf.put(v1.getXf()).put(v1.getYf()).put(v1.getZf()).put(v2.getXf()).put(v2.getYf()).put(v2.getZf()).put(v3.getXf()).put(v3.getYf()).put(v3.getZf()).put(v4.getXf()).put(v4.getYf()).put(v4.getZf());
                limit += 12;
            }
        }
    }
    buf.limit(limit);
    sunRegion.getMeshData().updateVertexCount();
    sunRegion.updateModelBound();
    sunRegion.updateGeometricState(0);
    dirtySunRegion = false;
}
Also used : FloatBuffer(java.nio.FloatBuffer) ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) Vector3(com.ardor3d.math.Vector3) CullHint(com.ardor3d.scenegraph.hint.CullHint)

Example 57 with Vector3

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

the class Heliodon method drawSun.

public void drawSun() {
    final Vector3 sunLocation = computeSunLocation(hourAngle, declinationAngle, latitude);
    setSunLocation(sunLocation);
}
Also used : ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) Vector3(com.ardor3d.math.Vector3)

Example 58 with Vector3

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

Example 59 with Vector3

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

the class Rack method findRotationMatrix.

private Matrix3 findRotationMatrix(final ReadOnlyVector3 v1, final ReadOnlyVector3 v2) {
    final double angle = v1.smallestAngleBetween(v2);
    final Vector3 axis = v1.cross(v2, null).normalizeLocal();
    final Matrix3 matrix = new Matrix3().fromAngleAxis(angle, axis);
    return matrix;
}
Also used : ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) Vector3(com.ardor3d.math.Vector3) Matrix3(com.ardor3d.math.Matrix3)

Example 60 with Vector3

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

the class Rack method outOfBound.

private boolean outOfBound() {
    drawMesh();
    if (container instanceof Foundation) {
        final Foundation foundation = (Foundation) container;
        final int n = Math.round(mesh.getMeshData().getVertexBuffer().limit() / 3);
        for (int i = 0; i < n; i++) {
            final Vector3 a = getVertex(i);
            if (a.getZ() < foundation.getHeight() * 1.1) {
                // left a 10% margin above the foundation
                return true;
            }
            if (!foundation.containsPoint(a.getX(), a.getY())) {
                return true;
            }
        }
    } else if (container instanceof Roof) {
        final Roof roof = (Roof) container;
        final int n = Math.round(mesh.getMeshData().getVertexBuffer().limit() / 3);
        boolean init = true;
        for (int i = 0; i < n; i++) {
            final Vector3 a = getVertex(i);
            if (!roof.insideWalls(a.getX(), a.getY(), init)) {
                return true;
            }
            if (init) {
                init = false;
            }
        }
    }
    return false;
}
Also used : ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) Vector3(com.ardor3d.math.Vector3) CullHint(com.ardor3d.scenegraph.hint.CullHint)

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