Historique des modifications - Message

Message #10528

Sujet: Objets destructibles avec Newton


Type Date Auteur Contenu
Dernière modification 14-06-2012 14:09:39 johnplayer
J'ai essayé ta fonction "NewtonCollision* GrNewton::createTreeCollisionFromMesh(...)" mais ça n'a strictement aucun effet chez moi. Il renvoie une NewtonCollision valide mais le mesh reste à la position où je le place avec Irrlicht. Je juste remanié le code pour qu'il coïncide avec mes variables.

Voilà le code remanié
#define GRAVITY -9.8f
#define NEWTON_TO_IRR 32.0f
#define IRR_TO_NEWTON (1.0f/NEWTON_TO_IRR)


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;
}

Dans mon main, j'ai :
        //NC_NodeCaisse001 = NewtonCreateBox(World, size.X, size.Y, size.Z, -1, NULL);
        //NC_NodeCaisse001 = CreateNewtonConvexHull(World, Caisse001);
        NC_NodeCaisse001 = createTreeCollisionFromMesh(World, Caisse001);
        if(NC_NodeCaisse001){ ...

Si j'utilise une des 2 premières fonctions en commentaire je n'ai pas de problème. Bref, je ne comprends pas ce qu'il se passe.

Edit : La fonction "createTreeCollisionFromMesh" marche avec un plan mais pas avec un cube chanfreiné.
Edit 2 : Enfait, il y a les collisions mais pas de physique. Il n'est pas soumis à la gravité, pourtant j'ai un body valide.
Création du message 14-06-2012 13:16:40 johnplayer
J'ai essayé ta fonction "NewtonCollision* GrNewton::createTreeCollisionFromMesh(...)" mais ça n'a strictement aucun effet chez moi. Il renvoie une NewtonCollision valide mais le mesh reste à la position où je le place avec Irrlicht. Je juste remanié le code pour qu'il coïncide avec mes variables.

Voilà le code remanié
#define GRAVITY -9.8f
#define NEWTON_TO_IRR 32.0f
#define IRR_TO_NEWTON (1.0f/NEWTON_TO_IRR)


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;
}

Dans mon main, j'ai :
        //NC_NodeCaisse001 = NewtonCreateBox(World, size.X, size.Y, size.Z, -1, NULL);
        //NC_NodeCaisse001 = CreateNewtonConvexHull(World, Caisse001);
        NC_NodeCaisse001 = createTreeCollisionFromMesh(World, Caisse001);
        if(NC_NodeCaisse001){ ...

Si j'utilise une des 2 premières fonctions en commentaire je n'ai pas de problème. Bref, je ne comprends pas ce qu'il se passe.

Edit : La fonction "createTreeCollisionFromMesh" marche avec un plan mais pas avec un cube chanfreiné.
Edit 2 : Enfait, il y a les collisions mais pas de physique. Il n'est pas soumis à la gravité, pourtant j'ai un body valide.

Retour

Options Liens officiels Caractéristiques Statistiques Communauté
Préférences cookies
Corrections
irrlicht
irrklang
irredit
irrxml
Propulsé par Django
xhtml 1.0
css 2.1
884 membres
1440 sujets
11337 messages
Dernier membre inscrit: Saidov17
111 invités en ligne
membre en ligne: -
RSS Feed