• Create Account

### #ActualiLikeCarrots

Posted 23 April 2012 - 08:25 AM

I'm having trouble inverting my object matrix with non-uniform scaling. I have scanned the web and written the multiplication out by hand, but I haven't been able to find my error. I am creating a matrix for OpenGL, and I combine my 4x4 matrix in the order Translation, Rotation, Scale. Where could I be going wrong?

I find the position X,Y,Z in the last column
I find the scaling X,Y,Z as the lengths the first three columns
I use the upper left 3x3 matrix as the rotation
~ Inv Scale ~	 ~ Inv Rot ~  ~ Inv Pos ~
[1/X  0   0   0]   [\.......]   [1 0 0 -X]
[ 0  1/Y  0   0]   [..flip..]   [0 1 0 -Y]
[ 0   0  1/Z  0]   [diagonal]   [0 0 1 -Z]
[ 0   0   0   1]   [.......\]   [0 0 0  1]


After combining the above matrices in that order, I come up with the following code with matrix A as the result:
(GL Matrix Indices)
[0 4  8 12]
[1 5  9 13]
[2 6 10 14]
[3 7 11 15]

void invertMatrix (float A[], float B[]) {
float sclX = lengthVector(&B[0]);
float sclY = lengthVector(&B[4]);
float sclZ = lengthVector(&B[8]);

A[0] = B[0]/sclX; A[4] = B[1]/sclX; A[8]  = B[2] /sclX;
A[1] = B[4]/sclY; A[5] = B[5]/sclY; A[9]  = B[6] /sclY;
A[2] = B[8]/sclZ; A[6] = B[9]/sclZ; A[10] = B[10]/sclZ;
A[3] = 0.0;	   A[7] = 0.0;	   A[11] = 0.0;

float posX = -B[12],
posY = -B[13],
posZ = -B[14];

A[12] = A[0]*posX + A[4]*posY + A[8] *posZ;
A[13] = A[1]*posX + A[5]*posY + A[9] *posZ;
A[14] = A[2]*posX + A[6]*posY + A[10]*posZ;
A[15] = 1.0;
}


To test my inverse, I created a matrix with the following transform:
Position x=0, y=0, z=0
Rotation x=1, y=0, z=0
Scaling x=1, y=1, z=3
I multiply the inverse times the matrix, which always returns the scaling on the diagonal.
-- Object Matrix --   -- Inverse Matrix -- -- Inverse * Object --
[1.0  0.0  0.0  0.0]  [1.0  0.0  0.0 -0.0]  [1.0  0.0  0.0  0.0]
[0.0  0.5 -2.5  0.0]  [0.0  0.5  0.8 -0.0]  [0.0  1.0 -0.0  0.0]
[0.0  0.8  1.6  0.0]  [0.0 -0.8  0.5  0.0]  [0.0  0.0  3.0  0.0]
[0.0  0.0  0.0  1.0]  [0.0  0.0  0.0  1.0]  [0.0  0.0  0.0  1.0]


### #14iLikeCarrots

Posted 22 April 2012 - 09:21 AM

I'm having trouble inverting my object matrix with non-uniform scaling. I have scanned the web and written the multiplication out by hand, but I haven't been able to find my error. I am creating a matrix for OpenGL, and I combine my 4x4 matrix in the order Translation, Rotation, Scale. Where could I be going wrong?

I find the position X,Y,Z in the last column
I find the scaling X,Y,Z as the lengths the first three columns
I use the upper left 3x3 matrix as the rotation
~ Inv Scale ~	 ~ Inv Rot ~  ~ Inv Pos ~
[1/X  0   0   0]   [\.......]   [1 0 0 -X]
[ 0  1/Y  0   0]   [..flip..]   [0 1 0 -Y]
[ 0   0  1/Z  0]   [diagonal]   [0 0 1 -Z]
[ 0   0   0   1]   [.......\]   [0 0 0  1]


After combining the above matrices in that order, I come up with the following code with matrix A as the result:
(GL Matrix Indices)
[0 4  8 12]
[1 5  9 13]
[2 6 10 14]
[3 7 11 15]

