Fragmenting Objects

minnit_s

11-12-2007 17:12:24

Hi, I want to create objets (cubes for example) and fragment it when it collide with something. I have found informations about Physix (see at the end of this text) and how to do this but i don't understand how to do the same thing with NxOgre. I'm french so scuse me for my poor english.

NxReal boxStartHeight = iNumBoxesOnSide * fCubeSide * 2.0f;

// We need to add the main object to our scene
NxActorDesc actorDesc;
NxBodyDesc bodyDesc;

// The actor here is a compound: a cube with iNumBoxesOnSide cubes on a side, and thus is made of iNumBoxesOnSide^3 objects.
NxBoxShapeDesc boxDesc[iNumBoxesOnSide*iNumBoxesOnSide*iNumBoxesOnSide]; // it's a cube with n cubes on a side, so we need n^3 boxes

// Loop through all of the cubes
for ( int i=0; i<iNumBoxesOnSide; ++i )
{
for ( int j=0; j<iNumBoxesOnSide; ++j )
{
for ( int k=0; k<iNumBoxesOnSide; ++k )
{
// The dimensions are determined by fCubeSide
int iCurrentIndex = i * (iNumBoxesOnSide * iNumBoxesOnSide) + j * iNumBoxesOnSide + k;
boxDesc[ iCurrentIndex ].dimensions.set( fCubeSide, fCubeSide, fCubeSide );

// We need to place it in the right spot, relative to the main actor
boxDesc[ iCurrentIndex ].localPose.t.set(
NxVec3(
((i-1) * fCubeSide * 2.0f),
((j-1) * fCubeSide * 2.0f),
((k-1) * fCubeSide * 2.0f)
)
);

// Push it on to our shapes array
actorDesc.shapes.pushBack(&boxDesc[iCurrentIndex]);

// Track the number of objects globally so we can apply an appropriate force to the object
++iNumberObjects;
}
}
}

actorDesc.body = &bodyDesc;
actorDesc.density = 10;
actorDesc.globalPose.t = NxVec3(0,boxStartHeight,0);
return gScene->createActor(actorDesc);

betajaen

11-12-2007 17:25:16

Something like.

int size=3;
Vector3 pos(0,8,0);
Actor* lastB = 0;
JointParams jp;
jp.setToDefault();
jp.mBreakableMaxForce = 300;
jp.mBreakableMaxTorque = 300;

for (int x=0;x < size;x++) {
for (int y=0;y < size;y++) {
for (int z=0;z < size;z++) {
Body* b = mScene->createBody("fragment;cube.1m.mesh", new CubeShape(1), pos + Vector3(x,y,z), "mass: 10");
if (lastB != 0)
b->joinWith(lastB, jp)
lastB = b;
}
}
}


The code is rough though, and I think it's what you want.

minnit_s

11-12-2007 20:28:57

It's work but I need rigid joint, each actor must move with others. Actually i have elasticum reactions. I have read some tutorials of Ageia about joints and i don't understand how do it. I think i must modify parameters of the JointParams but there is a lot of choices. A documentation for NxOgre exists ?

minnit_s

12-12-2007 14:59:56

I set jp.mJointProjectionDistance jp.mJointProjectionAngle to a little value to limite distance between joints but it doesn't work. Another idea to do this?

betajaen

12-12-2007 15:10:20

joinWith is a short cut function to create a NxFixedJoint(FixedJoint in NxOgre), you should look at the FixedJoint class itself, and implement it in the standard way of doing it.

If you are unsure then the NxFixedJointDescription class member variables have almost the same variable names in the JointParams.