# Camera rotating in the opposite directions

Hello, I am using flycam and noticed when I rotate the cam (orbit) a whole 180 degrees the rotation becomes opposite. In other words the right/left panning becomes left/right panning - the tilt remains correct.

Anyway to fix that?

hello,

This is how flycam work. it probably donâ€™t have configuration to change this.

you can always make your own implementation of camera control.

could you tell which element of game â€śopposite rotationâ€ť destroys?

maybe there is easier way to avoid this problem.

could you tell which element of game â€śopposite rotationâ€ť destroys?

not sure I understood you here :s

its this part:

[java] private void rotateCamera(float value, Vector3f axis){
if (dragToRotate){
if (canRotate){
// value = -value;
}else{
return;
}
}

Matrix3f mat = new Matrix3f();
mat.fromAngleNormalAxis(rotationSpeed * value, axis);

Vector3f up = cam.getUp();
Vector3f left = cam.getLeft();
Vector3f dir = cam.getDirection();

mat.mult(up, up);
mat.mult(left, left);
mat.mult(dir, dir);

Quaternion q = new Quaternion();
q.fromAxes(left, up, dir);
q.normalizeLocal();

cam.setAxes(q);
}[/java]

I need to modify something in it but whenever I modify something I break the other :s

I donâ€™t understand why you are going through 5 steps to set the rotation of the camera. Why not just create a quaternion and set it?

The regular fly cam does not have this issue.

but this is taken from the source code of FlyByCamera : http://code.google.com/p/jmonkeyengine/source/search?q=FlyByCamera&origq=FlyByCamera&btnG=Search+Trunk

So you are saying if you run one of the standard tests that uses fly cam and rotate yourself 180 degrees that the keys are backwards after that?

homsi, there are 2 options I see, I donâ€™t know what game your making, but if you just want to prevent users from going â€śupside downâ€ť then something i have used before is this:

[java]

mat.mult(up, up);

mat.mult(left, left);

mat.mult(dir, dir);

if (up.getY() < 0) {

return;

}

[/java]

To get rid of the â€śopposite panningâ€ť with a free-for-all camera, I made this quickly, thereâ€™s probably a better way:

[java]

Matrix3f mat = new Matrix3f();

mat.fromAngleNormalAxis(rotationSpeed * value, axis);

if (up.getY() < 0) {

mat.set(0, 2, mat.get(0, 2) * -1);

mat.set(2, 0, mat.get(2, 0) * -1);

}

[/java]

1 Like

how did you flip your z and y :?

i asked my buddy Neo to go into the matrix and modify it

Basically it just reverts the left/right mouse motion when the camera is upside down. This was just a quick and dirty fix, and doesnâ€™t even apply to you because your coordinates are fucked.