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 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
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); }
Merci beaucoup pour votre aide, je suis sûr d'avoir manqué un truc important.
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); }
Partager