Search in sources :

Example 6 with BoundingBox

use of com.ardor3d.bounding.BoundingBox in project energy3d by concord-consortium.

the class SceneManager method createAxes.

private Spatial createAxes() {
    final int axisLen = SKY_RADIUS;
    final Node axisRoot = new Node();
    FloatBuffer buf;
    Line line;
    // X-Axis
    buf = BufferUtils.createVector3Buffer(2);
    buf.put(-axisLen).put(0).put(0);
    buf.put(axisLen).put(0).put(0);
    line = new Line("X-Axis", buf, null, null, null);
    line.setDefaultColor(ColorRGBA.RED);
    Util.disablePickShadowLight(line);
    line.setModelBound(new BoundingBox());
    line.updateModelBound();
    axisRoot.attachChild(line);
    // Y-Axis
    buf = BufferUtils.createVector3Buffer(2);
    buf.put(0).put(-axisLen).put(0);
    buf.put(0).put(axisLen).put(0);
    line = new Line("Y-Axis", buf, null, null, null);
    line.setDefaultColor(ColorRGBA.GREEN);
    Util.disablePickShadowLight(line);
    line.setModelBound(new BoundingBox());
    line.updateModelBound();
    axisRoot.attachChild(line);
    // Z-Axis
    buf = BufferUtils.createVector3Buffer(2);
    buf.put(0).put(0).put(-axisLen);
    buf.put(0).put(0).put(axisLen);
    line = new Line("Z-Axis", buf, null, null, null);
    Util.disablePickShadowLight(line);
    line.setDefaultColor(ColorRGBA.BLUE);
    line.setModelBound(new BoundingBox());
    line.updateModelBound();
    axisRoot.attachChild(line);
    axisRoot.updateWorldBound(true);
    return axisRoot;
}
Also used : Line(com.ardor3d.scenegraph.Line) Node(com.ardor3d.scenegraph.Node) CameraNode(com.ardor3d.scenegraph.extension.CameraNode) BoundingBox(com.ardor3d.bounding.BoundingBox) FloatBuffer(java.nio.FloatBuffer) CullHint(com.ardor3d.scenegraph.hint.CullHint)

Example 7 with BoundingBox

use of com.ardor3d.bounding.BoundingBox in project energy3d by concord-consortium.

the class Rack method addPole.

private void addPole(final Vector3 position, final double poleHeight, final double baseZ) {
    final Cylinder pole = new Cylinder("Pole Cylinder", 10, 10, 10, 0);
    pole.setRadius(0.6);
    pole.setRenderState(offsetState);
    // slightly shorter so that the pole won't penetrate the surface of the rack
    pole.setHeight(poleHeight - 0.5 * pole.getRadius());
    pole.setModelBound(new BoundingBox());
    pole.updateModelBound();
    position.setZ(baseZ + pole.getHeight() / 2);
    pole.setTranslation(position);
    polesRoot.attachChild(pole);
}
Also used : Cylinder(com.ardor3d.scenegraph.shape.Cylinder) BoundingBox(com.ardor3d.bounding.BoundingBox) OrientedBoundingBox(com.ardor3d.bounding.OrientedBoundingBox)

Example 8 with BoundingBox

use of com.ardor3d.bounding.BoundingBox in project energy3d by concord-consortium.

the class CameraControl method getCurrentExtent.

// the extent that depends on the camera orientation (not a perfect solution)
private static double getCurrentExtent() {
    double extent = 10;
    final BoundingVolume volume = Scene.getRoot().getWorldBound();
    if (volume instanceof BoundingBox) {
        final BoundingBox box = (BoundingBox) volume;
        final ReadOnlyVector3 cameraDirection = SceneManager.getInstance().getCamera().getDirection();
        final Vector3 e1 = box.getExtent(null);
        final double extent1 = Math.abs(e1.cross(cameraDirection, null).length());
        final Vector3 e2 = new Matrix3().applyRotationZ(Math.PI / 2).applyPost(e1, null);
        final double extent2 = Math.abs(e2.cross(cameraDirection, null).length());
        extent = 0.45 * (extent1 + extent2);
    }
    return extent;
}
Also used : ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) BoundingBox(com.ardor3d.bounding.BoundingBox) BoundingVolume(com.ardor3d.bounding.BoundingVolume) ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) Vector3(com.ardor3d.math.Vector3) Matrix3(com.ardor3d.math.Matrix3)

Example 9 with BoundingBox

use of com.ardor3d.bounding.BoundingBox in project energy3d by concord-consortium.

the class PrintController method arrangePrintPages.

