Problems with proper resetting camera after resizing JMECanvas

Hi,



I'm currently working on a 3D-Shoppingcenter game in JME. I have a JMECanvas integrated in a Swing application. I noticed that when I resize the application window (and with that also the JMECanvas of course), that the camera settings are completely wrong after that. With wrong camera settings I mean that when I try to pick my products out of the shelves in my shoppingcenter game it always takes the wrong ones. For picking the products out of the shelves I use a class NormalKeyboardHandler that extends InputHandler where I initialize an object KeySelectAction (extends InputActionInterface) with the current camera object. In the latter class I have the following method for picking the products:



public void performAction(InputActionEvent evt) {
      
      Ray selectRay = new Ray(cam.getLocation(), cam.getDirection());
      pr.clear();
      rootNode.findPick(selectRay, pr);
      
      if(pr.getNumber() > 1 && pr.getPickData(1).getDistance() < productPickDistance){
         ProductModelNode node = getModelNode(pr.getPickData(1).getTargetMesh().getParentGeom());
         if(node != null)
            selectAction.performAction(node);         
      }
}



In RenParticelEditor I have seen that the author always reinizializes the frustum when the canvas is getting resized:

protected void doResize() {
        if (impl != null) {
            impl.resizeCanvas(glCanvas.getWidth(), glCanvas.getHeight());
            if (impl.getCamera() != null) {
                Callable<?> exe = new Callable() {
                    public Object call() {
                        impl.getCamera().setFrustumPerspective(
                                45.0f,
                                (float) glCanvas.getWidth()
                                        / (float) glCanvas.getHeight(), 1,
                                10000);
                        return null;
                    }
                };
                GameTaskQueueManager.getManager()
                        .getQueue(GameTaskQueue.RENDER).enqueue(exe);
            }
        }
}



Do I need to do something like that also for the camera so that afterwards after a canvas resize I'll still be able to pick the right products?

Any help would be much appreciated.

Thanks,

Michael

Hi,



Well, maybe I need to ask differently. In that case when the swing window where the JME Canvas resides is getting resized, I actually shouldn't need to do anything more than call the resize(int width, int height) method of JMECanvasImplementor? Or do I need to do additional things in terms of camera and frustum settings? In my case it looks like that after a resize the camera settings are not right anymore…



Any help would be much appreciated!



Thanks,



Michael

You might want to check out this:

http://www.jmonkeyengine.com/jmeforum/index.php?topic=7168.0



The API allows you to have multiple canvases with ease, it automatically resizes the canvases when the size changes etc. The best feature is probably the ability to share textures/display lists between contexts. See the View3D class for a usage example.