New to jme - Camera problem

I was trying to rotate the camera and the only way to do it properly is to set it to look at an object.

However, this code doesn’t seem to work:

cam.setDirection(new Vector3f(3,0,0));

cam.setLocation(new Vector3f(9,9,9));

why is that? It just flips from one perspective to the other real fast (i used it in the update method)…

I just want to make a camera that is very precisely controlled. It would be great if the camera could just look wherever the mouse was pointing, but i tried some codes i found and it didn’t work. I want to make the camera very flexible based on mouse input, but i can’t even get it to look somewhere, plz help!

When you set some value to the camera in one frame (one update call) you obviously make it flip from one position to the other. You have to make the movement gradually over multiple frames, theres also a CameraControl that does this and creates a trailing camera for objects. However the basic misunderstanding about why the camera does what it should makes me suggest you to do the tutorials for jME3 first, they teach you a lot about the basics of the engine.

I have done some of the tutorials. Then i checked out the intermediate and advanced ones.

this was quite helpful, but the rotations didn’t work out as i wanted, because i was rotating the camera itself. So i thought i should have an object which the camera is looking at

i tried this one…which simply refuses to work. (The spatial isn’t a mesh though, it’s just a node)

and finally, the update code i provided is all the code i put in there…So it should be looking in just one place. There’s no actual update to the location (or is there?)

the tutorials are great btw!

The first frame is set up in initSimpleApplication(), then update() is being called each frame. The code in the wiki that “refuses to work” should work just fine. For a better idea on the jme3 math you will need to place, rotate and move the stuff in your game, see this:

thanks normen!

Also, sorry, i meant it flips constantly from one to the other, not just once!!

Thanks, i just understood quaternions from ur presentation…after visiting wikipedia and understanding nothing…Your tutorial on them is just amazing…Ur the best!

Thank you :slight_smile: jME makes using the math behind Quaternions pretty easy actually. Really understanding them is a whole different matter but most people using them (including me) don’t anyway, its hard to think in 4 dimensions and its not needed :wink:

The back and forth is due to the cameraControl that is attached, do flyCam.disable(). Again, all these little things are mentioned in the basic tutorials, even if you don’t want to do whats shown there immediately, they are an immense help to accumulate jme knowledge.

Ok, ur quaternion concatenation advice was just perfect. This is just the effect i wanted to make. Like independent rotations!

If anyone is looking for the code:

private AnalogListener analogListener = new AnalogListener() {

public void onAnalog(String name, float value, float tpf) {

Quaternion Q1 = new Quaternion();

Quaternion Q2 = new Quaternion();

Q1.fromAngleAxis(AxisY, Vector3f.UNIT_X);

Q2.fromAngleAxis(AxisX, Vector3f.UNIT_Y);

if (name.equals(“Look Left”)) {

AxisX += 0.01f; // AxisX and AxisY are floats


if (name.equals(“Look Right”)) {

AxisX -= 0.01f;


if (name.equals(“Look Up”)) {

AxisY += 0.01f;


if (name.equals(“Look Down”)){

AxisY -= 0.01;





Thanks again!!!

1 Like

Note that you can also interpolate between two Quaternions using quat.slerp() (maybe helpful for going the smoothing route).

Good to see the tutorial had the intended effect, have (more) fun with jME3! :wink: