Author Topic: Max Camera Matrix to JPCT  (Read 12694 times)

Offline AGP

  • quad
  • ******
  • Posts: 1726
    • View Profile
Max Camera Matrix to JPCT
« on: September 24, 2010, 05:12:42 pm »
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.

Code: [Select]
      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;
      }

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Max Camera Matrix to JPCT
« Reply #1 on: September 25, 2010, 09:22:08 pm »
I'm confused...what is the input matrix and what's the expected result and the actual result?

Offline AGP

  • quad
  • ******
  • Posts: 1726
    • View Profile
Re: Max Camera Matrix to JPCT
« Reply #2 on: September 25, 2010, 09:30:21 pm »
The input matrix are the values I got from 3ds max maxscript console. The above method is called like so:

Code: [Select]
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);

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Max Camera Matrix to JPCT
« Reply #3 on: September 25, 2010, 09:33:42 pm »
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.

Offline AGP

  • quad
  • ******
  • Posts: 1726
    • View Profile
Re: Max Camera Matrix to JPCT
« Reply #4 on: September 25, 2010, 09:40:47 pm »
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.

Code: [Select]
     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);
      }
« Last Edit: September 25, 2010, 09:48:22 pm by AGP »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Max Camera Matrix to JPCT
« Reply #5 on: September 25, 2010, 09:50:53 pm »
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?

Offline AGP

  • quad
  • ******
  • Posts: 1726
    • View Profile
Re: Max Camera Matrix to JPCT
« Reply #6 on: September 25, 2010, 10:10:16 pm »
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.
« Last Edit: September 25, 2010, 11:17:06 pm by AGP »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Max Camera Matrix to JPCT
« Reply #7 on: September 25, 2010, 10:21:49 pm »
Can you access max matrix represention so that you can post a matrix from max that does that simple 90° down look?

Offline AGP

  • quad
  • ******
  • Posts: 1726
    • View Profile
Re: Max Camera Matrix to JPCT
« Reply #8 on: September 25, 2010, 10:35:40 pm »
I'm downloading a Max trial right now, since I'm not home, but it'll take a little while, buddy.

Offline AGP

  • quad
  • ******
  • Posts: 1726
    • View Profile
Re: Max Camera Matrix to JPCT
« Reply #9 on: September 26, 2010, 01:36:14 am »
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])

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Max Camera Matrix to JPCT
« Reply #10 on: September 26, 2010, 10:06:05 am »
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.

Offline AGP

  • quad
  • ******
  • Posts: 1726
    • View Profile
Re: Max Camera Matrix to JPCT
« Reply #11 on: September 26, 2010, 06:07:18 pm »
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.

Offline AGP

  • quad
  • ******
  • Posts: 1726
    • View Profile
Re: Max Camera Matrix to JPCT
« Reply #12 on: September 28, 2010, 01:46:47 am »
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.
« Last Edit: September 28, 2010, 02:28:56 am by AGP »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Max Camera Matrix to JPCT
« Reply #13 on: September 28, 2010, 12:25:26 pm »
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
   
   
Code: [Select]
    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.

Offline AGP

  • quad
  • ******
  • Posts: 1726
    • View Profile
Re: Max Camera Matrix to JPCT
« Reply #14 on: September 28, 2010, 05:15:35 pm »
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?