private void arrangePrintPages(final ArrayList<ArrayList<Spatial>> pages) {
    final double ratio = (double) Camera.getCurrentCamera().getWidth() / Camera.getCurrentCamera().getHeight();
    cols = (int) Math.round(Math.sqrt(pages.size() + 4) * ratio);
    if (cols % 2 == 0) {
        cols++;
    }
    rows = (int) Math.ceil((pages.size() + 4) / cols);
    int pageNum = 0;
    printCenters.clear();
    for (final ArrayList<Spatial> page : pages) {
        final Vector3 upperLeftCorner = new Vector3();
        double x, z;
        final BoundingBox originalHouseBoundingBox = (BoundingBox) Scene.getOriginalHouseRoot().getWorldBound().asType(Type.AABB);
        final ReadOnlyVector3 originalHouseCenter = Scene.getOriginalHouseRoot().getWorldBound().getCenter();
        final double minXDistance = originalHouseBoundingBox.getXExtent() + pageWidth / 2.0;
        final double minYDistance = originalHouseBoundingBox.getZExtent();
        do {
            x = (pageNum % cols - cols / 2) * (pageWidth + SPACE_BETWEEN_PAGES) + originalHouseCenter.getX();
            z = (pageNum / cols) * (pageHeight + SPACE_BETWEEN_PAGES);
            upperLeftCorner.setX(x - pageWidth / 2.0);
            upperLeftCorner.setZ(z + pageHeight);
            pageNum++;
        } while (Math.abs(x - originalHouseCenter.getX()) < minXDistance && Math.abs(z - originalHouseCenter.getZ()) < minYDistance);
        printCenters.add(upperLeftCorner);
        for (final Spatial printSpatial : page) {
            ((UserData) printSpatial.getUserData()).getPrintCenter().addLocal(upperLeftCorner.multiply(1, 0, 1, null));
        }
        final Box box = new Box("Page Boundary");
        final double y = Scene.getOriginalHouseRoot().getWorldBound().getCenter().getY();
        box.setData(upperLeftCorner.add(0, y + 1, 0, null), upperLeftCorner.add(pageWidth, y + 1.2, -pageHeight, null));
        box.setModelBound(new BoundingBox());
        box.updateModelBound();
        pagesRoot.attachChild(box);
        final BMText footNote = Annotation.makeNewLabel(1);
        final String url = Scene.getURL() != null ? Scene.getURL().getFile().substring(Scene.getURL().getFile().lastIndexOf('/') + 1, Scene.getURL().getFile().length()) + " -" : "";
        footNote.setText(url.replaceAll("%20", " ") + " Page " + printCenters.size() + " / " + pages.size() + " - http://energy.concord.org/");
        footNote.setFontScale(0.5);
        footNote.setAlign(Align.North);
        footNote.setTranslation(upperLeftCorner.add(pageWidth / 2.0, 0.0, -pageBottom - spaceBetweenParts / 2.0, null));
        pagesRoot.attachChild(footNote);
    }
    pagesRoot.updateGeometricState(0);
}
Also used : ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) Spatial(com.ardor3d.scenegraph.Spatial) BoundingBox(com.ardor3d.bounding.BoundingBox) OrientedBoundingBox(com.ardor3d.bounding.OrientedBoundingBox) ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) Vector3(com.ardor3d.math.Vector3) BoundingBox(com.ardor3d.bounding.BoundingBox) Box(com.ardor3d.scenegraph.shape.Box) OrientedBoundingBox(com.ardor3d.bounding.OrientedBoundingBox) BMText(com.ardor3d.ui.text.BMText) CullHint(com.ardor3d.scenegraph.hint.CullHint)

Example 10 with BoundingBox

use of com.ardor3d.bounding.BoundingBox in project energy3d by concord-consortium.

the class Mirror method init.

