Historique des modifications - Message

Message #7169

Sujet: 6 Questions.


Type Date Auteur Contenu
Création du message 13-10-2009 20:00:00 Ilovechocolat
Ben en fait, je fais comme ça (je vous mets mes portions de code) :
(le second est sans doute le plus important, c'est surement la qu'il y a l'erreur)

Bon, ça c'est comment j'initialise Newton
    
void ApplyForce(const NewtonBody *nbody)
{
    float mass, ixx, iyy, izz;
    NewtonBodyGetMassMatrix(nbody, &mass, &ixx, &iyy, &izz);
    float force[3] = {0, mass * -90.82, 0};
    NewtonBodyAddForce(nbody, force);
}
NewtonCollision* CreateCollisionFromTreeMesh(NewtonWorld *nWorld, irr::scene::IMesh *m_mesh)
{
    using namespace irr;
    using namespace core;
    using namespace gui;
    using namespace io;
    using namespace scene;
    using namespace video;

    NewtonCollision * collision = NULL;

    collision = NewtonCreateTreeCollision (nWorld, NULL);

    NewtonTreeCollisionBeginBuild (collision);
    int nMeshBuffer = 0; //Mesh Buffer count
    int v_index[3] = {0,0,0}; //vertex indices
    IMeshBuffer *mesh_buffer = NULL;
    float array[9]; //Array to store 3 vertices

     //Get m_mesh buffers and copy face by face to collision mesh
     for( nMeshBuffer=0 ; nMeshBuffer < (int)m_mesh->getMeshBufferCount() ; nMeshBuffer++ )
     {

         mesh_buffer = m_mesh->getMeshBuffer(nMeshBuffer);

         //Get pointer to vertices and indices
         S3DVertex *vertices = (S3DVertex*)mesh_buffer->getVertices();
         u16 *indices = mesh_buffer->getIndices();

         //Fill collision mesh
         for(int i=0; i<(int)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;
             array[1] = vertices[ v_index[0] ].Pos.Y;
             array[2] = vertices[ v_index[0] ].Pos.Z;

             // 2nd position vertex
             array[3] = vertices[ v_index[1] ].Pos.X;
             array[4] = vertices[ v_index[1] ].Pos.Y;
             array[5] = vertices[ v_index[1] ].Pos.Z;

             // 3rd position vertex
             array[6] = vertices[ v_index[2] ].Pos.X;
             array[7] = vertices[ v_index[2] ].Pos.Y;
             array[8] = vertices[ v_index[2] ].Pos.Z;

             //Add new face to collision mesh
             NewtonTreeCollisionAddFace(collision, //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

         }
    }
    NewtonTreeCollisionEndBuild(collision, 0);

    return collision;
}

    [...]

    //moteur physique de la map
    bodyMap = NewtonCreateBody(world,CreateCollisionFromTreeMesh(world, room));
    matMap.setTranslation(irr::core::vector3df(0,0,0));
    NewtonBodySetMatrix(bodyMap,&matMap.M[0]);
    NewtonBodySetMassMatrix(bodyMap,0,2,2,2);
    NewtonBodySetForceAndTorqueCallback(bodyMap, ApplyForce);
    //moteur physique du perso
    bodyPerso = NewtonCreateBody(world,NewtonCreateBox(world,1,1,1,0));
    matPerso.setTranslation(positionPerso);
    NewtonBodySetMatrix(bodyPerso,&matPerso.M[0]);
    NewtonBodySetMassMatrix(bodyPerso,70,2,2,2);
    NewtonBodySetForceAndTorqueCallback(bodyPerso, ApplyForce);

ça c'est comment je fait la translation :

        m_Nperso->setTranslation(v);
        NewtonBodySetMatrix(m_bodyPerso, m_Nperso->pointer());
        NewtonBodySetMassMatrix(m_bodyPerso,70,2,2,2);
        NewtonBodySetForceAndTorqueCallback(m_bodyPerso, ApplyForce);

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
171 invités en ligne
membre en ligne: -
RSS Feed