Collision shape for changing shape entities.

koirat

11-07-2009 12:52:01

I have got a body with a collision shape made from capsule. Newton Body with this shape is connected with scene node with my animated entity. When my character is standing or walking the shape is ok but when it starts to run or crouch the collision shape is very not aproperiate to actual object. I'm moving my character by adding velocity to this main Body. How can i make it compound collision so i can change the positions of sub collisions accordingly to animation.

The perfect solution for me would be something like this:
[pseudocode :P]
CompoundColision.Add(coll1,coll2,coll3);

few frames later :)

coll1.Position(newPosition)
coll2.Orientation(newOrientation)

deadvirus

11-07-2009 13:37:52

I think you can use multiple collisions connected by joints.

koirat

11-07-2009 14:10:45

You means to update joint every time shape changes. As i assume.

So what joint would you suggest. I want to suppress any movement of a bodies in relation to each other.

kallaspriit

12-07-2009 07:53:16

Perhaps use collision modifer? So for example when you crouch, you scale your collision shape to be shorter. This should be fast enough to do even every frame, but you should watch out for example when the player is crouching in a tight place and then wants to stand up. If you scale the capsule back to full height, it will start penetrating and giving trouble so you should perhaps to a raycast to see if there is enough room or not let the character stand up.

For reference on how to use the collision modifier:
// Create the collision as normal
OgreNewt::ConvexCollisionPtr collision = OgreNewt::ConvexCollisionPtr(new OgreNewt::CollisionPrimitives::Capsule(world, radius, height));

// Create collision modifier
OgreNewt::ConvexModifierCollision* modifiedCollision = new OgreNewt::ConvexModifierCollision(world, collision);

// Make it half shorter
Ogre::Vector3 scale(1.0f, 0.5f, 1.0f);

// Example of rotating the collision shape, instead pass Ogre::Quaternion::IDENTITY if you dont need rotation
// If you do use rotation, you have to take that into account in scale, in this case swapping scale.x and scale.y.
Ogre::Quaternion rotation(Ogre::Degree(90), Ogre::Vector3::UNIT_Z);

// Create the transformation matrix
Ogre::Matrix4 modifierMatrix;
modifierMatrix.makeTransform(centerOffset, scale, rotation);

// And apply it
modifiedCollision->setScalarMatrix(modifierMatrix);

OgreNewt::ConvexCollisionPtr col(modifiedCollision);

object->body = new OgreNewt::Body(world, col, objectType);

Ogre::Vector3 inertia, offset;
modifiedCollision->calculateInertialMatrix(inertia, offset);
object->body->setMassMatrix(mass, inertia * mass);
object->body->setCenterOfMass(offset);
object->body->setStandardForceCallback();

object->body->attachNode(object->node);
object->body->setPositionOrientation(position, orientation);

koirat

13-07-2009 20:30:34

Thank you that is some idea.
It is good to know that you can modify collision.
But I will try with a CustomJoint af this is not going to work I will do it your way.

nullsquared

30-07-2009 17:26:57

Use a compound collision composed by several convex hull modifiers. Each modifier can be changed separate, which would let you do exactly what you explained in your original post.