Thanks.
"im going crazy"
![Shocked :shock:](./images/smilies/icon_eek.gif)
heh
Code: Select all
1. Create NewtonWorld
2. Create objects
a. Define NewtonCollision
b. Create NewtonBody
c. Set Body Properties
- You have to repeat step 2 for each body you are creating
3. Update Simulation
4. Destroy NewtonWorld
Code: Select all
// 1. Create NewtonWorld
NewtonWorld nWorld = NewtonCreate(NULL, NULL);
// 2. Create Objects
//a. Define NewtonCollision
NewtonCollision* myShape = NewtonCreateBox(nWorld, 10,10,10, NULL);
//b. Create NewtonBody
NewtonBody* myBody = NewtonCreateBody(nWorld, myShape);
//c. Set Body Properties
NewtonBodySetMassMatrix(myBody, 1.0f, 1.0f, 1.0f, 1.0f);
// 3. Update Simulation
// inside your while{} loop
while (Looping==true)
{
NewtonUpdate(nWorld, 0.01);
}
// 4. Destroy World
NewtonDestroy(nWorld);
Code: Select all
static void setForceAndTorque(const NewtonBody* body)
{
float mass;
float Ixx;
float Iyy;
float Izz;
NewtonBodyGetMassMatrix (body, &mass, &Ixx, &Iyy, &Izz);
core::vector3df force(0, -mass * 9.8, 0.0);
core::vector3df torque(0, 0, 0);
NewtonBodyAddForce(body, &force.X);
NewtonBodyAddTorque(body, &torque.X);
}
Code: Select all
static void setTransform(const NewtonBody* body, const float* matrix)
{
//get graphic object
ISceneNode* node = (ISceneNode*) NewtonBodyGetUserData(body);
//copy matrix to an irrlicht matrix
core::matrix4 mat;
memcpy(mat.M, matrix, sizeof(float)*16);
//set transformation
node->setPosition(mat.getTranslation() * NewtonToIrr); //Adjust scales, NewtonToIrr = 32. You can find why in the Newton forum.
}
Code: Select all
NewtonToIrr
MikeR wrote:I've seen this a lot in these examples, but have no clue where it is comming from. What file has this in it?Code: Select all
NewtonToIrr
Well this is a point which drived me crazy a while ago.MarcoTMP wrote:in step 2.c. you add this line
NewtonBodySetForceAndTorqueCallback(myBody, setForceAndTorque);
Now newton will call your function setForceAndTorque each time you call NewtonUpdate().
Code: Select all
NewtonBodySetAutoFreeze( body, 0 );
NewtonWorldUnfreezeBody( nWorld, body );