xexuxjy / bullet-xna

Automatically exported from code.google.com/p/bullet-xna
Other
21 stars 5 forks source link

Matrix <-> IndexedMatrix conversion #19

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
-What steps will reproduce the problem?

var m = Matrix.CreateRotationY(MathHelper.PiOver2);
IndexedMatrix a = new IndexedMatrix(m);
Console.WriteLine(m);
Console.WriteLine(a.ToMatrix());

// result :
// { {M11:-4,371139E-08 M12:0 M13:-1 M14:0} {M21:0 M22:1 M23:0 M24:0} {M31:1 
M32:0 M33:-4,371139E-08 M34:0} {M41:0 M42:0 M43:0 M44:1} }
// { {M11:-4,371139E-08 M12:0 M13:1 M14:0} {M21:0 M22:1 M23:0 M24:0} {M31:-1 
M32:0 M33:-4,371139E-08 M34:0} {M41:0 M42:0 M43:0 M44:1} }

-What is the expected output? What do you see instead?
Both printed matrix should be the same, but here the basis is transposed 
(translation works fine)

-What version of the product are you using? On what operating system?
Tested on stable and last svn (187)

-Please provide any additional information below.
In the IndexedMatrix constructor, the Right, Up, and Backward properties of the 
Matrix are used as the Rows of the IndexedBasisMatrix, whereas the columns of 
the basis are used to set those three properties in the toMatrix() method.

One of the two is obviously wrong. Now when transforming coordinates vectors 
are multiplied as the right-operand in bullet and as the left one in XNA, the 
basis matrix actually need to be transposed, so I guess it's the 
Matrix->IndexedMatrix that should be corrected (so transforming a vector with a 
matrix and and it's indexed counterpart will give the same result)

Original issue reported on code.google.com by amand.be...@gmail.com on 25 Apr 2013 at 3:18

GoogleCodeExporter commented 9 years ago
Thanks, I'll have a look at this and get back to you.

Original comment by xexu...@gmail.com on 25 Apr 2013 at 8:29

GoogleCodeExporter commented 9 years ago
I believe this is correct,internally Bullet-XNA uses Indexed(Basis)Matrix which 
is transposed compared to the normal XNA Matrix - this is to keep compatability 
with the C++ version of bullet which has Matrices in that form.

I tend to use the MathUtil.PrintMatrix functions to test equivalency between 
the two different matrixes as they are aware of the conversions necessary.

Hope this helps, but please get in touch if it doesn't or you still think there 
is a problem.

Thanks,

Mark

Original comment by xexu...@gmail.com on 3 May 2013 at 12:28

GoogleCodeExporter commented 9 years ago
The problem the transposition happens when converting an indexed matrix to a 
matrix (toMatrix() method) but not when constructing an indexed matrix with a 
matrix

So when doing this:
var m1 = Matrix.CreateRotationY(MathHelper.PiOver2);
var m2 = new IndexedMatrix(m1).ToMatrix();

m1 and m2 bases aren't the same (m2 is transposed)

Original comment by amand.be...@gmail.com on 3 May 2013 at 2:14