[ODE] Trimesh-trimesh = no collision

Started by
0 comments, last by mrWodoo 12 years, 5 months ago
Hi there, I'm new to ode and I have problem with it... ode 0.11.1 with gimpact
I have two trimeshesh [this are cubes only for trimesh test] and one is 30 unit on Y axis and second is higher, so when i run my app, they are falling but when second drops on first cube, nothing happens like there is no 'first cube' to second and vice versa....


This is how i create my trimesh
HRESULT hr = D3DXLoadMeshFromX( "data/models/latus/body.X",
D3DXMESH_SYSTEMMEM,
cGame->GetDevice(),
NULL,
&m_BodyMaterialBuffer,
NULL,
&m_BodyNumMaterials,
&m_BodyMesh );

if( FAILED( hr ) )
{
return false;
}

D3DXMATERIAL* Bodyd3dxMaterials = (D3DXMATERIAL*) m_BodyMaterialBuffer->GetBufferPointer();

m_BodyMeshMaterials = new D3DMATERIAL9[m_BodyNumMaterials];
m_BodyMeshTextures = new LPDIRECT3DTEXTURE9[m_BodyNumMaterials];

for( DWORD i = 0; i < m_BodyNumMaterials; i++ )
{
m_BodyMeshMaterials = Bodyd3dxMaterials.MatD3D;
m_BodyMeshMaterials.Ambient = m_BodyMeshMaterials.Diffuse;

m_BodyMeshTextures = NULL;

if( Bodyd3dxMaterials.pTextureFilename )
{
D3DXCreateTextureFromFile( cGame->GetDevice(), Bodyd3dxMaterials.pTextureFilename, &m_BodyMeshTextures );
}
}

m_BodyMaterialBuffer->Release();


//Vertexy karoserii
D3DXVECTOR3 *p_Vertices;
BYTE *p_iVertices;

m_BodyMesh->LockVertexBuffer( D3DLOCK_READONLY, (LPVOID*) &p_Vertices );

m_VerticesCount = m_BodyMesh->GetNumVertices(); //ilosc vertexow

m_Vertices = new dVector3[ m_VerticesCount ];

for( int i = m_VerticesCount; i == 0; i-- )
{
m_Vertices[0] = p_Vertices.x;
m_Vertices[1] = p_Vertices.y;
m_Vertices[2] = p_Vertices.z;
}

m_BodyMesh->LockIndexBuffer( D3DLOCK_READONLY, (LPVOID*) &p_iVertices );

int ic = (int) m_BodyMesh->GetNumFaces() * 3;

m_iVertices = new dTriIndex[ ic ];

for( int i = 0; i < ic; i++ )
{
m_iVertices = p_iVertices;
}

m_BodyMesh->UnlockIndexBuffer();

m_BodyMesh->UnlockVertexBuffer();

m_TrimeshData = dGeomTriMeshDataCreate();
//dGeomTriMeshDataBuildSimple( m_TrimeshData, (dReal*) m_Vertices, m_VerticesCount, m_iVertices, ic );
dGeomTriMeshDataBuildSingle( m_TrimeshData, (dReal*) m_Vertices, 3 * sizeof(dReal), m_VerticesCount, m_iVertices, ic, 3*sizeof(unsigned int) );

//Dodajemy samochod do jako obiekt fizyczny aby ode go widzialo
m_ODEBody = dBodyCreate( cWorld.GetWorld() );
m_ODEGeom = dCreateTriMesh( cWorld.GetSpace(), m_TrimeshData, 0, 0, 0 );
dMassSetTrimesh( &m_ODEMass, 5, m_ODEGeom );
dGeomSetBody( m_ODEGeom, m_ODEBody );
dBodySetPosition( m_ODEBody, 0, 0, MaxSpeed );


And here is my callback
void World::CollisionCallback( dGeomID o1, dGeomID o2 )
{
int i;
// if (o1->body && o2->body) return;

// exit without doing anything if the two bodies are connected by a joint
dBodyID b1 = dGeomGetBody(o1);
dBodyID b2 = dGeomGetBody(o2);
if (b1 && b2 && dAreConnectedExcluding (b1,b2,dJointTypeContact)) return;

dContact contact[ODE_MAX_CONTACTS]; // up to MAX_CONTACTS contacts per box-box
for (i=0; i<ODE_MAX_CONTACTS; i++) {
contact.surface.mode = dContactBounce | dContactSoftCFM;
contact.surface.mu = dInfinity;
contact.surface.mu2 = 0;
contact.surface.bounce = 0.7;
contact.surface.bounce_vel = 0.1;
contact.surface.soft_cfm = 0.01;
}
if (int numc = dCollide (o1,o2,ODE_MAX_CONTACTS,&contact[0].geom,
sizeof(dContact))) {
dMatrix3 RI;
dRSetIdentity (RI);
const dReal ss[3] = {0.02,0.02,0.02};
for (i=0; i<numc; i++) {
dJointID c = dJointCreateContact (m_World,m_ContactGroup,contact+i);
dJointAttach (c,b1,b2);
//if (show_contacts) dsDrawBox (contact.geom.pos,RI,ss);
}
}
}
Advertisement
refresh

This topic is closed to new replies.

Advertisement