Search in sources :

Example 51 with Vector3

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

the class SceneManager method createCompass.

private Node createCompass() throws IOException {
    final ResourceSource source = ResourceLocatorTool.locateResource(ResourceLocatorTool.TYPE_MODEL, "compass.dae");
    final ColladaImporter colladaImporter = new ColladaImporter();
    // Load the collada scene
    Logger.getLogger(ColladaAnimUtils.class.getName()).setLevel(Level.SEVERE);
    Logger.getLogger(ColladaMaterialUtils.class.getName()).setLevel(Level.SEVERE);
    final ColladaStorage storage = colladaImporter.load(source);
    final Node compass = storage.getScene();
    BMText txt;
    final double Z = 0.1;
    txt = new BMText("N", "N", FontManager.getInstance().getAnnotationFont(), Align.South);
    txt.setTextColor(ColorRGBA.BLACK);
    txt.setAutoRotate(false);
    txt.setTranslation(2, 0.0, Z);
    txt.setRotation(new Matrix3().fromAngles(0.0, MathUtils.HALF_PI, -MathUtils.HALF_PI));
    compass.attachChild(txt);
    txt = new BMText("S", "S", FontManager.getInstance().getAnnotationFont(), Align.South);
    txt.setTextColor(ColorRGBA.BLACK);
    txt.setAutoRotate(false);
    txt.setTranslation(-2, -0.0, Z);
    txt.setRotation(new Matrix3().fromAngles(0.0, -MathUtils.HALF_PI, MathUtils.HALF_PI));
    compass.attachChild(txt);
    txt = new BMText("W", "W", FontManager.getInstance().getAnnotationFont(), Align.South);
    txt.setAutoRotate(false);
    txt.setTranslation(-0.0, 2, Z);
    txt.setRotation(new Matrix3().fromAngles(-MathUtils.HALF_PI, 0.0, 0.0));
    compass.attachChild(txt);
    txt = new BMText("E", "E", FontManager.getInstance().getAnnotationFont(), Align.South);
    txt.setAutoRotate(false);
    txt.setTranslation(-0.0, -2, Z);
    txt.setRotation(new Matrix3().fromAngles(MathUtils.HALF_PI, MathUtils.PI, 0.0));
    compass.attachChild(txt);
    final DirectionalLight light = new DirectionalLight();
    light.setDirection(new Vector3(0, 0, -1));
    light.setEnabled(true);
    final LightState lightState = new LightState();
    lightState.attach(light);
    compass.setRenderState(lightState);
    compass.getSceneHints().setLightCombineMode(LightCombineMode.Replace);
    compass.updateWorldRenderStates(true);
    final Node compassNode = new Node();
    compassNode.setRotation(new Matrix3().fromAngles(-MathUtils.HALF_PI, 0.0, 0.0));
    compassNode.attachChild(compass);
    System.out.println("done");
    compass.addController(new SpatialController<Spatial>() {

        @Override
        public void update(final double time, final Spatial caller) {
            final Vector3 direction = getCamera().getDirection().normalize(null);
            direction.setZ(0);
            direction.normalizeLocal();
            double angle = -direction.smallestAngleBetween(Vector3.UNIT_Y);
            if (direction.dot(Vector3.UNIT_X) > 0) {
                angle = -angle;
            }
            angle -= MathUtils.HALF_PI;
            compass.setRotation(new Matrix3().fromAngles(0.0, 0.0, angle - 0.3));
        }
    });
    return compassNode;
}
Also used : LightState(com.ardor3d.renderer.state.LightState) ColladaImporter(com.ardor3d.extension.model.collada.jdom.ColladaImporter) Node(com.ardor3d.scenegraph.Node) CameraNode(com.ardor3d.scenegraph.extension.CameraNode) ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) Vector3(com.ardor3d.math.Vector3) Matrix3(com.ardor3d.math.Matrix3) ResourceSource(com.ardor3d.util.resource.ResourceSource) Spatial(com.ardor3d.scenegraph.Spatial) DirectionalLight(com.ardor3d.light.DirectionalLight) ColladaStorage(com.ardor3d.extension.model.collada.jdom.data.ColladaStorage) BMText(com.ardor3d.ui.text.BMText)

Example 52 with Vector3

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

the class SceneManager method mouseMoved.

