Loading a Valve BSP map and simulating physics with bullet

montoyo
Posts: 2
Joined: Wed Feb 12, 2014 8:04 pm

Loading a Valve BSP map and simulating physics with bullet

Post by montoyo »

Hello,
I'm trying to load a source engine map into my game, which uses bullet. For that I took a look on the bullet Quake BSP Demo; and wrote this: http://pastebin.com/QbXx9uNn
I did this in two parts: a converter, which extracts all brushes from the BSP map and put them in a file that my "game" can read; and the map loader which reads this file.
World is correctly rendered, but it lags a lot (because there's a lot of physics body: my converter says that there's over 3000 shapes) and the physics aren't working. I think that the problem comes from the converter... Maybe can someone help me?
Thanks, montoyo.
PS: Sorry for my bad english :S
jagh
Posts: 4
Joined: Wed Feb 12, 2014 4:39 pm

Re: Loading a Valve BSP map and simulating physics with bull

Post by jagh »

After quick look i found it strange, that you practically ignore a distance component of the plane equation. I'm not sure how one is supposed to encode it in btVector3, perhaps as a vector length, but certainly not as norm[3](fourth component is just for alignment and is unused)
montoyo
Posts: 2
Joined: Wed Feb 12, 2014 8:04 pm

Re: Loading a Valve BSP map and simulating physics with bull

Post by montoyo »

Well; I wrote this by looking at bullet's BSP demo:

Code: Select all

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]);
	planeEq[3] = scaling*-plane.dist;

	planeEquations.push_back(planeEq);
	isValidBrush=true;
}
if (isValidBrush)
{

	btAlignedObjectArray<btVector3>	vertices;
	btGeometryUtil::getVerticesFromPlaneEquations(planeEquations,vertices);

	bool isEntity = false;
	btVector3 entityTarget(0.f,0.f,0.f);
	addConvexVerticesCollider(vertices,isEntity,entityTarget);

}
I think that I'm reading the wrong data from the BSP; yes I do it like the bullet BSP loader does, but this one is for Quake maps, which differs a bit from the Source one. Maybe I shouldn't read brushes... :/ Any ideas?