Insanity with Camera

Okay, I seem to be having strange issues with my camera.  I want to reset it to its starting position:

        camera.setLocation(new Vector3f(0.0f, 0.0f, 0.0f));
        camera.setUp(new Vector3f(0.0f, 1.0f, 0.0f));
        camera.setLeft(new Vector3f(-1.0f, 0.0f, 0.0f));
        camera.setDirection(new Vector3f(0.0f, 0.0f, -1.0f));

and it seems to work fine as long as I comment out the camera.setUp(...) line.  If I put that line in it shows a black screen. This has happened to me more than once, is there something I'm not doing that I should be, or am that I should not?

Sorry for the 50 questions today, I'm trying to finish up Roll-A-Rama and it's primarily bug-fixing time. :)


Looks ok for me. And it's nearly the same what BaseSimpleGame.initSystem does, except that setFrame is used there. Try using that method and report back here if it helps (it shouldn't).

I've already tried that, didn't make any difference.  It's a problem I'm having when switching between game states.

Roll-A-Rama does as a fade-in to the main menu, you navigate through, join a soccer server, fade-out, fade-in to the soccer game. All works great there. I then hit escape, prompts me asking if I want to return to the menu, I click okay, fade-out, then fade-in back to the main menu except now I'm rotated (if I don't setUp(…)) and I've got a black screen if I do setUp(…).

I have a ChaseCamera that I use in-game, could that be part of it?  It is part of a custom input handler though isn't being updated after the game state has been disabled though.  This is not a really big issue at the moment, except I've been trying to get smooth transitions to work and I'm so close. :slight_smile:

BTW, I developed a GameManager that I'd be happy to release the source for after this game is finished that is entirely based around GameStates and further has features for ManagedGameStates (which is my custom extension that adds some extras) and I've got it so fade transitions between games are one line of code:

TransitionGameState.transitionGameState(GameState start, GameState end, float timeInSeconds, URL image);

This simply does a fade-out on "start", disables that game state, displays "image" (if it is not null), inits "end", enables end, then fades back in.  The timeInSeconds is the amount of time the fade-in/fade-out takes.  Would anyone else be interested in this or should it remain proprietary? ;)


I ' m certainly interested!!!

By the way, I also have a problem involving camera and states. Here it goes:

I've written a few states for the game's menus. All menus implement a base class

which extends the StandardGameState and overrides the initCamera() method like so:

    protected void initCamera() {
        Vector3f loc = new Vector3f(0.0f, 0.0f, 5.0f);
        Vector3f left = new Vector3f(-1.0f, 0.0f, 0.0f);
        Vector3f up = new Vector3f(0.0f, 1.0f, 0.0f);
        Vector3f dir = new Vector3f(0.0f, 0f, -1.0f);
        // Move our camera to a correct place and orientation.
        getCamera().setFrame(loc, left, up, dir);

Now when I start the game, the main menu displays just fine, but when
I try to switch to the settings menu then the following exceptions are thrown:

   at java.awt.EventQueue.invokeAndWait(
   at javax.swing.SwingUtilities.invokeAndWait(
   at com.jmex.awt.swingui.JMEDesktop.onButton(
   at com.jmex.awt.swingui.JMEDesktop$ButtonAction.performAction(
   at com.jme.input.ActionTrigger.performAction(
   at com.jme.input.InputHandler.update(
   at com.jme.input.InputHandler.update(
   at fps.states.BaseMenuState.stateUpdate(
   at fps.DebugState.update(
   at fps.FPSGame.update(
   at fps.FPSGame.main(
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(
   at java.lang.reflect.Method.invoke(
   at com.intellij.rt.execution.application.AppMain.main(
Caused by: java.lang.NullPointerException
   at org.lwjgl.opengl.GL11.glMatrixMode(
   at com.jme.renderer.lwjgl.LWJGLCamera.onFrustumChange(
   at com.jme.renderer.AbstractCamera.<init>(
   at com.jme.renderer.lwjgl.LWJGLCamera.<init>(
   at com.jme.renderer.lwjgl.LWJGLRenderer.createCamera(
   at fps.states.BaseMenuState.initCamera(
   at fps.states.BaseMenuState.<init>(
   at fps.states.SettingsMenuState.<init>(
   at fps.states.MainMenuState$2.actionPerformed(
   at javax.swing.AbstractButton.fireActionPerformed(
   at javax.swing.AbstractButton$Handler.actionPerformed(
   at javax.swing.DefaultButtonModel.fireActionPerformed(
   at javax.swing.DefaultButtonModel.setPressed(
   at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(
   at org.jvnet.substance.utils.RolloverButtonListener.mouseReleased(
   at java.awt.Component.processMouseEvent(
   at javax.swing.JComponent.processMouseEvent(
   at java.awt.Component.processEvent(
   at java.awt.Container.processEvent(
   at java.awt.Component.dispatchEventImpl(
   at java.awt.Container.dispatchEventImpl(
   at java.awt.Component.dispatchEvent(
   at com.jmex.awt.swingui.JMEDesktop.dispatchEvent(
   at com.jmex.awt.swingui.JMEDesktop.sendAWTMouseEvent(
   at com.jmex.awt.swingui.JMEDesktop.access$800(
   at com.jmex.awt.swingui.JMEDesktop$
   at java.awt.event.InvocationEvent.dispatch(
   at java.awt.EventQueue.dispatchEvent(
   at java.awt.EventDispatchThread.pumpOneEventForHierarchy(
   at java.awt.EventDispatchThread.pumpEventsForHierarchy(
   at java.awt.EventDispatchThread.pumpEvents(
   at java.awt.EventDispatchThread.pumpEvents(

Does creating more than one camera cause the problem? Any suggestions?

Obviously creating more than one camera is not the problem, since the

TestGameStateSystem creates one more when switching between states.

My code that changes the camera's frame isn't the problem as well since

it is never executed. Could that exception be caused because I try to switch

states within the ActionListener of a JButton and has something to do with

the AWT thread or something? Or could that be a bug? Or am I doing

something stupidly wrong again?

Yes, you should call jME methods (including those related to the camera) from the jME thread.