Breakable RagDoll [SOLVED]

sajan

31-12-2007 15:06:17

I'am trying to implement a breakable glass in my Ogre app. As my experience with 3D programming and with Ogre is limited, I need your help.

I tried to apply Ragdoll class from demo_08 but Ragdoll bones don't behave as I expected. I have a mesh with an armature (4 bones) and simple xml with bones definition (without joints).

Rigid bodies seem to be created correctly and they are not connected, but the problem is that the entity does not fall apart. Orientation is updated correctly but not the position of the pieces. I checked the code and tried to update _placementCallback which is used in setCustomTransformCallback but I didn't manage to achieve what I need.

void RagDoll::_placementCallback( OgreNewt::Body* me, const Ogre::Quaternion& orient, const Ogre::Vector3& pos )
{
RagDoll::RagBone* bone = RagDoll::RagBone*)me->getUserData();
RagDoll* doll = bone->getDoll();
// is this the root bone?
if (!bone->getParent())
{
Ogre::Quaternion finalorient = (orient * bone->getOffsetOrient());
Ogre::Vector3 finalpos = pos + (orient * bone->getOffsetPos());

doll->mNode->setPosition( finalpos );
doll->mNode->setOrientation( finalorient );
}
else
{
// standard bone, calculate the local orientation between it and it's parent.
Ogre::Quaternion parentorient;
Ogre::Vector3 parentpos;

bone->getParent()->getBody()->getPositionOrientation( parentpos, parentorient );

Ogre::Quaternion localorient = parentorient.Inverse() * orient;

bone->getOgreBone()->setOrientation( localorient );
}
}


I tried to put bone->getOgreBone()->setPosition( pos ) after setOrientation but it didn't work. The bones' position was updated incorrectly.

Could you please suggest what should be added to that callback?

If you don't think that this is the correct approach to the problem, could you please suggest some other way of implementing a "breakable glass"?

BTW
Although I have just started with OgreNewt, I found it very useful and I think that this is a really good piece of software - THANKS WALABER

walaber

01-01-2008 04:33:56

I don't understand exactly what you are trying to create... broken glass pieces should not need the Ragdoll class... can you please explain what you are trying to do exactly?

sajan

01-01-2008 13:33:21

I just want to break glass :)

When the bullet hits the window I would like the glass to fall into pieces.

My idea was to create a window model, split it into pieces and assign bones. Then I would create ragdoll and eather use breakable joints or remove joints on contact.

Possible? I would say it should be :) I just don't know the method.

I got stuck with the Ragdoll, but as I don't even know if that is the correct approach, I didn't want to digg deeper (if you know what I mean).

walaber

01-01-2008 18:19:22

you should make 2 models... one of the glass unbroken, and one with it broken into severral smaller meshes.

when the glass breaks, destroy the rigid body of the unbroken glass, and create several smaller rigid bodies, 1 for each broken piece.

give each piece some velocity based on the impact, and it should look pretty good!

sajan

01-01-2008 20:04:13

Excuse the stupid question but does it mean that I will have to have several .mesh files (one for each piece)?
I already have one .mesh file with all the pieces of the window, but I don't know how to assign rigid bodies to the pieces without using bones :(

walaber

02-01-2008 04:34:43

to use the default constructors that come with OgreNewt, yes, you will need a .mesh for each piece.

or, you could modify OgreNewt to create a ConvexHull from just 1 submesh / vertex group in a mesh, but that would be more complicated.

sajan

02-01-2008 09:13:45

Thanks very much for help - It was nice to see your sombrero in my post :)

I will update the post and put some avi when I have something.

Regards.