Collision Object and Scaling

stnal

22-11-2010 16:27:01

Hi all,

Is it possible to scale a trimesh?
I've loaded a mesh, scaled it and then created a trimesh out of it using StaticMeshToShapeConverter but the physical shape is original size.
Do I need to provide a transform matrix? how do I build it?

Thanks,
Stan

Fish

22-11-2010 18:20:37

Yes. You'll probably want to use a btScaledBvhTriangleMeshShape.


// Create the rigid body as usual.
OgreBulletDynamics::RigidBody *body = new OgreBulletDynamics::RigidBody(uniqueName, mPhysics);

// Create a converter that converts the mesh of the entity to a collision shape.
MMOnsterStaticMeshToShapeConverter *trimeshConverter = \
new MMOnsterStaticMeshToShapeConverter(ogreEntity);

// Create a new TriangleMeshCollisionShape using the converter data.
// Your app is responsible for deleting the sceneTriMeshShape when you are done with it.
OgreBulletCollisions::TriangleMeshCollisionShape *sceneTriMeshShape = trimeshConverter->createTrimesh();

// Delete the converter since we are done with it.
delete trimeshConverter;

// Create a btScaledBvhTriangleMeshShape with the TriangleMeshCollisionShape data.
// The scale data can come from your ogreEntity.
btScaledBvhTriangleMeshShape *collisionShape = \
new btScaledBvhTriangleMeshShape((btBvhTriangleMeshShape*)(sceneTriMeshShape->getBulletShape()), \
btVector3(scale.x, scale.y, scale.z));

// Set the body shape.
body->setStaticShape(collisionShape, mBodyRestitution, mBodyFriction, mPosition, mQuaternion);


I hope that helps you.

- Fish

stnal

22-11-2010 21:35:26

Thanks, that's awesome!

By the way, I need to use only the collision detection feature so what I've done I used OgreBulletCollisions::CollisionsWorld, and I added a OgreBulletCollisions::Object to it using the setShape method.

1. Is OgreBulletCollisions::Object like RigidBody for collision detection?
2. Do I need to call mWorld->discreteCollide(); every frame?

Thanks,
Stan

Thrakbad

18-12-2010 13:49:55

Hi, I just tried the above method, but the compiler throws an error, because it says it cannot convert from btScaledBvhTriangleMeshShape* to OgreBulletCollisions::CollisionShape *. How did you get this to work?

Edit: I found out myself, I was calling the wrong function, nevermind