Good Design Pattern for Camera?

Hello,

Sorry if this is in the wrong sub-forum. I’ve been trying to ask this question on IRC the past few days but there seems to be no activity there.

I am trying to implement a system where there is a single viewport, but multiple cameras in a scene. The application needs to be able to switch between a chaseCam implementation, and one of several CameraNode based cameras. Furthermore some of these cameras need to be controllable via input.

I approched this problem by creating several AppStates that encapsulate a camera node, handle adding/removing input management, and have its own update loop to perform any translation effects it may house internally.

The problem I am running into is related to the ownership of a camera. For instance, the way I understand it (through testing) the camera gets attached/assigned to a CameraNode through the CameraNode’s constructor. Ala camNode = new CameraNode(name+ “: Camera Node”, app.getCamera(camera)); I then attach that node onto another node which is on the scene graph, so far so good.

But what about switching to a new camera? Lets say I have 3 seperate app states controlling 3 seperate cameras, only one of which is enabled at a single time (covering usage scenarios similar to the built in flycam). Do I need to construct a new camera node each time I want to change the primary camera? (and thus re-build all of that, and maybe wiggle through the ownership issues by implementing singleton like data structures). There really seems to be a lack of documentation around what (seems to me) to be a pretty common requirement.

If anyone can point me in the right direction it would make my day. Thanks!

Richard

You might need to explain your problem with a little less abstraction so that it is easier for us to keep track of which viewport is which and used for what and so on.

Otherwise, I’m not sure why:
http://hub.jmonkeyengine.org/javadoc/com/jme3/scene/CameraNode.html#setEnabled(boolean)

or:
http://hub.jmonkeyengine.org/javadoc/com/jme3/scene/CameraNode.html#setCamera(com.jme3.renderer.Camera)

…isn’t what you are looking for.

It may be, but the pattern is not making much sense to me. Hopefully I can better explain my problem and you can correct my misunderstanding.

This is for SINGLE view port scenarios. What I want is for all cameras to SHARE a viewport (toggling them on and off through enabling/disabling app states). The way I understand it, SimpleApplication exposes a pre-attached and necessary camera, and in all the examples I have seen, THAT camera is passed to the CameraNode via its constructor. The very act of passing it to the constructor seems to be what enables it. Note that all CameraNodes (except for the one marked serialization only) forcably take a camera in its constructor. It seems to me based on the examples that any time there are multiple “Camera” objects, is when there are multiple “Viewports”. And thus, I would think setCamera in that case would only be useful for effectively swaping which “Viewport” a node is associated to.

You have one viewport and many cameras… so why not set the appropriate camera to the viewport when you want to.

SimpleApplication sets up the main viewport and the main camera for you but you are free to do whatever you want with them after.

“so why not set the appropriate camera to the viewport when you want to.”

thats what I was originally hoping I could do, however the viewport returned from app.getViewPort does not contain a setCamera. it contains a getCamera, but not a setCamera. So how would one recommend I do that?

Hmmm… that is kind of lame.

So I guess maybe you’ll have to go the other way and just attach your camera node where you need it.

Hm?

Why not just make a Node for each of your secenes,

and just attach detach that from the rootNode, and use virtual cameras in each scene (on attach just move the real camera to where ever you want it to be?)