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

Bullet Discussion :

[BulletPhysics] Essai avec BSP


Sujet :

Bullet

  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 [BulletPhysics] Essai avec BSP
    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 :

    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
    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);
     
    							}
    						}
     
    					}
    				}
    			}
    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 : 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
    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 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 : 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
    		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;
    		}
    Et le résultat... Baaaa le cube tombe mais il ne collisionne pas. Voilà les messages recus :

    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)
    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 :

    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
    		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);
    Merci beaucoup pour votre aide, j'en aurai sérieusement besoin.

  2. #2
    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
    Up, après quelques manipulations, j'ai trouvé comment faire collisionner l'objet, et j'ai trouvé le moyen d'y mettre ses extremités :

    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
    		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]);
    			}
    			btCollisionShape *colShape = new btConvexHullShape(NULL,0,0); 
    			btConvexHullShape* hullshape = dynamic_cast<btConvexHullShape*>(colShape);
    			hullshape->addPoint( btPoint3( 2.5, 0.0, 0.0) );
    			hullshape->addPoint( btPoint3( 2.0,-1.0, 0.0) );
    			hullshape->addPoint( btPoint3( 2.0, 1.0, 0.0) );
    			hullshape->addPoint( btPoint3(-1.0,-1.0, 0.0) );
    			hullshape->addPoint( btPoint3(-1.0, 1.0, 0.0) );
    			hullshape->addPoint( btPoint3( 1.0, 0.0,-1.0) );
    			hullshape->addPoint( btPoint3(-1.0, 0.0,-1.0) );
    			m_collisionShapes.push_back(colShape);
     
    			body = localCreateRigidBody(ent, btScalar(ent->mass), startTransform, colShape);
    			PrintIt("Model found! %s %s %s\n",ent->model, vtos(ent->r.mins), vtos(ent->r.maxs));
     
    			//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] ) );
    			//}
    			return;
    		}
    Voilà toutes les coordonnées que j'ai récupéré du cube :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    Point 0 : X = -96.000000 Y = 1024.000000 Z = 64.000000
    Point 1 : X = -96.000000 Y = 1024.000000 Z = 256.000000
    Point 2 : X = -96.000000 Y = 1216.000000 Z = 64.000000
    Point 3 : X = -96.000000 Y = 1216.000000 Z = 256.000000
    Point 4 : X = 96.000000 Y = 1024.000000 Z = 64.000000
    Point 5 : X = 96.000000 Y = 1024.000000 Z = 256.000000
    Point 6 : X = 96.000000 Y = 1216.000000 Z = 64.000000
    Point 7 : X = 96.000000 Y = 1216.000000 Z = 256.000000
    Récupération des vertex du model :

    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
    				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;
    				}
    Voilà, si quelqu'un pourrait m'expliquer comment on paramètre les points à partir des vertex avec ces lignes, ce serait vraiment sympa de sa part, je n'ai besoin que de ça en plus pour progresser. C'est la seule impasse. =/

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    			hullshape->addPoint( btPoint3( 2.5, 0.0, 0.0) );
    			hullshape->addPoint( btPoint3( 2.0,-1.0, 0.0) );
    			hullshape->addPoint( btPoint3( 2.0, 1.0, 0.0) );
    			hullshape->addPoint( btPoint3(-1.0,-1.0, 0.0) );
    			hullshape->addPoint( btPoint3(-1.0, 1.0, 0.0) );
    			hullshape->addPoint( btPoint3( 1.0, 0.0,-1.0) );
    			hullshape->addPoint( btPoint3(-1.0, 0.0,-1.0) );
    Merci,
    Eltran.

Discussions similaires

  1. Essais avec fail2ban
    Par troumad dans le forum Sécurité
    Réponses: 5
    Dernier message: 21/11/2020, 23h17
  2. [Framework] Premier essaie avec Spring: echec :( !
    Par jlassiramzy dans le forum Spring
    Réponses: 2
    Dernier message: 01/07/2010, 22h08
  3. essai avec TreeView
    Par aurel_D dans le forum Macros et VBA Excel
    Réponses: 2
    Dernier message: 17/03/2008, 15h45
  4. Réponses: 3
    Dernier message: 08/01/2008, 10h04
  5. Mon 1er essai avec WAMP
    Par kagura dans le forum Langage
    Réponses: 21
    Dernier message: 30/06/2006, 19h16

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