Max Camera Matrix to JPCT

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

Previous topic - Next topic

EgonOlsen

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.

AGP

Didn't work, Egon. I can't see anything.

EgonOlsen

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.

EgonOlsen

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.

AGP

#19
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?

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

EgonOlsen

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

AGP

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?

EgonOlsen

Quote from: AGP on September 28, 2010, 09:28:24 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!?

AGP

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?

paulscode

Quote from: AGP on September 28, 2010, 09:05:01 PMWhen 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.

Quote from: AGP 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?
Correct as long as the camera is aligned with the cardinal directions.

AGP

QuoteThis 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?

QuoteCorrect 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! : -)

paulscode

Quote from: AGP on September 28, 2010, 10:31:09 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.

AGP

I flipped the values now and, unfortunately, no cigar. I see nothing on screen.

EgonOlsen

Quote from: AGP on September 28, 2010, 10:31:09 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 ???

paulscode

Quote from: AGP on September 28, 2010, 10:45:13 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.