Hi. I have two viewports in my application. I want to use two different chase cameras, one for each viewport.
Assuming that one can interact with one viewport at a time, it would be ok for me to setEnable(false) the chase camera that is not needed in that moment, so there would be no problem if both cameras where bind to the same input.
The problem: I don’t seem to get the chase camera creation working. It always work only in the first viewport, no way to get it working in the second one, which is not displayed if the chasecamera is created.
Any suggestions?
Would it be a good idea to use only one chase camera and rebind it at any time to the active viewport? How to do so?
So this is the error I get when trying to detach the case camera from the first viewport and attach it to the other one:
[java]
GRAVE: Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main]
java.lang.NullPointerException
at com.jme3.input.ChaseCamera.updateCamera(ChaseCamera.java:329)
at com.jme3.input.ChaseCamera.update(ChaseCamera.java:548)
at com.jme3.scene.Spatial.runControlUpdate(Spatial.java:540)
at com.jme3.scene.Spatial.updateLogicalState(Spatial.java:658)
at com.jme3.scene.Node.updateLogicalState(Node.java:147)
at com.jme3.scene.Node.updateLogicalState(Node.java:154)
at com.jme3.scene.Node.updateLogicalState(Node.java:154)
at com.jme3.app.SimpleApplication.update(SimpleApplication.java:256)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.runLoop(LwjglAbstractDisplay.java:144)
at com.jme3.system.lwjgl.LwjglDisplay.runLoop(LwjglDisplay.java:185)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:218)
at java.lang.Thread.run(Thread.java:679)
[/java]
and this is the line of code that causes the exception when simpleupdate is called:
[java]
chaseCamTarget.removeControl(chaseCam);
[/java]
Any idea about what should I update to fix it? The camera (not chase camera)? The target spatial? What else?
By the way, is there any method to catch those exceptions from lwjgl?
Think of a ChaseCamera as a Camera control.
yes but all I get a black screen if I add that control to cameras cloned from Application.getCamera(). No geometry gets rendered in those viewports. Why?
as far as I can tell, ChaseCamera can only be used with Application.getCamera()
Did you attach the “rootNode” to the viewport? Did you attach that camera to that viewport?
It seems I attached everything, because if I render the viewport without adding the chasecamera control to the viewport camera, then geometry is displayed correctly.
Here is the code
[java]
rootNode = new Node("combinerRootNode");
combinerNode = new Node("combinerNode");
rootNode.attachChild(combinerNode);
Camera combinerCam = implementor.getCamera().clone();
combinerCam.setLocation(new Vector3f(0f, 15f, -50f));
combinerCam.lookAt(new Vector3f(0, 0, 0), new Vector3f(0, 1, 0));
combinerCam.updateViewProjection();
combinerCam.update();
new ChaseCamera(combinerCam, combinerNode);
combinerCam.update();
Vector3f direction = new Vector3f(0.1f, -0.7f, 1).normalizeLocal();
DirectionalLight dl = new DirectionalLight();
dl.setName("sun");
dl.setDirection(direction);
dl.setColor(new ColorRGBA(1f, 1f, 1f, 1.0f));
rootNode.addLight(dl);
Node combinerNode1 = new Node("combinerNode1");
combinerNode1.setLocalTranslation(new Vector3f(-10, 0, 0));
Node combinerNode2 = new Node("combinerNode2");
combinerNode2.setLocalTranslation(new Vector3f(10, 0, 0));
combinerNode.attachChild(combinerNode1);
combinerNode.attachChild(combinerNode2);
ViewPort pv = implementor.getRenderManager().createMainView("combiner", combinerCam);
pv.setClearFlags(true, true, true);
pv.setBackgroundColor(new ColorRGBA(0.8f, 0.2f, 0.2f, 1f));
pv.attachScene(rootNode);
Node model1 = (Node) first.getProperties().get("itemModel");
((Node) combinerNode.getChild("combinerNode1")).attachChild(model1.clone());
Node model2 = (Node) second.getProperties().get("itemModel");
((Node) combinerNode.getChild("combinerNode2")).attachChild(model2.clone());
rootNode.updateGeometricState();
[/java]
ChaseCams should be used that way:
[java]
sceneCC = new ChaseCamera(theRealCam, someSpatialToFollow);
[/java]
Is this how you’ve done it?
I’ve got several cam/chaseCams that I use with different AppStates (Scenes really) but I can’t say I’ve had troubles with them. I don’t use it with other viewports though, although I do use cameras, but not chase cams with those viewports.
I’m also noticing you’re not storing that chase cam anywhere, you’re also not setting it’s min/max distance and that it’s not tied to a listener (for movement with mouse or otherwise).
In itself this shouldn’t be a problem, but it’s possible that the cam is inside an object and thus you get a black screen because of that. Is that possible?
Chase cams works fine in different app states to me too. I think this is a viewport related chasecam issue. There can not be two chasecams active at the same time (in different viewports).
In any case, I appreciate your effort in trying to help me.
That’s possible. I can’t say if it’s the case or not since I’ve never tried that, it might be interesting to have corroboration though. Unfortunately I don’t have the time right now, but maybe someone else would be willing to test this out.
As a hint, a workaround is using the Application.getCamera() chasecamera for every new viewport and translating the viewport scene in the location of the chasecamera target spatial. Of course by doing this way all the viewports are controlled by the same input manager, thus they all rotate toghether