I'm trying to make the Box2D demo work in 3D but have some problems.
My first goal is to make a pendulum (like example 6 in the demo). However I can only make it swing in one direction. I have tried calculated the M matrix but I dont think I have succeded.
Anyone wanna push me in the right direction? I'm sure someone must have tried making this excellent demo work in 3D but I couldn't find anything on the forum.
Box2D in 3D
-
- Posts: 40
- Joined: Fri Jul 22, 2005 8:00 pm
- Location: Santa Monica
If you read Erin's slides you will see an equation that is essentially:
I have written CrossProductMatrix instead of the tilda ~ so it is clearer.
All of the * are matrix multiplies. m1 and m2 are the masses of the bodies. WoldInverseInertia are the inertia tensors in world space (these will be off diagonal if the body has rotation).
You can construct a cross product matrix of a vector r1, like this:
Code: Select all
inverseMassMatrix = (1/m1 + 1/m2) * IdentityMatrix - CrossProductMatrix(r1) * WorldInverseInertia1 * CrossproductMatrix(r1) - CrossProductMatrix(r2) * WorldInverseInertia2 * CrossproductMatrix(r2)
Final Mass Matrix M = Inv(inverseMassMatrix)
All of the * are matrix multiplies. m1 and m2 are the masses of the bodies. WoldInverseInertia are the inertia tensors in world space (these will be off diagonal if the body has rotation).
You can construct a cross product matrix of a vector r1, like this:
Code: Select all
0 -r1.z r1.y
r1.z 0 -r1.x
-r1.y r1.x 0
-
- Posts: 2
- Joined: Tue Feb 20, 2007 6:52 pm
thanks for you reply
so is this a correct way to calculate the WorldInverseInertia for a box?
I haven't understood all about inertia yet so I just need to get the calculations right so I can debug and figure out how it works 
Also, I am using 4x4 matrices now (D3DXMATRIX) instead of 3x3. I just start with the identity matrix and put the 3x3 in the top left corner. This shouldn't have any effect on the calculations right? Or does it screw up the CrossProduct-matrices?
so is this a correct way to calculate the WorldInverseInertia for a box?
Code: Select all
InertiaBody:
( y*y + z*z, 0, 0 )
( 0, z*z + x*x, 0 ) * Mass / 12
( 0, 0, x*x + y*y )
R = body's rotation matrix
WorldInverseInertia = MatrixInverse(R_Transpose * InertiaBody * R)

Also, I am using 4x4 matrices now (D3DXMATRIX) instead of 3x3. I just start with the identity matrix and put the 3x3 in the top left corner. This shouldn't have any effect on the calculations right? Or does it screw up the CrossProduct-matrices?
-
- Posts: 861
- Joined: Sun Jul 03, 2005 4:06 pm
- Location: Kirkland, WA
-
- Posts: 861
- Joined: Sun Jul 03, 2005 4:06 pm
- Location: Kirkland, WA