void invertMatrix (float A[], float B[]) {
float sclX = lengthVector(&B[0]);
float sclY = lengthVector(&B[4]);
float sclZ = lengthVector(&B[8]);

A[0] = B[0]/sclX; A[4] = B[1]/sclX; A[8]  = B[2] /sclX;
A[1] = B[4]/sclY; A[5] = B[5]/sclY; A[9]  = B[6] /sclY;
A[2] = B[8]/sclZ; A[6] = B[9]/sclZ; A[10] = B[10]/sclZ;
A[3] = 0.0;	   A[7] = 0.0;	   A[11] = 0.0;

float posX = -B[12],
posY = -B[13],
posZ = -B[14];

A[12] = A[0]*posX + A[4]*posY + A[8] *posZ;
A[13] = A[1]*posX + A[5]*posY + A[9] *posZ;
A[14] = A[2]*posX + A[6]*posY + A[10]*posZ;
A[15] = 1.0;
}


To test my inverse, I created a matrix with the following transform:
Position x=0, y=0, z=0
Rotation x=1, y=0, z=0
Scaling x=1, y=1, z=3
I multiply the inverse times the matrix, which always returns the scaling on the diagonal.
-- Object Matrix --   -- Inverse Matrix -- -- Inverse * Object --
[1.0  0.0  0.0  0.0]  [1.0  0.0  0.0 -0.0]  [1.0  0.0  0.0  0.0]
[0.0  0.5 -2.5  0.0]  [0.0  0.5  0.8 -0.0]  [0.0  1.0 -0.0  0.0]
[0.0  0.8  1.6  0.0]  [0.0 -0.8  0.5  0.0]  [0.0  0.0  3.0  0.0]
[0.0  0.0  0.0  1.0]  [0.0  0.0  0.0  1.0]  [0.0  0.0  0.0  1.0]


### #13iLikeCarrots

Posted 22 April 2012 - 09:21 AM

I'm having trouble inverting my object matrix with non-uniform scaling. I have scanned the web and written the multiplication out by hand, but I haven't been able to find my error. I am creating a matrix for OpenGL, and I combine my 4x4 matrix in the order Translation, Rotation, Scale. Where could I be going wrong?

I find the position X,Y,Z in the last column
I find the scaling X,Y,Z as the lengths the first three columns
I use the upper left 3x3 matrix as the rotation
~ Inv Scale ~	 ~ Inv Rot ~  ~ Inv Pos ~
[1/X  0   0   0]   [\.......]   [1 0 0 -X]
[ 0  1/Y  0   0]   [..flip..]   [0 1 0 -Y]
[ 0   0  1/Z  0]   [diagonal]   [0 0 1 -Z]
[ 0   0   0   1]   [.......\]   [0 0 0  1]


After combining the above matrices in that order, I come up with the following code with matrix A as the result:
(GL Matrix Indices)
[0 4  8 12]
[1 5  9 13]
[2 6 10 14]
[3 7 11 15]

void invertMatrix (float A[], float B[]) {
float sclX = lengthVector(&B[0]);
float sclY = lengthVector(&B[4]);
float sclZ = lengthVector(&B[8]);

A[0] = B[0]/sclX; A[4] = B[1]/sclX; A[8]  = B[2] /sclX;
A[1] = B[4]/sclY; A[5] = B[5]/sclY; A[9]  = B[6] /sclY;
A[2] = B[8]/sclZ; A[6] = B[9]/sclZ; A[10] = B[10]/sclZ;
A[3] = 0.0;	   A[7] = 0.0;	   A[11] = 0.0;

float posX = -B[12],
posY = -B[13],
posZ = -B[14];

A[12] = A[0]*posX + A[4]*posY + A[8] *posZ;
A[13] = A[1]*posX + A[5]*posY + A[9] *posZ;
A[14] = A[2]*posX + A[6]*posY + A[10]*posZ;
A[15] = 1.0;
}


To test my inverse, I created a matrix with the following transform:
Position x=0, y=0, z=0
Rotation x=1, y=0, z=0
Scaling x=1, y=1, z=3
I multiply the inverse times the matrix, which always returns the scaling on the diagonal.
-- Object Matrix --   -- Inverse Matrix -- -- Inverse * Object --
[1.0  0.0  0.0  0.0]  [1.0  0.0  0.0 -0.0]  [1.0  0.0  0.0  0.0]
[0.0  0.5 -2.5  0.0]  [0.0  0.5  0.8 -0.0]  [0.0  1.0 -0.0  0.0]
[0.0  0.8  1.6  4.0]  [0.0 -0.8  0.5  0.0]  [0.0  0.0  3.0  0.0]
[0.0  0.0  0.0  1.0]  [0.0  0.0  0.0  1.0]  [0.0  0.0  0.0  1.0]