private void mouseMoved() {
    if (!mouseControlEnabled) {
        return;
    }
    final int x = mouseState.getX();
    final int y = mouseState.getY();
    if (Scene.getInstance().getDisableShadowInAction()) {
        if (mouseState.getButtonState(MouseButton.LEFT) == ButtonState.DOWN || mouseState.getButtonState(MouseButton.RIGHT) == ButtonState.DOWN) {
            if (MainPanel.getInstance().getShadowButton().isSelected()) {
                shadowPass.setEnabled(false);
            }
        } else {
            if (MainPanel.getInstance().getShadowButton().isSelected()) {
                shadowPass.setEnabled(true);
            }
        }
    }
    try {
        if (selectedPart != null) {
            if (!selectedPart.isDrawCompleted()) {
                selectedPart.setPreviewPoint(x, y);
                if (selectedPart instanceof Meshable) {
                    // don't draw grid if it sits on an imported mesh
                    selectedPart.setGridsVisible(((Meshable) selectedPart).getMeshLocator() == null);
                }
            } else if (objectMoveStartPoint != null) {
                if ((operation == Operation.RESIZE || selectedPart instanceof Foundation)) {
                    final PickedHousePart pick = SelectUtil.pickPart(x, y, collisionLand);
                    if (pick != null) {
                        if (selectedPart instanceof Foundation) {
                            final Foundation foundation = (Foundation) selectedPart;
                            final Vector3 pickPoint = pick.getPoint().clone();
                            // if (!foundation.insideBuilding(pickPoint.getX(), pickPoint.getY(), true)) { // only move the building when clicking outside
                            final Vector3 d = pickPoint.multiply(1, 1, 0, null).subtractLocal(objectMoveStartPoint.multiply(1, 1, 0, null));
                            if (foundation.isGroupMaster()) {
                                final List<Foundation> g = Scene.getInstance().getFoundationGroup(foundation);
                                for (final Foundation f : g) {
                                    final ArrayList<Vector3> movePoints = objectGroupMovePoints.get(f);
                                    if (movePoints != null) {
                                        // just in case this foundation's move point hasn't been included yet
                                        f.move(d, movePoints);
                                    }
                                }
                            } else {
                                foundation.move(d, objectMovePoints);
                            }
                        }
                    }
                } else if (selectedPart instanceof Tree) {
                    final PickedHousePart pick = SelectUtil.pickPart(x, y, collisionLand);
                    if (pick != null) {
                        final Vector3 d = pick.getPoint().multiply(1, 1, 0, null).subtractLocal(objectMoveStartPoint.multiply(1, 1, 0, null));
                        ((Tree) selectedPart).move(d, objectMovePoints);
                    }
                } else if (selectedPart instanceof Window) {
                    final PickedHousePart pick = SelectUtil.pickPart(x, y, selectedPart.getContainer());
                    if (pick != null) {
                        final Vector3 d = pick.getPoint().subtract(objectMoveStartPoint, null);
                        ((Window) selectedPart).move(d, objectMovePoints);
                    }
                }
            }
        }
        hoveredPart = null;
        if ((operation == Operation.SELECT || operation == Operation.RESIZE) && mouseState.getButtonState(MouseButton.LEFT) == ButtonState.UP && mouseState.getButtonState(MouseButton.MIDDLE) == ButtonState.UP && mouseState.getButtonState(MouseButton.RIGHT) == ButtonState.UP) {
            final PickedHousePart pickedPart = SelectUtil.selectHousePart(x, y, false);
            pick = pickedPart == null ? null : pickedPart.getUserData();
            final HousePart housePart = pick == null ? null : pick.getHousePart();
            if (pick != null) {
                hoveredPart = housePart;
                if (pick.getEditPointIndex() != -1) {
                    lastSelectedEditPointMouseState = mouseState;
                }
            }
        }
        mouseState = null;
    } catch (final Throwable t) {
        t.printStackTrace();
        BugReporter.report(t);
    }
    EventQueue.invokeLater(new // this method is run by the main Energy3D thread, so invoke the Swing code later
    Runnable() {

        @Override
        public void run() {
            final Component canvasComponent = (Component) canvas;
            canvasComponent.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
            if (!zoomLock && (operation == Operation.SELECT || operation == Operation.RESIZE) && hoveredPart != null) {
                if (hoveredPart instanceof Tree || hoveredPart instanceof Human) {
                    canvasComponent.setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));
                } else if (hoveredPart instanceof SolarCollector) {
                    if (pick.getEditPointIndex() >= 0) {
                        canvasComponent.setCursor(Cursor.getPredefinedCursor(pick.getEditPointIndex() == 0 ? Cursor.MOVE_CURSOR : Cursor.HAND_CURSOR));
                    }
                } else {
                    if (pick.getEditPointIndex() == -1) {
                        if (hoveredPart instanceof Window) {
                            // for windows, there is no apparent move point
                            canvasComponent.setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));
                        }
                    }
                }
            }
        }
    });
}
Also used : Window(org.concord.energy3d.model.Window) Human(org.concord.energy3d.model.Human) ArrayList(java.util.ArrayList) ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) Vector3(com.ardor3d.math.Vector3) CullHint(com.ardor3d.scenegraph.hint.CullHint) Meshable(org.concord.energy3d.model.Meshable) SolarCollector(org.concord.energy3d.model.SolarCollector) Tree(org.concord.energy3d.model.Tree) Foundation(org.concord.energy3d.model.Foundation) ArrayList(java.util.ArrayList) List(java.util.List) Component(java.awt.Component) PickedHousePart(org.concord.energy3d.model.PickedHousePart) HousePart(org.concord.energy3d.model.HousePart) PickedHousePart(org.concord.energy3d.model.PickedHousePart)

