Exemple #1
0
void Slice::SliceShapePostStep(cpSpace *space, cpShape *shape, struct SliceContext *context)
{
	cpVect a = context->a;
	cpVect b = context->b;
	
	// Clipping plane normal and distance.
	cpVect n = cpvnormalize(cpvperp(cpvsub(b, a)));
	cpFloat dist = cpvdot(a, n);
	
	ClipPoly(space, shape, n, dist);
	ClipPoly(space, shape, cpvneg(n), -dist);
	
	cpBody *body = cpShapeGetBody(shape);
	cpSpaceRemoveShape(space, shape);
	cpSpaceRemoveBody(space, body);
	cpShapeFree(shape);
	cpBodyFree(body);
}
//=====================================================================================
//	CreateAllOutsidePortals
//=====================================================================================
geBoolean CreateAllOutsidePortals(GBSP_Node *Node)
{
	int32		k, i, Index;
	GBSP_Plane	PPlanes[6];
	GBSP_Portal	*Portals[6];

	memset(OutsideNode, 0, sizeof(GBSP_Node));

	memset(PPlanes, 0, 6*sizeof(GBSP_Plane));

	OutsideNode->PlaneNum = PLANENUM_LEAF;
	OutsideNode->Contents = BSP_CONTENTS_SOLID2;
	OutsideNode->Portals = NULL;
	OutsideNode->BrushList = NULL;

	// So there won't be NULL volume leafs when we create the outside portals
	for (k=0; k< 3; k++)
	{
		if (VectorToSUB(NodeMins, k)-128 <= -MIN_MAX_BOUNDS || VectorToSUB(NodeMaxs, k)+128 >= MIN_MAX_BOUNDS)
		{
			GHook.Error("CreateAllOutsidePortals:  World BOX out of range...\n");
			return GE_FALSE;
		}

		VectorToSUB(NodeMins, k) -= (geFloat)128;
		VectorToSUB(NodeMaxs, k) += (geFloat)128;
	}

	// Create 6 portals, and point to the outside and the RootNode
	for (i=0; i<3; i++)
	{
		for (k=0; k<2; k++)
		{
			Index = k*3 + i;
			geVec3d_Clear(&PPlanes[Index].Normal);

			if (k == 0)
			{
				VectorToSUB(PPlanes[Index].Normal, i) = (geFloat)1;
				PPlanes[Index].Dist = VectorToSUB(NodeMins, i);
			}
			else
			{
				VectorToSUB(PPlanes[Index].Normal, i) = (geFloat)-1;
				PPlanes[Index].Dist = -VectorToSUB(NodeMaxs, i);
			}
			
			Portals[Index] = CreateOutsidePortal(&PPlanes[Index], Node);
			if (!Portals[Index])
				return GE_FALSE;
		}
	}
							  
	for (i=0; i< 6; i++)
	{
		for (k=0; k< 6; k++)
		{
			if (k == i)
				continue;

			if (!ClipPoly(Portals[i]->Poly, &PPlanes[k], GE_FALSE, &Portals[i]->Poly))
			{
				GHook.Error("CreateAllOutsidePortals:  There was an error clipping the portal.\n");
				return GE_FALSE;
			}

			if (!Portals[i]->Poly)
			{
				GHook.Error("CreateAllOutsidePortals:  Portal was clipped away.\n");
				return GE_FALSE;
			}
		}
	}

	return GE_TRUE;
}