### #12iLikeCarrots

Posted 21 April 2012 - 10:45 PM

I'm having trouble inverting my object matrix with non-uniform scaling. I have scanned the web and written the multiplication out by hand, but I haven't been able to find my error. I am creating a matrix for OpenGL, and I combine my 4x4 matrix in the order Translation, Rotation, Scale. Where could I be going wrong?

I find the position X,Y,Z in the last column
I find the scaling X,Y,Z as the lengths the first three columns
I use the upper left 3x3 matrix as the rotation
~ Inv Scale ~	 ~ Inv Rot ~  ~ Inv Pos ~
[1/X  0   0   0]   [\.......]   [1 0 0 -X]
[ 0  1/Y  0   0]   [..flip..]   [0 1 0 -Y]
[ 0   0  1/Z  0]   [diagonal]   [0 0 1 -Z]
[ 0   0   0   1]   [.......\]   [0 0 0  1]


After combining the above matrices in that order, I come up with the following code with matrix A as the result:
(GL Matrix Indices)
[0 4  8 12]
[1 5  9 13]
[2 6 10 14]
[3 7 11 15]

void invertMatrix (float A[], float B[]) {
float sclX = lengthVector(&B[0]);
float sclY = lengthVector(&B[4]);
float sclZ = lengthVector(&B[8]);

A[0] = B[0]/sclX; A[4] = B[1]/sclX; A[8]  = B[2] /sclX;
A[1] = B[4]/sclY; A[5] = B[5]/sclY; A[9]  = B[6] /sclY;
A[2] = B[8]/sclZ; A[6] = B[9]/sclZ; A[10] = B[10]/sclZ;
A[3] = 0.0;	   A[7] = 0.0;	   A[11] = 0.0;

float posX = -B[12],
posY = -B[13],
posZ = -B[14];

A[12] = A[0]*posX + A[4]*posY + A[8] *posZ;
A[13] = A[1]*posX + A[5]*posY + A[9] *posZ;
A[14] = A[2]*posX + A[6]*posY + A[10]*posZ;
A[15] = 1.0;
}


To test my inverse, I created a matrix with the following transform:
Position x=0, y=0, z=0
Rotation x=1, y=0, z=0
Scaling x=1, y=1, z=3
I multiply the inverse times the matrix, which always returns the scaling on the diagonal.
-- Object Matrix --   -- Inverse Matrix -- -- Inverse * Object --
[1.0  0.0  0.0  0.0]  [1.0  0.0  0.0 -0.0]  [1.0  0.0  0.0  0.0]
[0.0  0.5 -2.5  0.0]  [0.0  0.5  0.8 -3.4]  [0.0  1.0 -0.0  0.0]
[0.0  0.8  1.6  4.0]  [0.0 -0.8  0.5 -2.2]  [0.0  0.0  3.0  0.0]
[0.0  0.0  0.0  1.0]  [0.0  0.0  0.0  1.0]  [0.0  0.0  0.0  1.0]


### #11iLikeCarrots

Posted 21 April 2012 - 10:44 PM

I'm having trouble inverting my object matrix with non-uniform scaling. I have scanned the web and written the multiplication out by hand, but I haven't been able to find my error. I am creating a matrix for OpenGL, and I combine my 4x4 matrix in the order Translation, Rotation, Scale. Where could I be going wrong?

I find the position X,Y,Z in the last column
I find the scaling X,Y,Z as the lengths the first three columns
I use the upper left 3x3 matrix as the rotation
~ Inv Scale ~	 ~ Inv Rot ~  ~ Inv Pos ~
[1/X  0   0   0]   [\.......]   [1 0 0 -X]
[ 0  1/Y  0   0]   [..flip..]   [0 1 0 -Y]
[ 0   0  1/Z  0]   [diagonal]   [0 0 1 -Z]
[ 0   0   0   1]   [.......\]   [0 0 0  1]


After combining the above matrices in that order, I come up with the following code with matrix A as the result:
(GL Matrix Indices)
[0 4  8 12]
[1 5  9 13]
[2 6 10 14]
[3 7 11 15]

