Exemplo n.º 1
0
  private static MouseCursor createMouseCursor(
      final AWTImageLoader awtImageLoader, final String resourceName) throws IOException {
    final com.ardor3d.image.Image image =
        awtImageLoader.load(
            ResourceLocatorTool.getClassPathResourceAsStream(LwjglSwtExample.class, resourceName),
            false);

    return new MouseCursor("cursor1", image, 0, image.getHeight() - 1);
  }
Exemplo n.º 2
0
  public static void main(final String[] args) {
    System.setProperty("ardor3d.useMultipleContexts", "true");

    final Timer timer = new Timer();
    final FrameHandler frameWork = new FrameHandler(timer);
    final LogicalLayer logicalLayer = new LogicalLayer();

    final MyExit exit = new MyExit();
    final ExampleScene scene = new ExampleScene();
    final RotatingCubeGame game = new RotatingCubeGame(scene, exit, logicalLayer, Key.T);

    frameWork.addUpdater(game);

    // INIT SWT STUFF
    final Display display = new Display();
    final Shell shell = new Shell(display);
    shell.setLayout(new FillLayout());

    // This is our tab folder, it will be accepting our 3d canvases
    final TabFolder tabFolder = new TabFolder(shell, SWT.BORDER);

    // Add a menu item that will create and add a new canvas.
    final Menu bar = new Menu(shell, SWT.BAR);
    shell.setMenuBar(bar);

    final MenuItem fileItem = new MenuItem(bar, SWT.CASCADE);
    fileItem.setText("&Tasks");

    final Menu submenu = new Menu(shell, SWT.DROP_DOWN);
    fileItem.setMenu(submenu);
    final MenuItem item = new MenuItem(submenu, SWT.PUSH);
    item.addListener(
        SWT.Selection,
        new Listener() {
          public void handleEvent(final Event e) {
            Display.getDefault()
                .asyncExec(
                    new Runnable() {
                      public void run() {
                        addNewCanvas(tabFolder, scene, frameWork, logicalLayer);
                      }
                    });
          }
        });
    item.setText("Add &3d Canvas");
    item.setAccelerator(SWT.MOD1 + '3');

    AWTImageLoader.registerLoader();

    try {
      final SimpleResourceLocator srl =
          new SimpleResourceLocator(
              ResourceLocatorTool.getClassPathResource(
                  LwjglSwtExample.class, "com/ardor3d/example/media/"));
      ResourceLocatorTool.addResourceLocator(ResourceLocatorTool.TYPE_TEXTURE, srl);
    } catch (final URISyntaxException ex) {
      ex.printStackTrace();
    }

    addNewCanvas(tabFolder, scene, frameWork, logicalLayer);

    shell.open();

    game.init();
    // frameWork.init();

    while (!shell.isDisposed() && !exit.isExit()) {
      display.readAndDispatch();
      frameWork.updateFrame();
      Thread.yield();

      // using the below way makes things really jerky. Not sure how to handle that.

      // if (display.readAndDispatch()) {
      // frameWork.updateFrame();
      // }
      // else {
      // display.sleep();
      // }
    }

    display.dispose();
    System.exit(0);
  }