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

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11745
    • View Profile
    • http://www.jpct.net
Re: Max Camera Matrix to JPCT
« Reply #15 on: September 28, 2010, 05:54:46 pm »
This is just to make a 4x4 matrix out of this 3x4 matrix. Just add a 0 in each row but the last and a 1 in the last.

Offline AGP

  • quad
  • ******
  • Posts: 1516
    • View Profile
Re: Max Camera Matrix to JPCT
« Reply #16 on: September 28, 2010, 07:08:40 pm »
Didn't work, Egon. I can't see anything.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11745
    • View Profile
    • http://www.jpct.net
Re: Max Camera Matrix to JPCT
« Reply #17 on: September 28, 2010, 08:57:42 pm »
Then...be creative. I mean, what can be different between 3ds and jPCT? The matrix order (row/column-major), the coordinates system...or 3ds stores something really strange in that matrix.

So i would do the following to find out:

  • leave out the transform2GL call
  • try to transpose the matrix (with and without transform2GL)
  • last idea: Try to invert it. Maybe 3ds uses an inverted matrix for whatever reason...

Create yourself a simple testcase in 3ds with a cube or something that is viewed by a camera with a simple transformation. Load that cube, place it like in 3ds and try to make the jPCT matrix match the view in 3ds.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11745
    • View Profile
    • http://www.jpct.net
Re: Max Camera Matrix to JPCT
« Reply #18 on: September 28, 2010, 09:01:14 pm »
And don't forget to make this 3x4->4x4 step every time. That's definitely needed no matter what else you do to the matrix.

Offline AGP

  • quad
  • ******
  • Posts: 1516
    • View Profile
Re: Max Camera Matrix to JPCT
« Reply #19 on: September 28, 2010, 09:05:01 pm »
I added the 0s and the 1. When I commented-out the entire matrix thing and set the FOV to 45 (as it is in Max), and entered the position of the camera (-y/z flipped) and set camera.lookAt to the position of Max's camera's target, I got a camera looking sideways at the scene (as if it had been jpctY-rotated 90 around the center of the scene). But I got to see the characters (the height was right). Bizarre, right?

Code: [Select]
   theCamera.setFOVLimits((float)Math.toRadians(10), (float)Math.toRadians(170));
    theCamera.setFOV((float)Math.toRadians(45));
    theCamera.setPosition(new SimpleVector(-51.598f, -59.977f, 26.276f));
/*    float[] mat = {-0.147809f,-0.989015f,0f,0f,
 0.581329f,-0.0868801f,0.809016f,0f,
 -0.80013f,0.11958f,0.587785f,0f,
 -51.5975f,26.2763f,59.9766f,1f};
    Matrix m = new Matrix();
    m.setDump(mat);
    m.transformToGL();
    theCamera.setBack(m);
*/

    theCamera.lookAt(new SimpleVector(-24.935f, -40.39f, 22.292f));
« Last Edit: September 28, 2010, 09:07:19 pm by AGP »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11745
    • View Profile
    • http://www.jpct.net
Re: Max Camera Matrix to JPCT
« Reply #20 on: September 28, 2010, 09:25:30 pm »
Might be an artifact of lookAt(). There are unlimited ways to stand at some position and look at another, because you can always rotate around the direction vector and "look at" is still true. If you already have the camera's position and a target to look at...maybe you have an up vector too? In that case, you might want to use setOrientation() instead, where the direction vector is the vector between the target and the position (i.e. target-position).

Offline AGP

  • quad
  • ******
  • Posts: 1516
    • View Profile
Re: Max Camera Matrix to JPCT
« Reply #21 on: September 28, 2010, 09:28:24 pm »
Without the transformToGL call some of the characters show up rotated as if they were lying on the ground, but in a weird position on screen. I wish I was on more sure-footing on this, man, so I can't very well get creative.

How do I get an up-vector?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11745
    • View Profile
    • http://www.jpct.net
Re: Max Camera Matrix to JPCT
« Reply #22 on: September 28, 2010, 09:44:46 pm »
How do I get an up-vector?
No idea...it's possible to derive it from the cam's rotation matrix, but if that one would be working, you wouldn't need it in the first place...so...isn't it possible to get it from max? I mean you can get obviously get the position and the target. Both are worth nothing without the up vector, so there should be a way to get it!?

