[ODE] Collisions from models

David Rogers davidrogers at mac.com
Tue May 18 04:45:31 MST 2004


Hey, thanks.  that helps a little bit.  Unfortunately I'm not using 
directx.  Good ol' opengl with lib3ds(from sourceforge) to load and 
display the models.

 From lib3ds, once a file is loaded, the structure that contains the 
models data does have an array of the meshes.  I assume then that the 
process would be similar.  Am I right?  I'm not sure how the meshes are 
ordered in the array yet(haven't looked at it that much), but would 
that matter?

thanks,

dave

On May 18, 2004, at 4:21 AM, Ivan Bolcina wrote:

> David Rogers wrote:
>
>> Hi all, I'm new to ODE and I haven't found any examples yet of how to 
>> do what I want.  I have some 3DS models that I load for a game and 
>> I'm trying to use ODE for collision detection between the models.  
>> Does anyone have an example or pointers to info on how to go about 
>> building the bboxes or whatever i need?
>>
>> thanks in advance,
>>
>> dave rogers
>>
>> _______________________________________________
>> ODE mailing list
>> ODE at q12.org
>> http://q12.org/mailman/listinfo/ode
>>
> Hi.
> You can use following pattern.
>
> 1. Convert 3ds  model to .x model.
> 2. Load .x model into hierarcy - D3DXLoadMeshHierarchyFromX
> 3. this way you can get array of boxes. You can construct ODE body 
> from it.
>
>  void SObject::createPhy()
> {
>    if (PhyUp) return;
>    PhyUp=true;
>    string bounding=entry->collision->GetBounding();
>    D3DXVECTOR3 box=entry->mesh->MainBox.b-entry->mesh->MainBox.a;
>    if (bounding=="") bounding="sphere";
>    if (bounding=="box")
>    {
>        PhyBody = dBodyCreate (app->world);
>        dBodySetGravityMode(PhyBody,1);
>        dBodySetPosition 
> (PhyBody,m_Position.x,m_Position.y,m_Position.z);
>        float vol=box.z*box.y*box.x;
>        float den=Mass/vol;
>        dMassSetBox (&m,den,box.z,box.y,box.x);
>        dBodySetMass (PhyBody,&m);
>        PhyGeom[0] = dCreateBox (app->space,box.x,box.y,box.z);
>        PhyGeomCnt=1;
>        dGeomSetBody (PhyGeom[0],PhyBody);
>    }
>    if (bounding=="boxes")
>    {
>        PhyBody = dBodyCreate (app->world);
>        dBodySetGravityMode(PhyBody,1);
>        dBodySetPosition 
> (PhyBody,m_Position.x,m_Position.y,m_Position.z);
>        float vol=box.z*box.y*box.x;
>        float den=Mass/vol;
>        dMassSetBox (&m,den,box.z,box.y,box.x);
>        dBodySetMass (PhyBody,&m);
>        for (unsigned int i=0;i<entry->mesh->Boxes.size();i++)
>        {
>            D3DXVECTOR3 kot1=entry->mesh->Boxes[i].a;
>            D3DXVECTOR3 kot2=entry->mesh->Boxes[i].b;
>            D3DXVECTOR3 mid=(kot1+kot2)*0.5f;
>            D3DXVECTOR3 diff=(kot2-kot1);
>            dGeomID skatlica=dCreateBox(0,diff.x,diff.y,diff.z);
>            dGeomID skatlicaonpos=dCreateGeomTransform(app->space);
>            dGeomTransformSetGeom(skatlicaonpos,skatlica);
>            dGeomSetPosition(skatlica,mid.x,mid.y,mid.z);
>            dGeomTransformSetCleanup(skatlicaonpos,1);
>            dGeomSetBody(skatlicaonpos,PhyBody);
>            PhyGeom[i]=skatlicaonpos;
>        }
>        PhyGeomCnt=(int) entry->mesh->Boxes.size();
>    }
>    if (bounding=="sphere")
>    {
>        PhyBody = dBodyCreate (app->world);
>        dBodySetGravityMode(PhyBody,1);
>        dBodySetPosition 
> (PhyBody,m_Position.x,m_Position.y,m_Position.z);
>        float rad=GetRadius();
>        float vol=rad*rad*rad*3.1459f;
>        float den=Mass/vol;
>        dMassSetSphere (&m,den,rad);
>        dBodySetMass (PhyBody,&m);
>        PhyGeom[0] = dCreateSphere(app->space,rad);
>        PhyGeomCnt=1;
>        dGeomSetBody (PhyGeom[0],PhyBody);
>    }
> }
>
>
> _______________________________________________
> ODE mailing list
> ODE at q12.org
> http://q12.org/mailman/listinfo/ode



More information about the ODE mailing list