## Newton in 2D

Share with us how are you using the powerrrr of the force

Moderator: Alain

### Newton in 2D

I know its been discussed a bit, but I haven't seen a working implementation yet, so heres a short video of testing newton working in my 2D engine For those who are wondering, I've acheived 2D in newton by simply resetting the matrix in the meshtransform callback for bodies. It seems to do the trick!

Code: Select all
`void _cdecl CGame::SetMeshTransformEvent(const NewtonBody* body, const float* matrix){      dMatrix mat = dMatrix(   dVector( matrix,      matrix, 0, 0),                     dVector( matrix,      matrix, 0, 0 ),                     dVector( 0, 0, 1, 0 ),                     dVector( matrix,   matrix, 0, 0)   );   NewtonBodySetMatrix(body, &mat);}`

Mercior

Posts: 32
Joined: Sun Mar 07, 2004 8:18 pm

Nice, very nice.

Code: Select all
`dMatrix mat = dMatrix(   dVector( matrix,      matrix, 0, 0),                      dVector( matrix,      matrix, 0, 0 ),                      dVector( 0, 0, 1, 0 ),                      dVector( matrix,   matrix, 0, 0)   );    NewtonBodySetMatrix(body, &mat); `

That trick will in 1.53 cause a litle performance lost because of rearrengement of the scene internally, but is is perfectly legal in
Newton Archemedia,

How would you like to have those object to a higher count.
Or at least have the physic not be a performance concern in yor engine?
send me a PM if you are interet it.
Julio Jerez
Moderator Posts: 10945
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Great post, this one really helped me out.

Here is my code i used to realize boxes which are limited to rotation arround the z-axis and translation in the xy-plane in irrlicht.
Code: Select all
`void  Game::PhysicsSetTransform (const NewtonBody* body, const float* matrix){                irr::core::matrix4 mat;      memcpy(&mat, matrix, sizeof(float)*16);            irr::core::vector3df translation = mat.getTranslation();      translation.Z = 0;            mat.setTranslation(translation);            irr::core::vector3df rotation = mat.getRotationDegrees();      rotation.X = rotation.Y = 0;            mat.setRotationDegrees(rotation);            NewtonBodySetMatrix(body, &mat);                // ... proceed with applying this info to your render engine}`

I'd like to point out that you will get intersections when using this method with boxes that should not rotate arround any axis. 2 boxes might just "not" intersect because their rotations "fit" to each other. If you rotate one box (that's what this code does) you will most likely rotate it into another box.

If you don't know what i mean, take 2 pieces of paper, make them collide at one of the edges so one is rotated a bit but still touching the other one at the edge. Now rotate the angled piece arround it's center.

For spheres it will work again since the consumed area of sphere won't differ from the original area, even if rotated.
GreyHound

Posts: 1
Joined: Tue May 13, 2008 1:43 pm