Problem with saving the camera position and load it back again

Hi guys,

I’m having some kind of problem with my camera handled by a FirstPersonHandler. When I start my app everything looks just fine - my camera starts at my default position with default orientation etc. and there’s no problem moving around.

But when I save my camera location, direction, left and up vectors, set everything back to default (after setting it to default it works fine) and then setting it back to my saved vectors (i use .clone() every time) it’s like my whole scene is rotated. Viewport shows just the right stuff, but when I start moving after setting camera to my saved values it looks like the scene was rotated to get the right view and not the camera, if you know what I mean.

Start at default position:

Switching to new position:

After saving camera parameters, loading them again and going manually back to the start position:

I think it’s not a big problem, but I just don’t get it… :cry:

My default values (got them via System.out.println after getting to a good starting position) and my first camera setup:

private final Vector3f DEFAULT_LOCATION = new Vector3f(7.8894286f, 2.4855723f, -22.402708f);
private final Vector3f DEFAULT_DIRECTION = new Vector3f(-0.08299516f, 0.051177584f, 0.995235f);
private final Vector3f DEFAULT_LEFT = new Vector3f(0.9965409f, 1.7462298E-10f, 0.083104104f);
private final Vector3f DEFAULT_UP = new Vector3f(0.0042530587f, 0.9986896f, 0.05100064f);


mainCam.setFrustumPerspective(45.0f, (float) width / (float) height, 1,10000);


And at least my saving and re-loading code (lastView & activeView having local Vector3f's for saving cam parameters):



P.S.: Just a little sample scene again, but same prob with my real scene.

P.P.S.: Thanks for reading so far and for maybe solving my problem.  XD

Just a suggestion for an alternative approach: Camera.lookAt() avoids the problem you are having here.

You can get a valid lookAt target by adding the source camera's direction to it's current location.

Then you'll just have to copy the location before calling lookAt on the copied camera.

Thanks for your suggestion… I tried to do it your way and my new code looks like:

Saving cam-parameters is done in the same way as before

Setting up the camera:

mainCam.lookAt(activeView.getCamLocation.clone().add(activeView.getCamDirection.clone()), new Vector3f(0,1,0));

But I'm still having the same problem as above...
if I replace the "new Vector3f(0,1,0)" in my lookAt-call with view.getCamUp() [stored Up-vector before exchanging the camera] and set mainCam.setUp(0,1,0); after it, the cam-orienation/-rotation is fine, but (once again) I have disappearing object (I think because manually setting the Up-vector to 0,1,0  ;) )
Rustysponge said:

but (once again) I have disappearing object (I think because manually setting the Up-vector to 0,1,0  ;) )

I don't entirely understand that, but this might be a frustrum culling/bounding issue.
I#m not entirely sure but i think calling updateRenderState on your scene after updating the camera should fix that.
If that's not the case it might be any of the other update...() methods...