0 0 0 rotation different to pure opengl

I wanted to ask why the coordinate systems in pure opengl and jmonkey differ

JMonkey screenshot of the coord system with 0 0 0 rotation: https://lh5.googleusercontent.com/-b8vLur0wCy4/Ucmxm0_qvoI/AAAAAAAAWY4/CqjAf1pNcHk/w602-h289-no/jmonkeyCoordSystem.jpg

OpenGL screenshot of the coord system with 0 0 0 rotation: https://lh4.googleusercontent.com/-N6VD69sbCO8/UcmxmxNqjoI/AAAAAAAAWY8/ZvVSChD0_1E/w771-h546-no/openglCoordSystem.jpg

So the why is there a difference or is it because in opengl i change the modelview matrix and in jMonkey i change the “virtual camera” ? so in opengl I set the identity matrix :

[java]// Reset the modelview matrix
gl.glLoadIdentity();
// set the rotation
gl.glMultMatrixf(identityMatrix, 0);
gl.glTranslatef(0, 0, -14);[/java]

and in jMonkey I use camera.setRotation with a quaterion where I set the rotation matrix before. And is there a way to set the rotation like I do it in OpenGL?

Post the code on how you set up your camera in JME.
JME uses opengl system : Y top, X right, Z towards you.

Everything is correct. The jME3 camera is located at 0, 0, -10 by default so you’re looking at the scene from the opposite side.

<cite>@Momoko_Fan said:</cite> Everything is correct. The jME3 camera is located at 0, 0, -10 by default so you're looking at the scene from the opposite side.

in both images im at negative z values (-2 and -14) and x and y are 0. Also in both images I have 0 0 0 rotation but as you can see its not the same result: the coordinate axes are 180 degree rotated (or x and z are inverted?)

i use the following code to display the rotation values but i do not change the rotation manually and just use the normal fly cam controller

[java]cam.getRotation().toAngles(eulerAngles);
redXpitch = (int) (eulerAngles[0] * FastMath.RAD_TO_DEG);
greenYyaw = (int) (eulerAngles[1] * FastMath.RAD_TO_DEG);
blueZroll = (int) (eulerAngles[2] * FastMath.RAD_TO_DEG);[/java]

and to display the camera position I just use getCamera().getLocation()

So lets say I have given the opengl rotation matrix and want to use it in jmonkey, then I have to change it first before i use camera.setRotation(openglRotMatrixToJmeCameraRotMatrix(rotMatrix)) right? otherwise I will not get the same visual results because the modelview matrix is not what I have to pass to the jme camera

or is it even possible to set the model view matrix directly instead of camera.setRotation and camera.setPosition? That would be the easiest solution

In a right handed coordinate system, if you look at the origin from negative Z, then positive X will be on the left side.

Your OpenGL screenshot must be incorrect.

<cite>@Momoko_Fan said:</cite> In a right handed coordinate system, if you look at the origin from negative Z, then positive X will be on the left side. Your OpenGL screenshot must be incorrect.

