2 Bullet Continuous Collision Detection and Physics Library
3 Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
5 This software is provided 'as-is', without any express or implied warranty.
6 In no event will the authors be held liable for any damages arising from the use of this software.
7 Permission is granted to anyone to use this software for any purpose,
8 including commercial applications, and to alter it and redistribute it freely,
9 subject to the following restrictions:
11 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
12 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
13 3. This notice may not be removed or altered from any source distribution.
16 #include "BspConverter.h"
17 #include "BspLoader.h"
18 #include "LinearMath/btVector3.h"
19 #include "LinearMath/btGeometryUtil.h"
24 void BspConverter::convertBsp(BspLoader& bspLoader,float scaling)
28 float playstartf[3] = {0,0,100};
30 if (bspLoader.findVectorByName(&playstartf[0],"info_player_start"))
32 printf("found playerstart\n");
36 if (bspLoader.findVectorByName(&playstartf[0],"info_player_deathmatch"))
38 printf("found deatchmatch start\n");
42 btVector3 playerStart (playstartf[0],playstartf[1],playstartf[2]);
45 playerStart[2] += 20.f; //start a bit higher
47 playerStart *= scaling;
51 //progressBegin("Loading bsp");
53 for (int i=0;i<bspLoader.m_numleafs;i++)
55 printf("Reading bspLeaf %i from total %i (%f procent)\n",i, bspLoader.m_numleafs,(100.f*(float)i/float(bspLoader.m_numleafs)) );
57 bool isValidBrush = false;
59 BSPLeaf& leaf = bspLoader.m_dleafs[i];
61 for (int b=0;b<leaf.numLeafBrushes;b++)
63 btAlignedObjectArray<btVector3> planeEquations;
65 int brushid = bspLoader.m_dleafbrushes[leaf.firstLeafBrush+b];
67 BSPBrush& brush = bspLoader.m_dbrushes[brushid];
68 if (brush.shaderNum!=-1)
70 if (bspLoader.m_dshaders[ brush.shaderNum ].contentFlags & BSPCONTENTS_SOLID)
74 for (int p=0;p<brush.numSides;p++)
76 int sideid = brush.firstSide+p;
77 BSPBrushSide& brushside = bspLoader.m_dbrushsides[sideid];
78 int planeid = brushside.planeNum;
79 BSPPlane& plane = bspLoader.m_dplanes[planeid];
85 planeEq[3] = scaling*-plane.dist;
87 planeEquations.push_back(planeEq);
93 btAlignedObjectArray<btVector3> vertices;
94 btGeometryUtil::getVerticesFromPlaneEquations(planeEquations,vertices);
96 bool isEntity = false;
97 btVector3 entityTarget(0.f,0.f,0.f);
98 addConvexVerticesCollider(vertices,isEntity,entityTarget);
112 for (i=0;i<bspLoader.m_num_entities;i++)
114 const BSPEntity& entity = bspLoader.m_entities[i];
115 const char* cl = bspLoader.getValueForKey(&entity,"classname");
116 if ( !strcmp( cl, "trigger_push" ) ) {
117 btVector3 targetLocation(0.f,0.f,0.f);
119 cl = bspLoader.getValueForKey(&entity,"target");
120 if ( strcmp( cl, "" ) ) {
121 //its not empty so ...
124 //lookup the target position for the jumppad:
125 const BSPEntity* targetentity = bspLoader.getEntityByValue( "targetname" , cl );
128 if (bspLoader.getVectorForKey( targetentity , "origin",&targetLocation[0]))
136 cl = bspLoader.getValueForKey(&entity,"model");
137 if ( strcmp( cl, "" ) ) {
138 // add the model as a brush
141 int modelnr = atoi(&cl[1]);
142 if ((modelnr >=0) && (modelnr < bspLoader.m_nummodels))
144 const BSPModel& model = bspLoader.m_dmodels[modelnr];
145 for (int n=0;n<model.numBrushes;n++)
147 btAlignedObjectArray<btVector3> planeEquations;
148 bool isValidBrush = false;
151 const BSPBrush& brush = bspLoader.m_dbrushes[model.firstBrush+n];
153 for (int p=0;p<brush.numSides;p++)
155 int sideid = brush.firstSide+p;
156 BSPBrushSide& brushside = bspLoader.m_dbrushsides[sideid];
157 int planeid = brushside.planeNum;
158 BSPPlane& plane = bspLoader.m_dplanes[planeid];
164 planeEq[3] = scaling*-plane.dist;
165 planeEquations.push_back(planeEq);
171 btAlignedObjectArray<btVector3> vertices;
172 btGeometryUtil::getVerticesFromPlaneEquations(planeEquations,vertices);
175 addConvexVerticesCollider(vertices,isEntity,targetLocation);
185 printf("unsupported trigger_push model, md3 ?\n");
194 #endif //USE_ENTITIES