Bonjour,
J'essaye durement d'intégrer BulletPhysics sous Quake3, je commence d'abord par charger le fichier BSP à l'aide du AppBspDemo fourni dans Bullet. Je fais une entité func_box qui fait un cube simple afin de tester les collisions : elles fonctionnent parfaitement.
Le func_box est une brush que l'utilisateur peut dessiner comme il le veut dans l'éditeur de map. J'essaye donc de le charger avec le BSPDemo comme ceci :
Les vertex du model func_box trouvé sont directement enregistrés dans une struct, le model sera reconnu par son code généré par l'éditeur.Code:
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 if ( !strcmp( cl, "func_box" ) ) { btVector3 targetLocation(0.f,0.f,0.f); cl = bspLoader.getValueForKey(&entity,"model"); if ( strcmp( cl, "" ) ) { // add the model as a brush if (cl[0] == '*') { int modelnr = atoi(&cl[1]); if ((modelnr >=0) && (modelnr < bspLoader.m_nummodels)) { const BSPModel& model = bspLoader.m_dmodels[modelnr]; for (int n=0;n<model.numBrushes;n++) { btAlignedObjectArray<btVector3> planeEquations; bool isValidBrush = false; //convert brush const BSPBrush& brush = bspLoader.m_dbrushes[model.firstBrush+n]; { for (int p=0;p<brush.numSides;p++) { int sideid = brush.firstSide+p; BSPBrushSide& brushside = bspLoader.m_dbrushsides[sideid]; int planeid = brushside.planeNum; BSPPlane& plane = bspLoader.m_dplanes[planeid]; btVector3 planeEq; planeEq.setValue( plane.normal[0], plane.normal[1], plane.normal[2], scaling*-plane.dist); planeEquations.push_back(planeEq); isValidBrush=true; PrintIt("P = %i : %f | %f | %f\n",p,plane.normal[0],plane.normal[1],plane.normal[2]); } if (isValidBrush) { btAlignedObjectArray<btVector3> vertices; btGeometryUtil::getVerticesFromPlaneEquations(planeEquations,vertices); int x; for (x = 0;x < vertices.size(); x++) { PrintIt("Point %i = %f -!- %f -!- %f\n",x,vertices[x].getX(),vertices[x].getY(),vertices[x].getZ()); } bool isEntity=true; addConvexVerticesCollider(vertices,isEntity,targetLocation, cl); } } } } }
Et voilà ce qui se passe quand on spawn le func_box, je prend le model, je fais un btConvexHullShape (si il y a une autre solution, montrez moi svp si vous le pouvez) :Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 for (i = mdindex; i < 128; i++) { if (bspmodels[i].used == 0) { bspmodels[i].used = 1; strncpy(bspmodels[i].model,model,sizeof(bspmodels[i].model)); PrintIt("Model %s added to the database.\n",bspmodels[i].model); bspmodels[i].vertices = vertices; for (x = 0;x < vertices.size(); x++) { bspmodels[i].point[x][0] = vertices[x].getX(); bspmodels[i].point[x][1] = vertices[x].getY(); bspmodels[i].point[x][2] = vertices[x].getZ(); PrintIt("Point %i = %f -!- %f -!- %f\n",x,vertices[x].getX(),vertices[x].getY(),vertices[x].getZ()); // PrintIt("Registered %i = %f -!- %f -!- %f\n",x,bspmodels[i].point[x][0],bspmodels[i].point[x][1],bspmodels[i].point[x][2]); } mdindex++; break; } }
Et le résultat... Baaaa le cube tombe mais il ne collisionne pas. Voilà les messages recus :Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 if (!Q_stricmp(bspmodels[i].model,ent->model)) { for (x = 0;x < bspmodels[i].vertices.size(); x++) { PrintIt("Model Point %i = %f -!- %f -!- %f\n",x,bspmodels[i].point[x][0],bspmodels[i].point[x][1],bspmodels[i].point[x][0]); } btConvexHullShape* hullshape = new btConvexHullShape; for (x = 0;x < bspmodels[i].vertices.size(); x++) { hullshape->addPoint( btVector3( bspmodels[i].point[x][0], bspmodels[i].point[x][1], bspmodels[i].point[x][2] ) ); } btCollisionShape* colShape = hullshape; m_collisionShapes.push_back(colShape); body = localCreateRigidBody(ent, btScalar(ent->mass), startTransform, colShape); PrintIt("Model found! %s (%i)\n",ent->model, i); return; }
Donc voilà, je cherche péniblement comment définir la forme physique du func_box afin qu'elle rebondisse sur le sol. Il y a d'autres solutions pour définir une forme physique sur Bullet, notamment btTriangleMesh, mais je ne vois pas du tout comment faire un triangle mesh avec les vertex que j'ai récupéré, est-ce-possible ? J'ai trouvé ceci :Citation:
P = 0 : -1.000000 | 0.000000 | 0.000000
P = 1 : 1.000000 | 0.000000 | 0.000000
P = 2 : 0.000000 | -1.000000 | 0.000000
P = 3 : 0.000000 | 1.000000 | 0.000000
P = 4 : 0.000000 | 0.000000 | -1.000000
P = 5 : 0.000000 | 0.000000 | 1.000000
Point 0 = -96.000000 -!- 1024.000000 -!- 64.000000
Point 1 = -96.000000 -!- 1024.000000 -!- 256.000000
Point 2 = -96.000000 -!- 1216.000000 -!- 64.000000
Point 3 = -96.000000 -!- 1216.000000 -!- 256.000000
Point 4 = 96.000000 -!- 1024.000000 -!- 64.000000
Point 5 = 96.000000 -!- 1024.000000 -!- 256.000000
Point 6 = 96.000000 -!- 1216.000000 -!- 64.000000
Point 7 = 96.000000 -!- 1216.000000 -!- 256.000000
SPAWNING FUNC_BOX (-1312 1312 160) WITH MODEL *1
Model Point 0 = -96.000000 -!- 1024.000000 -!- -96.000000
Model Point 1 = -96.000000 -!- 1024.000000 -!- -96.000000
Model Point 2 = -96.000000 -!- 1216.000000 -!- -96.000000
Model Point 3 = -96.000000 -!- 1216.000000 -!- -96.000000
Model Point 4 = 96.000000 -!- 1024.000000 -!- 96.000000
Model Point 5 = 96.000000 -!- 1024.000000 -!- 96.000000
Model Point 6 = 96.000000 -!- 1216.000000 -!- 96.000000
Model Point 7 = 96.000000 -!- 1216.000000 -!- 96.000000
Model Found! *1 (0)
Merci beaucoup pour votre aide, j'en aurai sérieusement besoin.Code:
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 btTriangleMesh* trimesh = new btTriangleMesh(); m_trimeshes.push_back(trimesh); btVector3 localScaling(6.f,6.f,6.f); int i; for ( i=0;i<wo.mTriCount;i++) { int index0 = wo.mIndices[i*3]; int index1 = wo.mIndices[i*3+1]; int index2 = wo.mIndices[i*3+2]; btVector3 vertex0(wo.mVertices[index0*3], wo.mVertices[index0*3+1],wo.mVertices[index0*3+2]); btVector3 vertex1(wo.mVertices[index1*3], wo.mVertices[index1*3+1],wo.mVertices[index1*3+2]); btVector3 vertex2(wo.mVertices[index2*3], wo.mVertices[index2*3+1],wo.mVertices[index2*3+2]); vertex0 *= localScaling; vertex1 *= localScaling; vertex2 *= localScaling; trimesh->addTriangle(vertex0,vertex1,vertex2); } btConvexShape* tmpConvexShape = new btConvexTriangleMeshShape(trimesh); printf("old numTriangles= %d\n",wo.mTriCount); printf("old numIndices = %d\n",wo.mTriCount*3); printf("old numVertices = %d\n",wo.mVertexCount);