in the opengl screenshot where I write that the position is 0 0 -14 its actually 0 0 14 (otherwise it would also not make sense that the blue axis is pointing out of the screen. only the gl.glTranslatef(0, 0, -14) was confusing me, so its not the camera position you set with this its the movement you apply to the center of the world, so basically 14 units away from the camera on the z axis

so the position in both images is only negative in the jme image and positive in the opengl image but why it the camera then rotated by 180 degree? because in opengl the virtual camera then looks away from the center if it would be at 0 0 -14 (so along the -egative z axis) and in jme it looks in the other direction towards the center (along the positive z axis)

@simon.heinen said: in the opengl screenshot where I write that the position is 0 0 -14 its actually 0 0 14 (otherwise it would also not make sense that the blue axis is pointing out of the screen. only the gl.glTranslatef(0, 0, -14) was confusing me, so its not the camera position you set with this its the movement you apply to the center of the world, so basically 14 units away from the camera on the z axis

so the position in both images is only negative in the jme image and positive in the opengl image but why it the camera then rotated by 180 degree? because in opengl the virtual camera then looks away from the center if it would be at 0 0 -14 (so along the -egative z axis) and in jme it looks in the other direction towards the center (along the positive z axis)

Based on your clarification of moving the world and not the camera, then in the OpenGL case, the camera is at location 0, 0, 0 and the world is at 0, 0, -14, so the camera in the OpenGL case must point towards negative Z in order to see the object and the X arrow is on the right side. In the jME3 case, the camera is at 0, 0, -2 and the world is at 0, 0, 0, so the camera must point towards positive Z to see the object (and the X arrow would appear on the left side instead of right side). Everything in the screenshots makes sense.
<cite>@Momoko_Fan said:</cite> Based on your clarification of moving the world and not the camera, then in the OpenGL case, the camera is at location 0, 0, 0 and the world is at 0, 0, -14, so the camera in the OpenGL case must point towards negative Z in order to see the object and the X arrow is on the right side. In the jME3 case, the camera is at 0, 0, -2 and the world is at 0, 0, 0, so the camera must point towards positive Z to see the object (and the X arrow would appear on the left side instead of right side). Everything in the screenshots makes sense.

Yes but I didn’t want to see the object I set the camera rotation in both images to 0 0 0
no matter where the camera is its the rotationwhich is the problem. you can see the coordinate system in both images which cant be right if the rotation would be used in jme the same way it is used in opengl… does the modelview matrix have to be inverted or something like this to get the jme rotation matrix for cam.setRotation(…) ?

I found out that in the camera class there is the viewMatrix in there which I want to set manually basically. I think there is no simple way to do this, should i create a subclass of camera and override the onFrameChange() method? But then i would also not be able to call getRotation and all these methods because all the fields would be unused. A camera.setViewMatrix method would be great but I dont know how to extract the rotation matrix out of the view matrix :confused:

I guess you will need to override Camera.onFrameChange() to generate the view matrix according to your specs. You can still use setRotation()/getRotation() and other methods, since the onFrameChange() method uses the location/rotation fields to generate the view matrix.

<cite>@Momoko_Fan said:</cite> I guess you will need to override Camera.onFrameChange() to generate the view matrix according to your specs. You can still use setRotation()/getRotation() and other methods, since the onFrameChange() method uses the location/rotation fields to generate the view matrix.

but its a one way calculation: if I want set the viewMatrix and remove the modification of it in the onFrameChange method then the values set in the rotation and translation fields of the camera will not be in sync with the viewmatrix itselt. only if I update the rotation and translation according to the current view matrix this would work i think (?)

I read that the camera matrix is the inverse of 3x3 Rotation part of the model view matrix, can somebody confirm this and explain why? In the camera class the model view matrix is calculated in a totally different way then just inverting it…

What is it that you are actually trying to do?

I don’t think it makes sense for you to use the scenegraph if you then work with the base opengl matrices. Just use OpenGL directly.

<cite>@pspeed said:</cite> What is it that you are actually trying to do?

I have a model view matrix and I have to tell the camera how to rotate and translate according to this model view matrix. So basically something like this:

cam.setRotation(rotMatFromModelViewMatrix(modelviewMatrix);
cam.setLocation(posFromModelViewMatrix(modelviewMatrix);

I think the second part I figured out, its just location=-1*(R*t); where R is the 3x3 in the model view matrix and t is the entries 12 to 14

<cite>@normen said:</cite> I don't think it makes sense for you to use the scenegraph if you then work with the base opengl matrices. Just use OpenGL directly.

With pure OpenGL its working fine, but I want to use JME for rendering and thought converting the modelview matrix to the camera rotation and translation would be the easiest solution. I mean thats all the model view matrix contains right?

In JME (and most scene graphs I imagine), the model to world matrix and the world to view matrix are not the same thing. The model view matrix would then be a composition of the model to world and world to view. It doesn’t necessarily make sense to do what you are trying to do.

Where does this model view matrix come from? Why are you trying to do this?

<cite>@pspeed said:</cite> In JME (and most scene graphs I imagine), the model to world matrix and the world to view matrix are not the same thing. The model view matrix would then be a composition of the model to world and world to view. It doesn't necessarily make sense to do what you are trying to do.

Where does this model view matrix come from? Why are you trying to do this?

Ok as I understand it if I only want to move the camera around then the model to world matrix does not matter, I do not want to move objects in the world around with my modelview matrix (maybe i sould name it view matrix because it only defines the cam rotation/translation around the world center). I get the view matrix from opencv and want to use jmonkey for rendering. It already works fine with opengl but in jme I need this conversion from view matrix to camera Rotation and translation so apply it to the camera object