Par exemple, pour avoir une collision correcte avec un cube:
// rapport d'échelle
#define NEWTON_TO_IRR 32.0f
#define IRR_TO_NEWTON (1.0f/NEWTON_TO_IRR)
/// cube irrlicht
ISceneNode *Node001 = smgr->addCubeSceneNode(200);
/// récupère la taille de la boundingbox du node pour la creation d'une collision de type "BOX"
vector3df size = Node001->getBoundingBox().getExtent() * IRR_TO_NEWTON; // ADAPTATION DE L'ECHELLE AVEC UN COEF
/// créé le cube qui servira pour le calcul de collision
NewtonCollision* NC_Node001 = NewtonCreateBox(World, size.X, size.Y, size.Z, -1, NULL);
En appliquant le coef les collisions sont bonnes. J'utilise ce coef aussi pour les mesh importés.
NewtonCollision* createTreeCollisionFromMesh(NewtonWorld* nWorld, IMesh* irr_mesh)
{
//Create new (tree optimized) collision mesh
NewtonCollision* collision_obj = NewtonCreateTreeCollision(nWorld,0);
//Begin collision mesh construction
NewtonTreeCollisionBeginBuild(collision_obj);
u32 nMeshBuffer = 0; //Mesh Buffer count
u16 v_index[3] = {0,0,0}; //vertex indices
IMeshBuffer *mesh_buffer = 0;
float array[9]; //Array to store 3 vertices
//Get (irr_)mesh buffers and copy face by face to collision mesh
for( nMeshBuffer=0 ; nMeshBuffer < irr_mesh->getMeshBufferCount() ; nMeshBuffer++ )
{
mesh_buffer = irr_mesh->getMeshBuffer(nMeshBuffer);
//Get pointer to vertices and indices
S3DVertex *vertices = (S3DVertex*)mesh_buffer->getVertices();
u16 *indices = mesh_buffer->getIndices();
//Fill collision mesh
for(u32 i=0; i<mesh_buffer->getIndexCount(); i+=3)
{
v_index[0] = indices[ i ];
v_index[1] = indices[i+1];
v_index[2] = indices[i+2];
// 1st position vertex
array[0] = vertices[ v_index[0] ].Pos.X * IRR_TO_NEWTON;
array[1] = vertices[ v_index[0] ].Pos.Y * IRR_TO_NEWTON;
array[2] = vertices[ v_index[0] ].Pos.Z * IRR_TO_NEWTON;
// 2nd position vertex
array[3] = vertices[ v_index[1] ].Pos.X * IRR_TO_NEWTON;
array[4] = vertices[ v_index[1] ].Pos.Y * IRR_TO_NEWTON;
array[5] = vertices[ v_index[1] ].Pos.Z * IRR_TO_NEWTON;
// 3rd position vertex
array[6] = vertices[ v_index[2] ].Pos.X * IRR_TO_NEWTON;
array[7] = vertices[ v_index[2] ].Pos.Y * IRR_TO_NEWTON;
array[8] = vertices[ v_index[2] ].Pos.Z * IRR_TO_NEWTON;
//Add new face to collision mesh
NewtonTreeCollisionAddFace( collision_obj, //collision mesh to add face to
3, //number of vertices in array
(float*)array, //pointer to vertex array
3*sizeof(float),//size of each vertex
1); //ID of the face
}
}
//End collision contruction , set 1 as 2dn param for optimization
NewtonTreeCollisionEndBuild(collision_obj,0);
return collision_obj;
}
J'ai testé newton 2.35 avec irrlicht 1.8 et ça marche nickel avec ces coefs. Si je ne les appliquent pas les meshs se traversent. Et puisque les coefs résolvent le problème pour les meshs régénérés directement avec Irrlicht (addCubeSceneNode, addSphereSceneNode...), j'en ai déduit que c'est un problème d'échelle entre irrlicht et newton.