Example 53 with Vector3

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

the class SceneManager method initMouse.

private void initMouse() {
    logicalLayer.registerTrigger(new InputTrigger(new MouseButtonPressedCondition(MouseButton.LEFT), new TriggerAction() {

        @Override
        public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) {
            ((Component) canvas).requestFocusInWindow();
            if (Config.isMac()) {
                // control-click is mouse right-click on the Mac, skip
                final KeyboardState ks = inputStates.getCurrent().getKeyboardState();
                if (ks.isDown(Key.LCONTROL) || ks.isDown(Key.RCONTROL)) {
                    return;
                }
            }
            if (firstClickState == null) {
                firstClickState = inputStates;
                mousePressed(inputStates.getCurrent().getMouseState(), inputStates.getCurrent().getKeyboardState());
            } else {
                firstClickState = null;
                mouseReleased(inputStates.getCurrent().getMouseState());
            }
        }
    }));
    logicalLayer.registerTrigger(new InputTrigger(new MouseButtonReleasedCondition(MouseButton.LEFT), new TriggerAction() {

        @Override
        public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) {
            if (Config.isMac()) {
                // control-click is mouse right-click on the Mac, skip
                final KeyboardState ks = inputStates.getCurrent().getKeyboardState();
                if (ks.isDown(Key.LCONTROL) || ks.isDown(Key.RCONTROL)) {
                    return;
                }
            }
            // if editing object using select or resize then only mouse drag is allowed
            if (operation == Operation.SELECT || operation == Operation.RESIZE) {
                firstClickState = null;
                mouseReleased(inputStates.getCurrent().getMouseState());
            } else if (firstClickState != null) {
                final MouseState mouseState = inputStates.getCurrent().getMouseState();
                final MouseState prevMouseState = firstClickState.getCurrent().getMouseState();
                final ReadOnlyVector2 p1 = new Vector2(prevMouseState.getX(), prevMouseState.getY());
                final ReadOnlyVector2 p2 = new Vector2(mouseState.getX(), mouseState.getY());
                if (!(selectedPart instanceof Foundation || selectedPart instanceof Wall || selectedPart instanceof Window || selectedPart instanceof Door) || p1.distance(p2) > 10) {
                    firstClickState = null;
                    mouseReleased(inputStates.getCurrent().getMouseState());
                }
            }
        }
    }));
    ((Component) canvas).addMouseListener(new MouseAdapter() {

        @Override
        public void mouseClicked(final MouseEvent e) {
            if (Util.isRightClick(e)) {
                mouseRightClicked(e);
            }
        }

        @Override
        public void mouseReleased(final MouseEvent e) {
            if (Util.isRightClick(e)) {
                if (cameraChanged) {
                    TimeSeriesLogger.getInstance().logCamera("Pan");
                    cameraChanged = false;
                }
            }
        }
    });
    ((Component) canvas).addMouseMotionListener(new MouseMotionAdapter() {

        @Override
        public void mouseDragged(final MouseEvent e) {
            EnergyPanel.getInstance().update();
            cameraChanged = true;
        }
    });
    ((Component) canvas).addMouseWheelListener(new MouseWheelListener() {

        @Override
        public void mouseWheelMoved(final MouseWheelEvent e) {
            TimeSeriesLogger.getInstance().logCamera("Zoom");
        }
    });
    logicalLayer.registerTrigger(new InputTrigger(new MouseMovedCondition(), new TriggerAction() {

        @Override
        public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) {
            refresh = true;
            mouseState = inputStates.getCurrent().getMouseState();
        }
    }));
    logicalLayer.registerTrigger(new InputTrigger(new MouseButtonClickedCondition(MouseButton.LEFT), new TriggerAction() {

        @Override
        public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) {
            if (Config.isMac()) {
                // control-click is mouse right-click on the Mac, skip
                final KeyboardState ks = inputStates.getCurrent().getKeyboardState();
                if (ks.isDown(Key.LCONTROL) || ks.isDown(Key.RCONTROL)) {
                    return;
                }
            }
            if (!isTopView() && inputStates.getCurrent().getMouseState().getClickCount(MouseButton.LEFT) == 2) {
                if (PrintController.getInstance().isPrintPreview()) {
                    final MouseState mouse = inputStates.getCurrent().getMouseState();
                    final Ray3 pickRay = Camera.getCurrentCamera().getPickRay(new Vector2(mouse.getX(), mouse.getY()), false, null);
                    final PickResults pickResults = new PrimitivePickResults();
                    PickingUtil.findPick(PrintController.getInstance().getPagesRoot(), pickRay, pickResults, false);
                    if (pickResults.getNumber() > 0) {
                        cameraControl.zoomAtPoint(pickResults.getPickData(0).getIntersectionRecord().getIntersectionPoint(0));
                    }
                } else {
                    final PickedHousePart pickedHousePart = SelectUtil.pickPart(inputStates.getCurrent().getMouseState().getX(), inputStates.getCurrent().getMouseState().getY());
                    if (pickedHousePart != null) {
                        cameraControl.zoomAtPoint(pickedHousePart.getPoint());
                    }
                }
            }
        }
    }));
    logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.LSHIFT), new TriggerAction() {

        @Override
        public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) {
        // SelectUtil.setPickLayer(0);
        }
    }));
    logicalLayer.registerTrigger(new InputTrigger(new KeyReleasedCondition(Key.LSHIFT), new TriggerAction() {

        @Override
        public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) {
        // SelectUtil.setPickLayer(-1);
        }
    }));
    logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.DELETE), new TriggerAction() {

        @Override
        public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) {
            deleteCurrentSelection();
        }
    }));
    logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.BACK), new TriggerAction() {

        @Override
        public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) {
            deleteCurrentSelection();
        }
    }));
    logicalLayer.registerTrigger(new InputTrigger(new KeyHeldCondition(Key.ESCAPE), new TriggerAction() {

        @Override
        public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) {
            hideAllEditPoints();
        }
    }));
    logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.ZERO), new TriggerAction() {

        @Override
        public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) {
            final KeyboardState ks = inputStates.getCurrent().getKeyboardState();
            if (Config.isMac()) {
                if (ks.isDown(Key.LMETA) || ks.isDown(Key.RMETA)) {
                    resetCamera();
                }
            } else {
                if (ks.isDown(Key.LCONTROL) || ks.isDown(Key.RCONTROL)) {
                    resetCamera();
                }
            }
        }
    }));
    logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.I), new TriggerAction() {

        @Override
        public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) {
            System.out.println("---- Parts: ------------------------");
            System.out.println("size = " + Scene.getInstance().getParts().size());
            for (final HousePart part : Scene.getInstance().getParts()) {
                System.out.println(part);
            }
            System.out.println("---- Scene: ------------------------");
            System.out.println("size = " + Scene.getOriginalHouseRoot().getNumberOfChildren());
            for (final Spatial mesh : Scene.getOriginalHouseRoot().getChildren()) {
                System.out.println(mesh);
            }
        }
    }));
    logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.R), new TriggerAction() {

        @Override
        public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) {
            Scene.getInstance().redrawAll(true);
        }
    }));
    // Run/pause model replay
    logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.SPACE), new TriggerAction() {

        @Override
        public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) {
            if (PlayControl.active) {
                PlayControl.replaying = !PlayControl.replaying;
            }
        }
    }));
    logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.LEFT), new TriggerAction() {

        @Override
        public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) {
            if (PlayControl.active) {
                PlayControl.replaying = false;
                PlayControl.backward = true;
            }
            if (isTopView()) {
                if (tooManyPartsToMove()) {
                    moveWithKey(inputStates.getCurrent().getKeyboardState(), new Vector3(-1, 0, 0));
                } else {
                    if (arrowKeyHolderTask != null) {
                        arrowKeyHolderTask.cancel();
                    }
                    arrowKeyHolderTask = new KeyHolderTask(inputStates.getCurrent().getKeyboardState(), new Vector3(-1, 0, 0));
                    keyHolder.scheduleAtFixedRate(arrowKeyHolderTask, 0, keyHolderInterval);
                }
            } else {
                if (selectedPart instanceof Window) {
                    final Vector3 v = selectedPart.getNormal().clone();
                    v.crossLocal(Vector3.UNIT_Z);
                    moveWithKey(inputStates.getCurrent().getKeyboardState(), v);
                    Scene.getInstance().redrawAll();
                }
            }
        }
    }));
    logicalLayer.registerTrigger(new InputTrigger(new KeyReleasedCondition(Key.LEFT), new TriggerAction() {

        @Override
        public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) {
            if (arrowKeyHolderTask != null) {
                arrowKeyHolderTask.cancel();
            }
        }
    }));
    logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.UP), new TriggerAction() {

        @Override
        public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) {
            if (PlayControl.active) {
                PlayControl.replaying = false;
                PlayControl.backward = true;
            }
            if (isTopView()) {
                if (tooManyPartsToMove()) {
                    moveWithKey(inputStates.getCurrent().getKeyboardState(), new Vector3(0, 1, 0));
                } else {
                    if (arrowKeyHolderTask != null) {
                        arrowKeyHolderTask.cancel();
                    }
                    arrowKeyHolderTask = new KeyHolderTask(inputStates.getCurrent().getKeyboardState(), new Vector3(0, 1, 0));
                    keyHolder.scheduleAtFixedRate(arrowKeyHolderTask, 0, keyHolderInterval);
                }
            } else {
                if (selectedPart instanceof Window) {
                    final Vector3 n = selectedPart.getNormal().clone();
                    final Vector3 v = n.cross(Vector3.UNIT_Z, null);
                    moveWithKey(inputStates.getCurrent().getKeyboardState(), v.crossLocal(n));
                    Scene.getInstance().redrawAll();
                }
            }
        }
    }));
    logicalLayer.registerTrigger(new InputTrigger(new KeyReleasedCondition(Key.UP), new TriggerAction() {

        @Override
        public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) {
            if (arrowKeyHolderTask != null) {
                arrowKeyHolderTask.cancel();
            }
        }
    }));
    logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.RIGHT), new TriggerAction() {

        @Override
        public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) {
            if (PlayControl.active) {
                PlayControl.replaying = false;
                PlayControl.forward = true;
            }
            if (isTopView()) {
                if (tooManyPartsToMove()) {
                    moveWithKey(inputStates.getCurrent().getKeyboardState(), new Vector3(1, 0, 0));
                } else {
                    if (arrowKeyHolderTask != null) {
                        arrowKeyHolderTask.cancel();
                    }
                    arrowKeyHolderTask = new KeyHolderTask(inputStates.getCurrent().getKeyboardState(), new Vector3(1, 0, 0));
                    keyHolder.scheduleAtFixedRate(arrowKeyHolderTask, 0, keyHolderInterval);
                }
            } else {
                if (selectedPart instanceof Window) {
                    final Vector3 v = selectedPart.getNormal().clone();
                    v.crossLocal(Vector3.UNIT_Z).negateLocal();
                    moveWithKey(inputStates.getCurrent().getKeyboardState(), v);
                    Scene.getInstance().redrawAll();
                }
            }
        }
    }));
    logicalLayer.registerTrigger(new InputTrigger(new KeyReleasedCondition(Key.RIGHT), new TriggerAction() {

        @Override
        public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) {
            if (arrowKeyHolderTask != null) {
                arrowKeyHolderTask.cancel();
            }
        }
    }));
    logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.DOWN), new TriggerAction() {

        @Override
        public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) {
            if (PlayControl.active) {
                PlayControl.replaying = false;
                PlayControl.forward = true;
            }
            if (isTopView()) {
                if (tooManyPartsToMove()) {
                    moveWithKey(inputStates.getCurrent().getKeyboardState(), new Vector3(0, -1, 0));
                } else {
                    if (arrowKeyHolderTask != null) {
                        arrowKeyHolderTask.cancel();
                    }
                    arrowKeyHolderTask = new KeyHolderTask(inputStates.getCurrent().getKeyboardState(), new Vector3(0, -1, 0));
                    keyHolder.scheduleAtFixedRate(arrowKeyHolderTask, 0, keyHolderInterval);
                }
            } else {
                if (selectedPart instanceof Window) {
                    final Vector3 n = selectedPart.getNormal().clone();
                    final Vector3 v = n.cross(Vector3.UNIT_Z, null).negateLocal();
                    moveWithKey(inputStates.getCurrent().getKeyboardState(), v.crossLocal(n));
                    Scene.getInstance().redrawAll();
                }
            }
        }
    }));
    logicalLayer.registerTrigger(new InputTrigger(new KeyReleasedCondition(Key.DOWN), new TriggerAction() {

        @Override
        public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) {
            if (arrowKeyHolderTask != null) {
                arrowKeyHolderTask.cancel();
            }
        }
    }));
    logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.ESCAPE), new TriggerAction() {

        @Override
        public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) {
            PlayControl.active = false;
        }
    }));
    logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.W), new TriggerAction() {

        @Override
        public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) {
            if (tooManyPartsToMove()) {
                moveWithKey(inputStates.getCurrent().getKeyboardState(), new Vector3(-1, 0, 0));
            } else {
                if (arrowKeyHolderTask != null) {
                    arrowKeyHolderTask.cancel();
                }
                arrowKeyHolderTask = new KeyHolderTask(inputStates.getCurrent().getKeyboardState(), new Vector3(-1, 0, 0));
                keyHolder.scheduleAtFixedRate(arrowKeyHolderTask, 0, keyHolderInterval);
            }
        }
    }));
    logicalLayer.registerTrigger(new InputTrigger(new KeyReleasedCondition(Key.W), new TriggerAction() {

        @Override
        public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) {
            if (arrowKeyHolderTask != null) {
                arrowKeyHolderTask.cancel();
            }
        }
    }));
    logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.E), new TriggerAction() {

        @Override
        public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) {
            if (tooManyPartsToMove()) {
                moveWithKey(inputStates.getCurrent().getKeyboardState(), new Vector3(1, 0, 0));
            } else {
                if (arrowKeyHolderTask != null) {
                    arrowKeyHolderTask.cancel();
                }
                arrowKeyHolderTask = new KeyHolderTask(inputStates.getCurrent().getKeyboardState(), new Vector3(1, 0, 0));
                keyHolder.scheduleAtFixedRate(arrowKeyHolderTask, 0, keyHolderInterval);
            }
        }
    }));
    logicalLayer.registerTrigger(new InputTrigger(new KeyReleasedCondition(Key.E), new TriggerAction() {

        @Override
        public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) {
            if (arrowKeyHolderTask != null) {
                arrowKeyHolderTask.cancel();
            }
        }
    }));
    logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.S), new TriggerAction() {

        @Override
        public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) {
            if (tooManyPartsToMove()) {
                moveWithKey(inputStates.getCurrent().getKeyboardState(), new Vector3(0, -1, 0));
            } else {
                if (arrowKeyHolderTask != null) {
                    arrowKeyHolderTask.cancel();
                }
                arrowKeyHolderTask = new KeyHolderTask(inputStates.getCurrent().getKeyboardState(), new Vector3(0, -1, 0));
                keyHolder.scheduleAtFixedRate(arrowKeyHolderTask, 0, keyHolderInterval);
            }
        }
    }));
    logicalLayer.registerTrigger(new InputTrigger(new KeyReleasedCondition(Key.S), new TriggerAction() {

        @Override
        public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) {
            if (arrowKeyHolderTask != null) {
                arrowKeyHolderTask.cancel();
            }
        }
    }));
    logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.N), new TriggerAction() {

        @Override
        public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) {
            if (tooManyPartsToMove()) {
                moveWithKey(inputStates.getCurrent().getKeyboardState(), new Vector3(0, 1, 0));
            } else {
                if (arrowKeyHolderTask != null) {
                    arrowKeyHolderTask.cancel();
                }
                arrowKeyHolderTask = new KeyHolderTask(inputStates.getCurrent().getKeyboardState(), new Vector3(0, 1, 0));
                keyHolder.scheduleAtFixedRate(arrowKeyHolderTask, 0, keyHolderInterval);
            }
        }
    }));
    logicalLayer.registerTrigger(new InputTrigger(new KeyReleasedCondition(Key.N), new TriggerAction() {

        @Override
        public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) {
            if (arrowKeyHolderTask != null) {
                arrowKeyHolderTask.cancel();
            }
        }
    }));
}
Also used : TriggerAction(com.ardor3d.input.logical.TriggerAction) MouseButtonReleasedCondition(com.ardor3d.input.logical.MouseButtonReleasedCondition) Wall(org.concord.energy3d.model.Wall) KeyPressedCondition(com.ardor3d.input.logical.KeyPressedCondition) InputTrigger(com.ardor3d.input.logical.InputTrigger) MouseButtonPressedCondition(com.ardor3d.input.logical.MouseButtonPressedCondition) KeyReleasedCondition(com.ardor3d.input.logical.KeyReleasedCondition) MouseWheelListener(java.awt.event.MouseWheelListener) Ray3(com.ardor3d.math.Ray3) PrimitivePickResults(com.ardor3d.intersection.PrimitivePickResults) KeyboardState(com.ardor3d.input.KeyboardState) Foundation(org.concord.energy3d.model.Foundation) Component(java.awt.Component) PickedHousePart(org.concord.energy3d.model.PickedHousePart) HousePart(org.concord.energy3d.model.HousePart) PickedHousePart(org.concord.energy3d.model.PickedHousePart) Window(org.concord.energy3d.model.Window) MouseEvent(java.awt.event.MouseEvent) MouseMovedCondition(com.ardor3d.input.logical.MouseMovedCondition) Canvas(com.ardor3d.framework.Canvas) MouseAdapter(java.awt.event.MouseAdapter) ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) Vector3(com.ardor3d.math.Vector3) MouseButtonClickedCondition(com.ardor3d.input.logical.MouseButtonClickedCondition) Door(org.concord.energy3d.model.Door) ReadOnlyVector2(com.ardor3d.math.type.ReadOnlyVector2) MouseMotionAdapter(java.awt.event.MouseMotionAdapter) MouseWheelEvent(java.awt.event.MouseWheelEvent) ReadOnlyVector2(com.ardor3d.math.type.ReadOnlyVector2) Vector2(com.ardor3d.math.Vector2) Spatial(com.ardor3d.scenegraph.Spatial) MouseState(com.ardor3d.input.MouseState) TwoInputStates(com.ardor3d.input.logical.TwoInputStates) PickResults(com.ardor3d.intersection.PickResults) PrimitivePickResults(com.ardor3d.intersection.PrimitivePickResults) KeyHeldCondition(com.ardor3d.input.logical.KeyHeldCondition)

Example 54 with Vector3

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

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

the class Heliodon method drawSunPath.

private void drawSunPath() {
    final FloatBuffer buf = sunPath.getMeshData().getVertexBuffer();
    buf.limit(buf.capacity());
    buf.rewind();
    final double step = MathUtils.TWO_PI / HOUR_DIVISIONS;
    int limit = 0;
    for (double hourAngle = -Math.PI; hourAngle < Math.PI + step / 2.0; hourAngle += step) {
        final Vector3 v = computeSunLocation(hourAngle, declinationAngle, latitude);
        if (v.getZ() > -0.3) {
            buf.put(v.getXf()).put(v.getYf()).put(v.getZf());
            limit += 3;
        }
    }
    buf.limit(limit);
    sunPath.updateModelBound();
    sunPath.getSceneHints().setCullHint(limit == 0 ? CullHint.Always : CullHint.Inherit);
    dirtySunPath = false;
}
Also used : FloatBuffer(java.nio.FloatBuffer) 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