yoshinoToylogic / bulletsharp

Automatically exported from code.google.com/p/bulletsharp
MIT License
0 stars 0 forks source link

MatrixToBtTransform fix #62

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
in file src/Math.cpp
in function 
void BulletSharp::Math::MatrixToBtTransform(Matrix matrix, btTransform* t)
at line 351
you should add the line
m[15] = 1;

:)

Original issue reported on code.google.com by virusfre...@gmail.com on 24 Jan 2014 at 10:59

GoogleCodeExporter commented 8 years ago
Ah, nice find! I remember trying to figure this out. Prepare for a wall of text 
:)

btTransform consists of an orientation matrix (btMatrix3x3 = 3 x btVector3) and 
a position vector (btVector3 = 3 x float). This is different from standard 
matrix representations where position has the 4th W-component, which enables 
you to also have skew and other stuff not really needed in a physics simulation.
Not having the position.W component makes algorithms that deal with matrices 
simpler. That is, it can be assumed that m[15] == 1.0f. However, converting 
from other matrix representations (like the one in SharpDX or SlimDX) where 
m[15] != 1.0f screws things up, because this can't be represented in Bullet 
matrices.
btVector3 actually does have a fourth member, but only because of alignment, it 
is not used in any calculations. Proper alignment to 16-byte boundaries helps 
the CPU make calculations faster (on x86 platforms at least).

So I think btTransform[15] doesn't actually need any initialization anywhere, 
but I'll see if I can remember all the related aspects...

Original comment by andres.traks on 24 Jan 2014 at 1:12

GoogleCodeExporter commented 8 years ago
oh ok :) .. it didn't caused me a problem/bug or anything .. 
i just picked it up in the corner of my eye as i was browsing through the code.
Because in the other function/cases above, it is always set to 1... I thought 
it might have been left out by accident

Original comment by virusfre...@gmail.com on 24 Jan 2014 at 6:13

GoogleCodeExporter commented 8 years ago
Yep, it should at least be consistent.
btTransform->Matrix should do "m[15] = 1" and Matrix->btTransform probably 
doesn't have to.

Original comment by andres.traks on 24 Jan 2014 at 11:10