Пример #1
0
  private LwjglAwtCanvas initContext() throws LWJGLException {
    //        refresher.addUpdater(controller);

    LwjglCanvasRenderer renderer = new LwjglCanvasRenderer(container);
    final DisplaySettings settings = new DisplaySettings(1, 1, 0, 0, 0, 32, 0, 4, false, false);
    final LwjglAwtCanvas canvas = new LwjglAwtCanvas(settings, renderer);
    canvas.setSize(new Dimension(100, 100));
    canvas.setPreferredSize(new Dimension(1, 1));
    canvas.setVisible(true);

    final AwtMouseWrapper mouseWrapper = new AwtMouseWrapper(canvas);
    final AwtKeyboardWrapper keyboardWrapper = new AwtKeyboardWrapper(canvas);
    final AwtFocusWrapper focusWrapper = new AwtFocusWrapper(canvas);
    final AwtMouseManager mouseManager = new AwtMouseManager(canvas);

    final PhysicalLayer pl = new PhysicalLayer(keyboardWrapper, mouseWrapper, focusWrapper);

    logicalLayer.registerInput(canvas, pl);

    logicalLayer.registerTrigger(
        new InputTrigger(
            new KeyPressedCondition(Key.H),
            new TriggerAction() {
              @Override
              public void perform(Canvas source, TwoInputStates arg1, double arg2) {
                if (source != canvas) {
                  return;
                }
              }
            }));
    logicalLayer.registerTrigger(
        new InputTrigger(
            new KeyPressedCondition(Key.J),
            new TriggerAction() {

              @Override
              public void perform(Canvas source, TwoInputStates arg1, double arg2) {
                if (source != canvas) {
                  return;
                }
                mouseManager.setCursor(MouseCursor.SYSTEM_DEFAULT);
              }
            }));

    //        refresher.addCanvas(canvas);

    return canvas;
  }
Пример #2
0
 public void dispose() {
   if (selectedMesh != null) selectedMesh.removeController(updater);
   selectedMesh = null;
   bbvn = null;
   root.detachChild(this);
   for (InputTrigger it : inputTriggers) {
     logicalLayer.deregisterTrigger(it);
   }
 }
Пример #3
0
  private void registerControls() {
    inputTriggers.add(
        new InputTrigger(
            new MouseButtonPressedCondition(MouseButton.LEFT),
            new TriggerAction() {
              @Override
              public void perform(
                  final Canvas source, final TwoInputStates inputStates, final double tpf) {
                final Vector2 pos =
                    Vector2.fetchTempInstance()
                        .set(
                            inputStates.getCurrent().getMouseState().getX(),
                            inputStates.getCurrent().getMouseState().getY());
                final Ray3 pickRay = Ray3.fetchTempInstance();
                source.getCanvasRenderer().getCamera().getPickRay(pos, false, pickRay);
                Vector2.releaseTempInstance(pos);
                pickResults.clear();
                CollisionTreeManager.getInstance().removeCollisionTree(root);
                PickingUtil.findPick(Analyzer.this.root, pickRay, pickResults);
                if (pickResults.getNumber() > 0) {
                  final PickData pick = pickResults.getPickData(0);
                  if (pick != null && pick.getTarget() instanceof Mesh) {
                    setSelection((Mesh) pick.getTarget());
                  } else {
                    setSelection(null);
                  }
                } else {
                  setSelection(null);
                }
              }
            }));

    inputTriggers.add(
        new InputTrigger(
            new KeyPressedCondition(Key.I),
            new TriggerAction() {
              @Override
              public void perform(
                  final Canvas source, final TwoInputStates inputStates, final double tpf) {
                if (hasSelection() && bbvn == null) {
                  bbvn = new BillBoardVertexNumbers(selectedMesh);
                  bbvn.updateGeometricState(0);
                } else {
                  bbvn = null;
                }
              }
            }));

    for (InputTrigger it : inputTriggers) {
      logicalLayer.registerTrigger(it);
    }
  }
Пример #4
0
  private static void addNewCanvas(
      final TabFolder tabFolder,
      final ExampleScene scene,
      final FrameHandler frameWork,
      final LogicalLayer logicalLayer) {
    i++;
    logger.info("Adding canvas");

    // Add a new tab to hold our canvas
    final TabItem item = new TabItem(tabFolder, SWT.NONE);
    item.setText("Canvas #" + i);
    tabFolder.setSelection(item);
    final Composite canvasParent = new Composite(tabFolder, SWT.NONE);
    canvasParent.setLayout(new FillLayout());
    item.setControl(canvasParent);

    final GLData data = new GLData();
    data.depthSize = 8;
    data.doubleBuffer = true;

    final SashForm splitter = new SashForm(canvasParent, SWT.HORIZONTAL);

    final SashForm splitterLeft = new SashForm(splitter, SWT.VERTICAL);
    final Composite topLeft = new Composite(splitterLeft, SWT.NONE);
    topLeft.setLayout(new FillLayout());
    final Composite bottomLeft = new Composite(splitterLeft, SWT.NONE);
    bottomLeft.setLayout(new FillLayout());

    final SashForm splitterRight = new SashForm(splitter, SWT.VERTICAL);
    final Composite topRight = new Composite(splitterRight, SWT.NONE);
    topRight.setLayout(new FillLayout());
    final Composite bottomRight = new Composite(splitterRight, SWT.NONE);
    bottomRight.setLayout(new FillLayout());

    canvasParent.layout();

    final SwtCanvas canvas1 = new SwtCanvas(topLeft, SWT.NONE, data);
    final LwjglCanvasRenderer lwjglCanvasRenderer1 = new LwjglCanvasRenderer(scene);
    addCallback(canvas1, lwjglCanvasRenderer1);
    canvas1.setCanvasRenderer(lwjglCanvasRenderer1);
    frameWork.addCanvas(canvas1);
    canvas1.addControlListener(newResizeHandler(canvas1, lwjglCanvasRenderer1));
    canvas1.setFocus();

    final SwtCanvas canvas2 = new SwtCanvas(bottomLeft, SWT.NONE, data);
    final LwjglCanvasRenderer lwjglCanvasRenderer2 = new LwjglCanvasRenderer(scene);
    addCallback(canvas2, lwjglCanvasRenderer2);
    canvas2.setCanvasRenderer(lwjglCanvasRenderer2);
    frameWork.addCanvas(canvas2);
    canvas2.addControlListener(newResizeHandler(canvas2, lwjglCanvasRenderer2));

    final SwtCanvas canvas3 = new SwtCanvas(topRight, SWT.NONE, data);
    final LwjglCanvasRenderer lwjglCanvasRenderer3 = new LwjglCanvasRenderer(scene);
    addCallback(canvas3, lwjglCanvasRenderer3);
    canvas3.setCanvasRenderer(lwjglCanvasRenderer3);
    frameWork.addCanvas(canvas3);
    canvas3.addControlListener(newResizeHandler(canvas3, lwjglCanvasRenderer3));

    final SwtCanvas canvas4 = new SwtCanvas(bottomRight, SWT.NONE, data);
    final LwjglCanvasRenderer lwjglCanvasRenderer4 = new LwjglCanvasRenderer(scene);
    addCallback(canvas4, lwjglCanvasRenderer4);
    canvas4.setCanvasRenderer(lwjglCanvasRenderer4);
    frameWork.addCanvas(canvas4);
    canvas4.addControlListener(newResizeHandler(canvas4, lwjglCanvasRenderer4));

    final SwtKeyboardWrapper keyboardWrapper = new SwtKeyboardWrapper(canvas1);
    final SwtMouseWrapper mouseWrapper = new SwtMouseWrapper(canvas1);
    final SwtFocusWrapper focusWrapper = new SwtFocusWrapper(canvas1);
    final SwtMouseManager mouseManager = new SwtMouseManager(canvas1);
    final ControllerWrapper controllerWrapper = new DummyControllerWrapper();

    final PhysicalLayer pl =
        new PhysicalLayer(keyboardWrapper, mouseWrapper, controllerWrapper, focusWrapper);

    logicalLayer.registerInput(canvas1, pl);

    logicalLayer.registerTrigger(
        new InputTrigger(
            new KeyPressedCondition(Key.H),
            new TriggerAction() {
              public void perform(
                  final Canvas source, final TwoInputStates inputStates, final double tpf) {
                if (source != canvas1) {
                  return;
                }

                if (_showCursor1.get(canvas1)) {
                  mouseManager.setCursor(_cursor1);
                } else {
                  mouseManager.setCursor(_cursor2);
                }

                _showCursor1.put(canvas1, !_showCursor1.get(canvas1));
              }
            }));
    logicalLayer.registerTrigger(
        new InputTrigger(
            new KeyPressedCondition(Key.J),
            new TriggerAction() {
              public void perform(
                  final Canvas source, final TwoInputStates inputStates, final double tpf) {
                if (source != canvas1) {
                  return;
                }

                mouseManager.setCursor(MouseCursor.SYSTEM_DEFAULT);
              }
            }));
    logicalLayer.registerTrigger(
        new InputTrigger(
            new KeyPressedCondition(Key.G),
            new TriggerAction() {
              public void perform(
                  final Canvas source, final TwoInputStates inputStates, final double tpf) {
                if (source != canvas1) {
                  return;
                }

                mouseManager.setGrabbed(
                    mouseManager.getGrabbed() == GrabbedState.NOT_GRABBED
                        ? GrabbedState.GRABBED
                        : GrabbedState.NOT_GRABBED);
              }
            }));

    final AWTImageLoader awtImageLoader = new AWTImageLoader();
    try {
      _cursor1 =
          createMouseCursor(awtImageLoader, "com/ardor3d/example/media/input/wait_cursor.png");
      _cursor2 = createMouseCursor(awtImageLoader, "com/ardor3d/example/media/input/movedata.gif");
    } catch (final IOException ioe) {
      ioe.printStackTrace();
    }

    _showCursor1.put(canvas1, true);
  }