Collision Bounding Bodies and Models

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
bdpdonp
Posts: 68
Joined: Sat Oct 10, 2009 6:35 am

Collision Bounding Bodies and Models

Post 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.
mikkis
Posts: 64
Joined: Mon Jan 28, 2013 2:38 pm
Location: Fi

Re: Collision Bounding Bodies and Models

Post 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?
Seven
Posts: 1034
Joined: Mon Nov 14, 2005 2:03 pm

Re: Collision Bounding Bodies and Models

Post 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;
    }
 
mikkis
Posts: 64
Joined: Mon Jan 28, 2013 2:38 pm
Location: Fi

Re: Collision Bounding Bodies and Models

Post 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).
Seven
Posts: 1034
Joined: Mon Nov 14, 2005 2:03 pm

Re: Collision Bounding Bodies and Models

Post 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.
mikkis
Posts: 64
Joined: Mon Jan 28, 2013 2:38 pm
Location: Fi

Re: Collision Bounding Bodies and Models

Post 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?
CuteAlien
Admin
Posts: 9687
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Collision Bounding Bodies and Models

Post 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).
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Post Reply