I’m trying out a particle system example that came out with RenderMonkey and it uses a “view inverse matrix” to billboard the quads for the particle effect.
I can see all the values from within RenderMonkey, but I can’t work out how they calculate the “view inverse matrix”, it’s not the inverse of the view matrix or the inverse of the view projection.
Here is what I know, the names are the "variable semantics":
ViewPosition:
25.044189 105.753433 240.177200 1.0
ViewProjection:
1.663676 0.483806 -.351623 -8.377671
-.790789 2.134270 -.804967 -12.567072
-.084668 -.379295 -.922480 262.789917
-.084583 -.378916 -.921558 263.527130
View:
1 0 0 0
0 1 0 0
0 0 1 -200
0 0 0 1
ViewTranspose:
.913838 .148949 -.377775 0
-.257723 .931662 -.256095 0
.313814 .331391 .889776 0
-.000004 -.000081 -200 1
ViewInverse: <-This is what I want to calculate
.941038 -.327556 .084583 25.044195
.273659 .884044 .378917 105.753433
-.198891 -.333427 .921557 240.177200
0 0 0 1
Edit, I think there's a bug in RenderMonkey, because the Viewmatrix never updates when I move, unless I activate another effect and go back to original.
From this article: http://swiftcoder.wordpress.com/2008/11/25/constructing-a-billboard-matrix/
I believe that it is:
V.a V.e V.i x
V.b V.f V.j y
V.c V.g V.k z
0 0 0 1
Where V represents the inverse of just the rotation part of the View matrix and x,y,z represent the View position. But I can't confirm until I try it, because of render monkey bug.
Confirmed, I have billboards working. Here is the java:
/**
*
* @param viewMatrix
* 4x4 (16 floats)
* @param viewPosition
* 3x1 (3 floats)
* @param resultMatrix
* 4x4 (16 floats)
*/
public static void calculateViewInverse(float[] viewMatrix,
float[] viewPosition, float[] resultMatrix) {
// derived from:
// http://swiftcoder.wordpress.com/2008/11/25/constructing-a-billboard-matrix/
// A rotation matrix is a
// "real special orthogonal matrix", which for our purposes means that
// its transpose is also its inverse.
resultMatrix[0] = viewMatrix[0];
resultMatrix[1] = viewMatrix[4];
resultMatrix[4] = viewMatrix[1];
resultMatrix[2] = viewMatrix[8];
resultMatrix[8] = viewMatrix[2];
resultMatrix[5] = viewMatrix[5];
resultMatrix[6] = viewMatrix[9];
resultMatrix[9] = viewMatrix[6];
resultMatrix[10] = viewMatrix[10];
resultMatrix[3] = viewPosition[0];
resultMatrix[7] = viewPosition[1];
resultMatrix[11] = viewPosition[2];
resultMatrix[12] = 0;
resultMatrix[13] = 0;
resultMatrix[14] = 0;
resultMatrix[15] = 1;
}