@Override
protected void init() {
    super.init();
    if (Util.isZero(mirrorWidth)) {
        mirrorWidth = 5;
    }
    if (Util.isZero(mirrorHeight)) {
        mirrorHeight = 3;
    }
    if (Util.isZero(reflectance)) {
        reflectance = 0.9;
    }
    if (Util.isZero(opticalEfficiency)) {
        opticalEfficiency = 1;
    }
    if (Util.isZero(baseHeight)) {
        baseHeight = 10;
    }
    if (heliostatTarget != null) {
        // FIXME: Somehow the target, when copied, doesn't point to the right object. This is not a prefect solution, but it fixes the problem.
        final HousePart hp = Scene.getInstance().getPart(heliostatTarget.getId());
        if (hp instanceof Foundation) {
            heliostatTarget = (Foundation) hp;
        } else {
            heliostatTarget = null;
        }
    }
    mesh = new Mesh("Reflecting Mirror");
    mesh.getMeshData().setVertexBuffer(BufferUtils.createVector3Buffer(6));
    mesh.getMeshData().setTextureBuffer(BufferUtils.createVector2Buffer(6), 0);
    mesh.setModelBound(new OrientedBoundingBox());
    mesh.setUserData(new UserData(this));
    root.attachChild(mesh);
    surround = new Box("Mirror (Surround)");
    surround.setModelBound(new OrientedBoundingBox());
    final OffsetState offset = new OffsetState();
    offset.setFactor(1);
    offset.setUnits(1);
    surround.setRenderState(offset);
    root.attachChild(surround);
    outlineMesh = new Line("Mirror (Outline)");
    outlineMesh.getMeshData().setVertexBuffer(BufferUtils.createVector3Buffer(8));
    outlineMesh.setDefaultColor(ColorRGBA.BLACK);
    outlineMesh.setModelBound(new OrientedBoundingBox());
    root.attachChild(outlineMesh);
    // if there are many mirrors, reduce the solution of post
    post = new Cylinder("Post Cylinder", 2, Scene.getInstance().getAllHeliostats().size() < 200 ? 10 : 2, 10, 0);
    post.setRadius(0.6);
    post.setDefaultColor(ColorRGBA.WHITE);
    post.setRenderState(offsetState);
    post.setModelBound(new BoundingBox());
    post.updateModelBound();
    root.attachChild(post);
    lightBeams = new Line("Light Beams");
    lightBeams.setLineWidth(1f);
    lightBeams.setStipplePattern((short) 0xffff);
    lightBeams.setModelBound(null);
    // final BlendState blendState = new BlendState();
    // blendState.setBlendEnabled(true);
    // lightBeams.setRenderState(blendState);
    // lightBeams.getSceneHints().setRenderBucketType(RenderBucketType.Transparent);
    Util.disablePickShadowLight(lightBeams);
    lightBeams.getMeshData().setVertexBuffer(BufferUtils.createVector3Buffer(4));
    lightBeams.setDefaultColor(new ColorRGBA(1f, 1f, 1f, 1f));
    root.attachChild(lightBeams);
    label = new BMText("Label", "# " + id, FontManager.getInstance().getPartNumberFont(), Align.Center, Justify.Center);
    Util.initHousePartLabel(label);
    label.setFontScale(0.5);
    label.setVisible(false);
    root.attachChild(label);
    updateTextureAndColor();
}
Also used : Line(com.ardor3d.scenegraph.Line) Cylinder(com.ardor3d.scenegraph.shape.Cylinder) OrientedBoundingBox(com.ardor3d.bounding.OrientedBoundingBox) ColorRGBA(com.ardor3d.math.ColorRGBA) BoundingBox(com.ardor3d.bounding.BoundingBox) OrientedBoundingBox(com.ardor3d.bounding.OrientedBoundingBox) Mesh(com.ardor3d.scenegraph.Mesh) BoundingBox(com.ardor3d.bounding.BoundingBox) Box(com.ardor3d.scenegraph.shape.Box) OrientedBoundingBox(com.ardor3d.bounding.OrientedBoundingBox) BMText(com.ardor3d.ui.text.BMText) OffsetState(com.ardor3d.renderer.state.OffsetState)

Aggregations

BoundingBox (com.ardor3d.bounding.BoundingBox)23 Line (com.ardor3d.scenegraph.Line)12 Mesh (com.ardor3d.scenegraph.Mesh)10 OrientedBoundingBox (com.ardor3d.bounding.OrientedBoundingBox)8 ReadOnlyVector3 (com.ardor3d.math.type.ReadOnlyVector3)8 Cylinder (com.ardor3d.scenegraph.shape.Cylinder)7 ColorRGBA (com.ardor3d.math.ColorRGBA)6 Vector3 (com.ardor3d.math.Vector3)6 CullHint (com.ardor3d.scenegraph.hint.CullHint)6 BMText (com.ardor3d.ui.text.BMText)6 FloatBuffer (java.nio.FloatBuffer)6 BlendState (com.ardor3d.renderer.state.BlendState)5 Node (com.ardor3d.scenegraph.Node)5 ArrayList (java.util.ArrayList)4 Matrix3 (com.ardor3d.math.Matrix3)3 Box (com.ardor3d.scenegraph.shape.Box)3 ReadOnlyColorRGBA (com.ardor3d.math.type.ReadOnlyColorRGBA)2 OffsetState (com.ardor3d.renderer.state.OffsetState)2 BillboardNode (com.ardor3d.scenegraph.extension.BillboardNode)2 Quad (com.ardor3d.scenegraph.shape.Quad)2