Max Camera Matrix to JPCT

Started by AGP, September 24, 2010, 05:12:42 PM

Previous topic - Next topic

AGP

The following have been my attempts at converting 3ds max's camera matrix into jPCT's. None have worked (and I've since forgotten the Maxscript to even get the camera's matrix!). Anyway, if anyone could help with this I would really appreciate it.


      private Matrix convertMaxToJpctMatrix(Matrix toConvert) {
Matrix newMatrix = new Matrix(toConvert);
Matrix transformer = new Matrix();
float[] transformerValues = {1f, 0f, 0f, 0f,0f, 0f, -1f, 0f,0f, 1f, 0f, 0f,0f,0f,0f,1f};
// float[] transformerValues = {1f, 0f, 0f, 0f, 0f, -1f, 0f, 0f, 0f, 0f, -1f, 0f, 0f,0f,0f,1f};
transformer.setDump(transformerValues);
/**
[ 1 0 0 ]
[ 0 0 1 ]
[ 0 1 0 ]*/
/**1st
1  0  0  0
0  0 -1  0
0  1  0  0
0  0  0  1
2nd:
0  -1  0  0
0  0 -1  0
1  0  0  0
0  0  0  1
3rd (ON THE LEFT:
1.0     -0.0    0.0     0.0
0.0     -1.0    0.0f     0.0
0.0     0.0f    -1.0    0.0
0.0     0.0     0.0     1.0
*/
newMatrix.matMul(transformer);
// transformer.matMul(newMatrix);
return newMatrix;
      }

EgonOlsen

I'm confused...what is the input matrix and what's the expected result and the actual result?

AGP

The input matrix are the values I got from 3ds max maxscript console. The above method is called like so:

theCamera.setFOVLimits((float)Math.toRadians(10), (float)Math.toRadians(170));
theCamera.setFOV((float)Math.toRadians(34.254));
Matrix cameraMatrix = new Matrix();
// float[] maxMatrix = {-0.0860526f,-0.996188f,-0.0143083f, 0.543894f,-0.0590056f,0.837077f,-0.83473f,0.0642504f,0.546898f,-86.031f,21.7374f,75.9077f};
float[] maxMatrix = {-0.0860526f,0.543894f,-0.83473f,0f,-0.996188f,-0.0590056f,0.0642504f,0f,-0.0143083f,0.837077f,0.546898f,0f,15.3374f,-15.4662f,-114.723f,1f};
cameraMatrix.setDump(maxMatrix);
cameraMatrix = convertMaxToJpctMatrix(cameraMatrix);
SimpleVector cameraPosition = new SimpleVector(-86.031f, 21.7374f, 75.9077f);//IN MAX: -86.031,21.7374,75.9077
theCamera.setBack(cameraMatrix);
theCamera.setPosition(cameraPosition);

EgonOlsen

What i actually meant was something like:

This is the max matrix: <matrix>...it rotates the camera around <whatever> <some> degrees

This is the jPCT is would expect: <matrix>

This is what i get: <matrix>

I'm having a real hard time figuring out how to convert them, if i have no idea what the initial matrix looks like and what it is supposed to do.

AGP

#4
OK, the variable named maxMatrix is the Max Matrix. The expected result is that I would be looking at the exact same thing in a jPCT scene as I am in Max, but instead the camera is always facing (and is positioned) somewhere else. The scene is of that QG 2.5d game I've been doing for nearly two years and, since I'm nearly finished now, I need to address this issue. Right now, I have made an approximation with the following method, but I need an exact result, since the backgrounds in this game are all 2D.

Oh, and the camera will never move in this game (the backgrounds, as said, are 2D screens). I can't get the position and rotation in Max of the camera until Monday, when I can get to the Max scene and check, sorry.

     private void oldCamera() {
SimpleVector cameraPosition = hero.getTransformedCenter();
cameraPosition.z -= 32;
theCamera.rotateCameraX((float)Math.toRadians(35));//ORIGINALLY 20
theCamera.setPosition(cameraPosition);
theCamera.moveCamera(Camera.CAMERA_MOVEUP, 33.2f);
theCamera.moveCamera(Camera.CAMERA_MOVELEFT, 12f);//14f
theCamera.moveCamera(Camera.CAMERA_MOVEOUT, 140f);//14f ORIGINALLY
theCamera.setFOVLimits((float)Math.toRadians(5), (float)Math.toRadians(175));
theCamera.setFOV(theCamera.getFOV()/3.2f);
     }

EgonOlsen

Do you have any information about the kind of matrix (row-/column-major) and the coordinate system max is using? How, you example, does a matrix look like that makes the camera facing 90° down?

AGP

#6
I'm fairly sure Max uses 4x4 row major matrices, and, I also read that rotations in max are backwards (Max is right-handed, but the rotations are left-handed). In the Max orthographic viewports, X points right, Y points up, and Z points out of the screen toward you. Worldspace coordinate system is such that X runs in a positive direction to the right, Z runs in a positive direction upward, and Y runs in a positive direction away from you.

EgonOlsen

Can you access max matrix represention so that you can post a matrix from max that does that simple 90° down look?

AGP

I'm downloading a Max trial right now, since I'm not home, but it'll take a little while, buddy.

AGP

Got it. Took me longer to remember the damn dollar sign than to download it :- )

This camera faces down on the viewport. Again, in worldspace coordinate system X runs in a positive direction to the right, and Y runs in a positive direction away from you, Z runs in a positive direction upward. $Camera001.transform gives: (matrix3 [1,0,0] [0,1,0] [0,0,1] [0,0,0])

EgonOlsen

That's an identity matrix, i.e. the camera hasn't roated at all. What i meant was a matrix from a camera that has a simple but defined rotation like 90° around X or something like that.

AGP

Sorry, I was in a hurry to leave for a wedding last night but I wanted to get this done first. The thing is, I don't know anything about MaxScript and Google isn't helping much. I'll look up how to get the rotation matrix and post back.

AGP

#12
When I rotate it so that the camera is facing forward on the viewport, the camera's matrix reads (matrix3 [1,0,0] [0,0,1] [0,-1,0] [0,0,0]). Does that help?

That was positive 90º on x, by the way.

EgonOlsen

I'm not sure, if my thinking is correct, but this looks very much like a normal GL like matrix. So to convert it, it would think that
   
   
    float[] mat={1,0,0,0, 0,0,1,0, 0,-1,0,0, 0,0,0,1};
    Matrix m=new Matrix();
    m.setDump(mat);
        m.transformToGL();

   
should do the trick. I'm abusing the transformToGL-method here to actually do the opposite. A simple rotation around X with 90° will have the same effect, but this is cheaper.

AGP

I don't get it: where do these values come from? I mean, I noticed the pattern of the extra 0 for the first rows and the extra 1 for the last, but is that what I need to add every time?