0
votes

Hi I have a camera projection matrix and I want to get the corresponding camera transform matrix.

The projection matrix(P) is 3*4, which converts a 3D-point's homogeneous coordinate into a planar homogeneous coordinate.

Now in my scenario, I can only specify the camera transform matrix, which describes how the camera is positioned. So how can I get the matrix transform matrix from camera projection matrix?

Edit

The projection matrix is read from a dataset, and I'm trying to render that data. But the render takes in the camera transform matrix in size 3*4, while the dataset provides the projection matrix 3*4. The difference of these two matrices are: the transform matrix is congruent, while the projection is not. Passing the projection matrix directly into the transform generates the "non-congruent transform on camera" error.

1

1 Answers

0
votes

EDIT

OK, so the rendering library has a fixed projection that you can't change but you still want to use your own. A standard perspective transform is indeed non-congruent due to a divide by zero (the matrix itself is congruent though afaik, are you sure the dataset doesn't provide an invalid projection matrix?) but since all points are clipped between the near and far planes there generally isn't an issue.

If you can extract the actual projection matrix used by the rendering engine, perhaps you can calculate the matrix that when multiplied with it produces the desired projection matrix.

  • The library does this: csVert = libProjectionMat * M * objectMat * osVert, where M is the camera transform provided to the library
  • You want this: csVert = myProjectionMat * myCameraMat * objectMat * osVert
  • But you can only set M
  • Thus find M for libProjectionMat * M = myProjectionMat * myCameraMat
  • libProjectionMatInverse * libProjectionMat * M = libProjectionMatInverse * myProjectionMat * myCameraMat
  • M = libProjectionMatInverse * myProjectionMat * myCameraMat

Then pass M as your camera transform. If the library still reports M as non-congruent, I don't think there's much you can do. It sounds like a pretty inflexible library.


It's common to work with 4x4 matrices all the way through, is there any reason for 3x4? The combined matrix is projection * camera (or projection * view). There might also be an object/model transform too, in which case mvp = projection * view * model (all standard matrix multiples). This matrix takes a vertex in object space all the way to 2D clip space (don't forget to divide by w to normalize the homogeneous coordinates, but only after any interpolation has occurred).

Your question is a little unclear.
If you can only specify a single matrix in your scenario, does passing in mvp or projection * view solve your problem?

If you have the final matrix and want to extract the view * model component, you could multiply mvp by the inverse projection: mv = projectionInv * mvp. This is more expensive and of course less accurate than just keeping all matrices and/or combinations separate.