IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Newton Discussion :

[Newton] Petit problème.


Sujet :

Newton

  1. #1
    Futur Membre du Club
    Profil pro
    Inscrit en
    Mai 2006
    Messages
    13
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2006
    Messages : 13
    Points : 9
    Points
    9
    Par défaut [Newton] Petit problème.
    Bonjour,
    J'essaye d'intégrer Newton dans mon projet utilisant une map BSP, j'ai créé un cube, il tombe mais ne touche strictement à aucune collision, je voudrais savoir comment on calcule la taille d'un cube à partir de ses coordonées AABB, (min et max).

    Code de chargement du cube :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    extern "C" void G_NewtonAddEntity(gentity_t *ent) {
    	dFloat Ixx;
    	dFloat Iyy;
    	dFloat Izz;
    	NewtonBody* rigidBody;
    	NewtonCollision* collision;
    	dVector origin;
    	dVector inertia;
    	dFloat mass, volume;
    	dMatrix matrix;
    	float objSizeX, objSizeY, objSizeZ;
     
    	matrix.m_posit.m_x = ent->s.origin[0];
    	matrix.m_posit.m_y = ent->s.origin[1];
    	matrix.m_posit.m_z = ent->s.origin[2];
     
    	objSizeX = 64.0f;//(ent->r.mins[0] + ent->r.maxs[0])/2;
    	objSizeY = 64.0f;//(ent->r.mins[1] + ent->r.maxs[1])/2;
    	objSizeZ = 64.0f;//(ent->r.mins[2] + ent->r.maxs[2])/2;
     
    	collision = NewtonCreateBox (g_NewtonWorld, objSizeX, objSizeY, objSizeZ, NULL); 
    	volume = 0.5f * NewtonConvexCollisionCalculateVolume (collision);
     
    	// calculate the moment of inertia and the relative center of mass of the solid
    	NewtonConvexCollisionCalculateInertialMatrix (collision, &inertia[0], &origin[0]);
    	mass = 100;
    	Ixx = mass * inertia[0];
    	Iyy = mass * inertia[1];
    	Izz = mass * inertia[2];
     
    	//create the rigid body
    	rigidBody = NewtonCreateBody (g_NewtonWorld, collision);
     
    	// release the collision geometry when not need it
    	NewtonReleaseCollision (g_NewtonWorld, collision);
     
    	// set the correct center of gravity for this body
    	NewtonBodySetCentreOfMass (rigidBody, &origin[0]);
     
    	// set the mass matrix
    	NewtonBodySetMassMatrix (rigidBody, mass, Ixx, Iyy, Izz);
     
    	// activate 
    	//	NewtonBodyCoriolisForcesMode (blockBoxBody, 1);
     
    	// save the pointer to the graphic object with the body.
    	NewtonBodySetUserData (rigidBody, ent);
     
    	// assign the wood id
    	NewtonBodySetMaterialGroupID (rigidBody, NewtonMaterialGetDefaultGroupID (g_NewtonWorld));
     
    //  set continue collision mode
    	NewtonBodySetContinuousCollisionMode (rigidBody, 1);
     
    	// set a destructor for this rigid body
    	NewtonBodySetDestructorCallback (rigidBody, PhysicsBodyDestructor);
     
    	// set the transform call back function
    	NewtonBodySetTransformCallback (rigidBody, PhysicsSetTransform);
     
    	// set the force and torque call back function
    	NewtonBodySetForceAndTorqueCallback (rigidBody, PhysicsApplyGravityForce);
     
    	// set the matrix for both the rigid body and the graphic body
    	NewtonBodySetMatrix (rigidBody, &matrix[0][0]);
    	PhysicsSetTransform (rigidBody, &matrix[0][0], 0);
    }
    Code de chargement du BSP :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    void G_NewtonCreateLevelBody (const CQuake3BSP& level)
    {
       int i;
       float* ptr;
       int j;
       int v1i, v2i, v3i;
       float vArray[9]; // vertex array (3*3 floats)
     
       // create a collision object
       g_NewtonCollision = NewtonCreateTreeCollision (g_NewtonWorld);
       NewtonTreeCollisionBeginBuild (g_NewtonCollision);
     
       // interate over the faces of the BSP level
       for (i = 0; i < level.m_numOfFaces; i ++)
       {
          tBSPFace& face = level.m_pFaces[i];
          // if a face is a polygon
          if (face.type == FACE_POLYGON)
          {
             // add this face to the collision tree;
    		 for (j=0; j<face.numOfIndices; j++) {
    		    v1i = level.m_pIndices[j];
    			v2i = level.m_pIndices[j+1];
    			v3i = level.m_pIndices[j+2];
     
    			vArray[0] = level.m_pVerts[v1i].vPosition.x;
    			vArray[1] = level.m_pVerts[v1i].vPosition.y;
    			vArray[2] = level.m_pVerts[v1i].vPosition.z;
    			vArray[3] = level.m_pVerts[v2i].vPosition.x;
    			vArray[4] = level.m_pVerts[v2i].vPosition.y;
    			vArray[5] = level.m_pVerts[v2i].vPosition.z;
    			vArray[6] = level.m_pVerts[v3i].vPosition.x;
    			vArray[7] = level.m_pVerts[v3i].vPosition.y;
    			vArray[8] = level.m_pVerts[v3i].vPosition.z;
     
    			G_Printf("---\n");
    			G_Printf("vArray 0 = %f ||| vArray 1 = %f ||| vArray 2 = %f\n", vArray[0], vArray[1], vArray[2]);
    			G_Printf("vArray 3 = %f ||| vArray 4 = %f ||| vArray 5 = %f\n", vArray[3], vArray[4], vArray[5]);
    			G_Printf("vArray 6 = %f ||| vArray 7 = %f ||| vArray 8 = %f\n", vArray[6], vArray[7], vArray[8]);
    			G_Printf("---\n");
     
                NewtonTreeCollisionAddFace (g_NewtonCollision, 3, (float*)vArray, 12, 1);
    		 }
          }
       }
     
       //close the collision mesh
       // optionally the collision mesh can be optimized, 
       NewtonTreeCollisionEndBuild (g_NewtonCollision, 0);
     
       g_NewtonRigidBody = NewtonCreateBody (g_NewtonWorld, g_NewtonCollision);   
       NewtonReleaseCollision (g_NewtonWorld, g_NewtonCollision);
    }
    Merci beaucoup pour votre aide, je suis sûr d'avoir manqué un truc important.

  2. #2
    Membre actif
    Profil pro
    Inscrit en
    Juillet 2007
    Messages
    318
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2007
    Messages : 318
    Points : 291
    Points
    291
    Par défaut
    Pour ton arbre BSP avec newton il faut que tu fasses attentions à l'orientation des faces (orientation vers l'extérieur), sinon les objet passent au travers.

    J'avais le même problème que toi quand j'ai implémenté Newton et ça venait de ça.

Discussions similaires

  1. un petit problème d'algo
    Par supertramp dans le forum Algorithmes et structures de données
    Réponses: 22
    Dernier message: 12/10/2004, 20h13
  2. Petit problème de décimales !
    Par ridan dans le forum Langage SQL
    Réponses: 5
    Dernier message: 11/09/2004, 21h24
  3. Réponses: 17
    Dernier message: 13/07/2004, 20h37
  4. petit problème premier plan, arrière plan
    Par gros bob dans le forum OpenGL
    Réponses: 4
    Dernier message: 19/04/2004, 12h00
  5. [jointure] Petit problème sur le type de jointure...
    Par SteelBox dans le forum Langage SQL
    Réponses: 13
    Dernier message: 13/02/2004, 18h55

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo