Camera : setUp() ? --Solved

Hello,

I’ve seen the page https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:advanced:camera?s[]=frustrum

which describe how to manipulate camera.



I can’t acess the method setUp() from my element cam.

All I want to do is setup my Camera with (0,1,0) for the up axis.



[java]

//Initialize camera

cam.setLocation( mainView.getCameraInitialPosition() );

cam.setDirection( mainView.getCameraInitialDirection());

//cam.setUp(…) ?

[/java]



There is a method setFrustrum(…) but I don’t understand how it works.

You don’t need to call this method, the camera up vector is 0,1,0 by default

Yep, by default it’s (0,1,0) but when I’m moving my camera with

[java]

cam.setLocation( mainView.getCameraInitialPosition() );

cam.setDirection( mainView.getCameraInitialDirection());

[/java]



The frustrum moved and my camera looses its verticality:

And I need to set it back after that. :frowning:

Ok I see, you probably create incorrect rotation if you just change the direction vector, in that case, setting the up to 0,1,0 won’t help since its already set to that.

What you probably need to do is update the left vector of the camera by taking the cross product of the direction and up vector.

Alternatively, you can also use quaternion for the camera’s rotation and update its direction using Quaternion.lookAt().

Ok, nice!



I’ve solved my problem like that :

[java]

this.cam.setLocation( position );

this.cam.setDirection( direction );

[/java]



Changed to :

[java]

this.cam.setLocation( position );

//this.cam.setDirection( direction );

this.cam.getRotation().lookAt(direction, new Vector3f(0,1,0) );

this.cam.update();

[/java]



This works well.



Thanks