void invertMatrix (float A[], float B[]) {
float sclX = lengthVector(&B[0]);
float sclY = lengthVector(&B[4]);
float sclZ = lengthVector(&B[8]);

A[0] = B[0]/sclX; A[4] = B[1]/sclX; A[8]  = B[2] /sclX;
A[1] = B[4]/sclY; A[5] = B[5]/sclY; A[9]  = B[6] /sclY;
A[2] = B[8]/sclZ; A[6] = B[9]/sclZ; A[10] = B[10]/sclZ;
A[3] = 0.0;	   A[7] = 0.0;	   A[11] = 0.0;

float posX = -B[12],
posY = -B[13],
posZ = -B[14];

A[12] = A[0]*posX + A[4]*posY + A[8] *posZ;
A[13] = A[1]*posX + A[5]*posY + A[9] *posZ;
A[14] = A[2]*posX + A[6]*posY + A[10]*posZ;
A[15] = 1.0;
}


To test my inverse, I created a matrix with the following transform:
Position x = 0, y = 0, z = 0
Rotation x = 1, y = 0, z = 0
Scaling x = 1, y = 1, z = 3
I multiply the inverse times the matrix, which always returns the scaling on the diagonal.
-- Object Matrix --   -- Inverse Matrix -- -- Inverse * Object --
[1.0  0.0  0.0  0.0]  [1.0  0.0  0.0 -0.0]  [1.0  0.0  0.0  0.0]
[0.0  0.5 -2.5  0.0]  [0.0  0.5  0.8 -3.4]  [0.0  1.0 -0.0  0.0]
[0.0  0.8  1.6  4.0]  [0.0 -0.8  0.5 -2.2]  [0.0  0.0  3.0  0.0]
[0.0  0.0  0.0  1.0]  [0.0  0.0  0.0  1.0]  [0.0  0.0  0.0  1.0]


### #10iLikeCarrots

Posted 21 April 2012 - 09:45 PM

I'm having trouble inverting my object matrix with non-uniform scaling. I have scanned the web and written the multiplication out by hand, but I haven't been able to find my error. I am creating a matrix for OpenGL, and I combine my 4x4 matrix in the order Translation, Rotation, Scale. Where could I be going wrong?

I find the position X,Y,Z in the last column
I find the scaling X,Y,Z as the lengths the first three columns
I use the upper left 3x3 matrix as the rotation
~ Inv Scale ~	 ~ Inv Rot ~  ~ Inv Pos ~
[1/X  0   0   0]   [\.......]   [1 0 0 -X]
[ 0  1/Y  0   0]   [..flip..]   [0 1 0 -Y]
[ 0   0  1/Z  0]   [diagonal]   [0 0 1 -Z]
[ 0   0   0   1]   [.......\]   [0 0 0  1]


After combining the above matrices in that order, I come up with the following code with matrix A as the result:
(GL Matrix Indices)
[0 4  8 12]
[1 5  9 13]
[2 6 10 14]
[3 7 11 15]

void invertMatrix (float A[], float B[]) {
float sclX = lengthVector(&B[0]);
float sclY = lengthVector(&B[4]);
float sclZ = lengthVector(&B[8]);

A[0] = B[0]/sclX; A[4] = B[1]/sclX; A[8]  = B[2] /sclX;
A[1] = B[4]/sclY; A[5] = B[5]/sclY; A[9]  = B[6] /sclY;
A[2] = B[8]/sclZ; A[6] = B[9]/sclZ; A[10] = B[10]/sclZ;
A[3] = 0.0;	   A[7] = 0.0;	   A[11] = 0.0;

float posX = -B[12],
posY = -B[13],
posZ = -B[14];

A[12] = A[0]*posX + A[4]*posY + A[8] *posZ;
A[13] = A[1]*posX + A[5]*posY + A[9] *posZ;
A[14] = A[2]*posX + A[6]*posY + A[10]*posZ;
A[15] = 1.0;
}


But this is what happens with pos(0,0,4) rot(1,0,0) and scale(1,1,3) ~ I don't get an identity with my inverse!
-- Object Matrix --   -- Inverse Matrix -- -- Inverse * Object --
[1.0  0.0  0.0  0.0]  [1.0  0.0  0.0 -0.0]  [1.0  0.0  0.0  0.0]
[0.0  0.5 -2.5  0.0]  [0.0  0.5  0.8 -3.4]  [0.0  1.0 -0.0  0.0]
[0.0  0.8  1.6  4.0]  [0.0 -0.8  0.5 -2.2]  [0.0  0.0  3.0  0.0]
[0.0  0.0  0.0  1.0]  [0.0  0.0  0.0  1.0]  [0.0  0.0  0.0  1.0]


PARTNERS