# Limiting rotation around only the Y axis

I’ve read the Quaternion tutorials and the rotation thing a lot of times now, but I’m unable to figure out how to limit rotation around Y axis. I used cam.getRotation().getY() to get the value for Y axis, I’m not even sure if thats an angle or not, and the I used >= to compare it to a number I got by using System.out.println() to test for maximum value. Inside the if-statement I don’t know what to put, if I use cam.setRotation() with a Quaternion, it doesn’t let me rotate at all with the mouse. If anyone can give some clues to figuring this out, I would really appreciate it.

Quaternions are rotations represented in 4D space . There are no axes.

If you want to get the rotation around the Y axis for a quaternion, use the toAngles() method

Ok, I’ll try toAngles(), but what I meant to say in my post was that I’m trying to limit the rotation for the camera, so that when you look down straight to the floor, you can’t go further than that angle, the camera is supposed to stay at rotation.

I was completely off, it had nothing to do with rotations, the problem was directions. The only problem that i have now is limiting in the up direction. is there any way of checking if direction is facing up or down?

When the y element of the cam drection is bigger or smaller than 0

this is what I have and it doesnt work:

if (cam.getDirection().y > 0 || cam.getDirection().y < 0) {

cam.getDirection().setY(0);

}

Nevermind, i got it, thanks for the help normen and momoko

never do get().set()

@normen just out of curiosity, because i am a total noob at java, why “never do get().set()”?

Doesn’t really have much to do with Java, its more like jME conventions. When you use get().set(), the class that has that vector doesn’t know you changed it, so it might have no effect or it might have a partial/buggy effect.

Calling the appropriate method like setDirection() notifies the class that the direction has changed and this update will be propagated properly through the system.

Because the object dont know you did that and doesnt update itself properly.

ok, noted. thanks.