@Override
 protected void renderExample(final Renderer renderer) {
   super.renderExample(renderer);
   renderer.renderBuckets();
   // draw our UI elements.
   renderer.draw(hud);
 }
  @Override
  protected void registerInputTriggers() {
    super.registerInputTriggers();

    _logicalLayer.registerTrigger(
        new InputTrigger(
            TriggerConditions.mouseMoved(),
            new TriggerAction() {
              public void perform(
                  final Canvas source, final TwoInputStates inputStates, final double tpf) {
                if (!allowClicks || !zoom) {
                  return;
                }
                final int x = inputStates.getCurrent().getMouseState().getX();
                float ratio = (float) x / _canvas.getCanvasRenderer().getCamera().getWidth();
                ratio = (2 * ratio) - 1;
                // make a dead zone in center.
                if (Math.abs(ratio) < 0.1) {
                  ratio = 0;
                }
                speed = MAX_SPEED * ratio;
              }
            }));
  }
Пример #3
0
  @Override
  protected void registerInputTriggers() {
    super.registerInputTriggers();

    // Add mouse-over to show labels

    _logicalLayer.registerTrigger(
        new InputTrigger(
            new MouseMovedCondition(),
            new TriggerAction() {
              public void perform(
                  final Canvas source, final TwoInputStates inputStates, final double tpf) {
                // Put together a pick ray
                final Vector2 pos =
                    Vector2.fetchTempInstance()
                        .set(
                            inputStates.getCurrent().getMouseState().getX(),
                            inputStates.getCurrent().getMouseState().getY());
                final Ray3 pickRay = Ray3.fetchTempInstance();
                _canvas.getCanvasRenderer().getCamera().getPickRay(pos, false, pickRay);
                Vector2.releaseTempInstance(pos);

                // Do the pick
                _pickResults.clear();
                PickingUtil.findPick(_root, pickRay, _pickResults);
                Ray3.releaseTempInstance(pickRay);

                if (_pickResults.getNumber() > 0) {
                  // picked something, show label.
                  _text.getSceneHints().setCullHint(CullHint.Never);

                  // set our text to the name of the ancestor of this object that is right under the
                  // _root node.
                  final PickData pick = _pickResults.getPickData(0);
                  if (pick.getTarget() instanceof Spatial) {
                    final Spatial topLevel = getTopLevel((Spatial) pick.getTarget());
                    if (!topLevel.equals(_picked)) {
                      clearPicked();
                      _picked = topLevel;
                      _picked.addController(_pickedControl);
                    }
                    _text.setText(topLevel.getName());
                  }
                } else {
                  // No pick, clear label.
                  _text.getSceneHints().setCullHint(CullHint.Always);
                  _text.setText("");

                  clearPicked();
                }
              }

              private void clearPicked() {
                if (_picked != null) {
                  final MaterialState ms =
                      (MaterialState) _picked.getLocalRenderState(StateType.Material);
                  ms.setAmbient(ColorRGBA.DARK_GRAY);
                  _picked.removeController(_pickedControl);
                }
                _picked = null;
              }

              private Spatial getTopLevel(final Spatial target) {
                if (target.getParent() == null || target.getParent().equals(_root)) {
                  return target;
                } else {
                  return getTopLevel(target.getParent());
                }
              }
            }));
  }
Пример #4
0
 @Override
 protected void renderExample(final Renderer renderer) {
   super.renderExample(renderer);
   manager.render(renderer);
 }