Offline AGP

  • quad
  • ******
  • Posts: 1516
    • View Profile
Re: Max Camera Matrix to JPCT
« Reply #23 on: September 28, 2010, 10:15:45 pm »
Question: is the up-vector just, say, a (0, 1, 0)-type of vector? Meaning are there only three (or six with negative values) possibilities for it?

Offline paulscode

  • double
  • *****
  • Posts: 863
    • View Profile
    • PaulsCode.Com
Re: Max Camera Matrix to JPCT
« Reply #24 on: September 28, 2010, 10:22:01 pm »
When I commented-out the entire matrix thing and set the FOV to 45 (as it is in Max), and entered the position of the camera (-y/z flipped) and set camera.lookAt to the position of Max's camera's target, I got a camera looking sideways at the scene (as if it had been jpctY-rotated 90 around the center of the scene). But I got to see the characters (the height was right). Bizarre, right?
This sounds like you have the wrong coordinate system.  The fact that you see the characters should mean that the target position is in the same coordinate system as the camera lookAt position, but the fact that in jPCT's coordinate system everything is rotated and you are looking from the side could mean that the entire scene (including the lookAt vector you are using) is rotated 90 around the jPCT camera's y-axis.  You should be able to just flip the x and z coordinates (in camera space) for the object positions and the camera lookAt vector (leave the camera in the position you have it), to have everything oriented properly.

Question: is the up-vector just, say, a (0, 1, 0)-type of vector? Meaning are there only three (or six with negative values) possibilities for it?
Correct as long as the camera is aligned with the cardinal directions.

Offline AGP

  • quad
  • ******
  • Posts: 1516
    • View Profile
Re: Max Camera Matrix to JPCT
« Reply #25 on: September 28, 2010, 10:31:09 pm »
Quote
This sounds like you have the wrong coordinate system.  The fact that you see the characters should mean that the target position is in the same coordinate system as the camera lookAt position, but the fact that in jPCT's coordinate system everything is rotated and you are looking from the side could mean that the entire scene (including the lookAt vector you are using) is rotated 90 around the jPCT camera's y-axis.  You should be able to just flip the x and z coordinates (in camera space) for the object positions and the camera lookAt vector (leave the camera in the position you have it), to have everything oriented properly.

Well, jPCT's up axis is -y, whereas worldspace up for max is +z. I accounted for that. Or do you mean something else?

Quote
Correct as long as the camera is aligned with the cardinal directions.

Cool, so I go at it by trial-and-error. But here's another thing: there is no setOrientation method in Camera! : -)

Offline paulscode

  • double
  • *****
  • Posts: 863
    • View Profile
    • PaulsCode.Com
Re: Max Camera Matrix to JPCT
« Reply #26 on: September 28, 2010, 10:34:08 pm »
Well, jPCT's up axis is -y, whereas worldspace up for max is +z. I accounted for that. Or do you mean something else?

No, I mean more like the x-axis you are using is equivalent to jPCT's z-axis.

Offline AGP

  • quad
  • ******
  • Posts: 1516
    • View Profile
Re: Max Camera Matrix to JPCT
« Reply #27 on: September 28, 2010, 10:45:13 pm »
I flipped the values now and, unfortunately, no cigar. I see nothing on screen.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11745
    • View Profile
    • http://www.jpct.net
Re: Max Camera Matrix to JPCT
« Reply #28 on: September 28, 2010, 10:49:54 pm »
Cool, so I go at it by trial-and-error. But here's another thing: there is no setOrientation method in Camera! : -)
There is: http://www.jpct.net/doc/com/threed/jpct/Camera.html#setOrientation(com.threed.jpct.SimpleVector,%20com.threed.jpct.SimpleVector)   Which version are you using ???

Offline paulscode

  • double
  • *****
  • Posts: 863
    • View Profile
    • PaulsCode.Com
Re: Max Camera Matrix to JPCT
« Reply #29 on: September 28, 2010, 10:52:56 pm »
I flipped the values now and, unfortunately, no cigar. I see nothing on screen.
Is camera at 0,0,0?  If not, you'll need to subtract it from the converted vectors.  Also try reversing the sign of x, z, or both.