Exemple #1
0
  private static MouseCursor createMouseCursor(final String resourceName) throws IOException {
    final com.ardor3d.image.Image image =
        ImageLoaderUtil.loadImage(
            new URLResourceSource(
                ResourceLocatorTool.getClassPathResource(JoglSwtExample.class, resourceName)),
            false);

    return new MouseCursor("cursor1", image, 0, image.getHeight() - 1);
  }
  public static ResourceSource locateResource(final String resourceType, String resourceName) {
    if (resourceName == null) {
      return null;
    }

    try {
      resourceName = URLDecoder.decode(resourceName, "UTF-8");
    } catch (final UnsupportedEncodingException ex) {
      ex.printStackTrace();
    }

    synchronized (_locatorMap) {
      final List<ResourceLocator> bases = _locatorMap.get(resourceType);
      if (bases != null) {
        for (int i = bases.size(); --i >= 0; ) {
          final ResourceLocator loc = bases.get(i);
          final ResourceSource rVal = loc.locateResource(resourceName);
          if (rVal != null) {
            return rVal;
          }
        }
      }
      // last resort...
      try {
        final URL u =
            ResourceLocatorTool.getClassPathResource(ResourceLocatorTool.class, resourceName);
        if (u != null) {
          return new URLResourceSource(u);
        }
      } catch (final Exception e) {
        logger.logp(
            Level.WARNING,
            ResourceLocatorTool.class.getName(),
            "locateResource(String, String)",
            e.getMessage(),
            e);
      }

      logger.warning("Unable to locate: " + resourceName);
      return null;
    }
  }
Exemple #3
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);
  }