Page 1 of 1
Collision Bounding Bodies and Models
Posted: Fri May 17, 2013 1:02 am
by bdpdonp
I am using Bullet Physics and Collision with Irrlicht. My problem is I do not understand how you get the Collision shape to match the appropriate size of the 3D model. For example I have a ship, and I will use a capsule as the collision body, how do I know what the dimensions of the capsule should be? Experimenttion seems wasteful of time.
Re: Collision Bounding Bodies and Models
Posted: Fri May 17, 2013 2:09 am
by mikkis
I havent done this by myself but I might create collision shapes with blender/3dsmax and name these COLL_* and then
parse them in code, and create shapes from them. I think with boxes this works, and maybe spheres but ellpisoids I dont know.
Or get these dimensioins in blender and put them in collision shapes name.
Just ideas. Hopefully someone knows how these should do (without creating own editor just for them). Or are there something like it already?
Re: Collision Bounding Bodies and Models
Posted: Fri May 17, 2013 2:17 am
by Seven
you can use the size of the scenenode bounding box to help.
example :
in this example, i have my own structure called IPhysicsData that houses the params that are needed, but you should be able to get the idea. I fill out the params structure inside the object creation code and then pass it to the physics world.
this is the object class function
Code: Select all
virtual void createPhysicsObject()
{
CS_LOG(L"IrrObject_Box::CreatePhysicsObject()");
// make sure the object is available
CSObject::createPhysicsObject();
// make sure the node is valid
CS_CHECK(m_Node,L"-- no node to create physics object from");
CS_CHECK(getLevel()->getPhysicsWorld(),"createPhysicsObject() - manager not valid");
// create a physics object to represent this node
IPhysicsObjectData data;
data.type = POT_PRIMITIVE_BOX;
data.position = getPosition();
data.rotation = getRotation();
data.scale = getScale();
data.mass = getMass();
data.gravity = true;
data.bboffset = getBBOffset();
data.frozen = getFrozen();
data.userdata = getId();
data.linearDamping = 1;
data.angularDamping = 1;
setPhysicsObject(getLevel()->getPhysicsWorld()->createPhysicsObject(data));
}
this is the physics world function
Code: Select all
IPhysicsObject* CSBullet281_World::createBox(IPhysicsObjectData data)
{
// data.printInfo();
CSBullet281_Object* obj = new CSBullet281_Object();
if (obj)
{
obj->initialize();
obj->create(this);
obj->setUserdata(data.userdata);
// Set the initial position of the object
btTransform Transform;
Transform.setIdentity();
Transform.setOrigin(btVector3(data.position.X,data.position.Y,data.position.Z));
// Give it a default MotionState
btDefaultMotionState *MotionState = new btDefaultMotionState(Transform);
// Create the shape
btVector3 HalfExtents(data.scale.X * 0.5f, data.scale.Y * 0.5f, data.scale.Z * 0.5f);
btCollisionShape *Shape = new btBoxShape(HalfExtents);
// Add mass
btVector3 LocalInertia;
Shape->calculateLocalInertia(data.mass, LocalInertia);
// Create the rigid body object
obj->m_RigidBody = new btRigidBody(data.mass, MotionState, Shape, LocalInertia);
obj->m_RigidBody->setDamping(data.linearDamping/2,data.angularDamping/2);
// Store a pointer to the object
obj->m_RigidBody->setUserPointer((void *)(obj));
// Add it to the world
m_World->addRigidBody(obj->m_RigidBody);
return obj;
}
else return NULL;
}
Re: Collision Bounding Bodies and Models
Posted: Fri May 17, 2013 2:30 am
by mikkis
If using bounding box, ie car, which is only one model. There is lower-part and upper-part which should use different collision shapes (because upperpart isnt as wide as lower part (when looking at side view)). So there one must still create these manually (or using per-poly collision, dont remember that shape's name).
Re: Collision Bounding Bodies and Models
Posted: Fri May 17, 2013 2:34 am
by Seven
each of those is it's own mesh right? you can get the meshbuffers and get the bounding box for each and then create the shapes.
Re: Collision Bounding Bodies and Models
Posted: Fri May 17, 2013 2:49 am
by mikkis
Im always though that it isnt performance wise to split model to multible meshes.
I dont think irrlicht frustum cull every mesh, but models, but still.
Correct if Im wrong?
Re: Collision Bounding Bodies and Models
Posted: Tue May 21, 2013 1:37 pm
by CuteAlien
Hm, in most (maybe all) games I did so far we kept physics and models separate. Which means we used bounding-boxes maybe as a first approximation, but allowed to set the physics directly. Usually with a small editor, or when it's only been a few objects then just by hand with xml's. Or you have an invisible collision geometry for each object (which then also doesn't need to be rendered).