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);



// add this here

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);



// add this here

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 :slight_smile:



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.