void btGImpactCollisionAlgorithm::processCollision (btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut)
{
    clearCache();

    m_resultOut = resultOut;
	m_dispatchInfo = &dispatchInfo;
    btGImpactShapeInterface * gimpactshape0;
    btGImpactShapeInterface * gimpactshape1;

	if (body0->getCollisionShape()->getShapeType()==GIMPACT_SHAPE_PROXYTYPE)
	{
		gimpactshape0 = static_cast<btGImpactShapeInterface *>(body0->getCollisionShape());

		if( body1->getCollisionShape()->getShapeType()==GIMPACT_SHAPE_PROXYTYPE )
		{
			gimpactshape1 = static_cast<btGImpactShapeInterface *>(body1->getCollisionShape());

			gimpact_vs_gimpact(body0,body1,gimpactshape0,gimpactshape1);
		}
		else
		{
			gimpact_vs_shape(body0,body1,gimpactshape0,body1->getCollisionShape(),false);
		}

	}
	else if (body1->getCollisionShape()->getShapeType()==GIMPACT_SHAPE_PROXYTYPE )
	{
		gimpactshape1 = static_cast<btGImpactShapeInterface *>(body1->getCollisionShape());

		gimpact_vs_shape(body1,body0,gimpactshape1,body0->getCollisionShape(),true);
	}
}
Ejemplo n.º 2
0
void btGImpactCollisionAlgorithm::processCollision (const btCollisionProcessInfo& processInfo)
{
    clearCache(processInfo.m_dispatcher);

    m_resultOut = processInfo.m_result;
	m_dispatchInfo = &processInfo.m_dispatchInfo;
    const btGImpactShapeInterface * gimpactshape0;
    const btGImpactShapeInterface * gimpactshape1;

	if (processInfo.m_body0.getCollisionShape()->getShapeType()==GIMPACT_SHAPE_PROXYTYPE)
	{
		gimpactshape0 = static_cast<const btGImpactShapeInterface *>(processInfo.m_body0.getCollisionShape());

		if (processInfo.m_body1.getCollisionShape()->getShapeType()==GIMPACT_SHAPE_PROXYTYPE )
		{
			gimpactshape1 = static_cast<const btGImpactShapeInterface *>(processInfo.m_body1.getCollisionShape());

			gimpact_vs_gimpact(
				processInfo.m_dispatcher,
				&processInfo.m_body0,
				&processInfo.m_body1,
				gimpactshape0,
				gimpactshape1
			);
		}
		else
		{
			gimpact_vs_shape(
				processInfo.m_dispatcher,
				&processInfo.m_body0,
				&processInfo.m_body1,
				gimpactshape0,
				processInfo.m_body1.getCollisionShape(),
				false
			);
		}

	}
	else if (processInfo.m_body1.getCollisionShape()->getShapeType()==GIMPACT_SHAPE_PROXYTYPE )
	{
		gimpactshape1 = static_cast<const btGImpactShapeInterface *>(processInfo.m_body1.getCollisionShape());

		gimpact_vs_shape(
			processInfo.m_dispatcher,
			&processInfo.m_body1,
			&processInfo.m_body0,
			gimpactshape1,
			processInfo.m_body0.getCollisionShape(),
			true
		);
	}
}
void btGImpactCollisionAlgorithm::processCollision (btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut)
{
    clearCache();

    m_resultOut = resultOut;
	m_triface0 = m_resultOut->m_index0;
	m_part0 = m_resultOut->m_partId0;
	m_triface1 = m_resultOut->m_index1;
	m_part1 = m_resultOut->m_partId1;
	m_dispatchInfo = &dispatchInfo;
    btGImpactShapeInterface * gimpactshape0;
    btGImpactShapeInterface * gimpactshape1;

    // if the gimpact shape is nested in a compound shape, we can be given a swapped body0 and body1
    // so ensure this is not the case
    if (m_resultOut->getBody0Internal() == body1)
    {
        swap(body0, body1);
        swap(m_triface0, m_triface1);
        swap(m_part0, m_part1);
    }


	if (body0->getCollisionShape()->getShapeType()==GIMPACT_SHAPE_PROXYTYPE)
	{
		gimpactshape0 = static_cast<btGImpactShapeInterface *>(body0->getCollisionShape());

		if( body1->getCollisionShape()->getShapeType()==GIMPACT_SHAPE_PROXYTYPE )
		{
			gimpactshape1 = static_cast<btGImpactShapeInterface *>(body1->getCollisionShape());

			gimpact_vs_gimpact(body0,body1,gimpactshape0,gimpactshape1);
		}
		else
		{
			gimpact_vs_shape(body0,body1,gimpactshape0,body1->getCollisionShape(),false);
		}

	}
	else if (body1->getCollisionShape()->getShapeType()==GIMPACT_SHAPE_PROXYTYPE )
	{
		gimpactshape1 = static_cast<btGImpactShapeInterface *>(body1->getCollisionShape());

        // hack: swap the original values, they get swapped back again later
        swap(m_triface0, m_triface1);
        swap(m_part0, m_part1);

		gimpact_vs_shape(body1,body0,gimpactshape1,body0->getCollisionShape(),true);
	}
}
void btGImpactCollisionAlgorithm::gimpact_vs_compoundshape(btCollisionObject * body0,
				  btCollisionObject * body1,
				  btGImpactShapeInterface * shape0,
				  btCompoundShape * shape1,bool swapped)
{
	btTransform orgtrans1 = body1->getWorldTransform();

	int i = shape1->getNumChildShapes();
	while(i--)
	{

		btCollisionShape * colshape1 = shape1->getChildShape(i);
		btTransform childtrans1 = orgtrans1*shape1->getChildTransform(i);

		body1->setWorldTransform(childtrans1);

		//collide child shape
		gimpact_vs_shape(body0, body1,
					  shape0,colshape1,swapped);


		//restore transforms
		body1->setWorldTransform(orgtrans1);
	}
}
Ejemplo n.º 5
0
void btGImpactCollisionAlgorithm::gimpact_vs_compoundshape(
	btDispatcher* dispatcher,
	const btCollider* body0,
	const btCollider* body1,
	const btGImpactShapeInterface* shape0,
	const btCompoundShape* shape1,
	bool swapped
)
{
	btTransform orgtrans1 = body1->getWorldTransform();

	int i = shape1->getNumChildShapes();
	while(i--)
	{

		const btCollisionShape* colshape1 = shape1->getChildShape(i);
		btTransform childtrans1 = orgtrans1 * shape1->getChildTransform(i);
		btCollider new1(body1, colshape1, body1->getCollisionObject(), childtrans1);

		//collide child shape
		gimpact_vs_shape(
			dispatcher,
			body0,
			&new1,
			shape0,
			colshape1,
			swapped
		);
	}
}
void btGImpactCollisionAlgorithm::processCollision(const btCollisionObjectWrapper* body0Wrap, const btCollisionObjectWrapper* body1Wrap, const btDispatcherInfo& dispatchInfo, btManifoldResult* resultOut)
{
	clearCache();

	m_resultOut = resultOut;
	m_dispatchInfo = &dispatchInfo;
	const btGImpactShapeInterface* gimpactshape0;
	const btGImpactShapeInterface* gimpactshape1;

	if (body0Wrap->getCollisionShape()->getShapeType() == GIMPACT_SHAPE_PROXYTYPE)
	{
		gimpactshape0 = static_cast<const btGImpactShapeInterface*>(body0Wrap->getCollisionShape());

		if (body1Wrap->getCollisionShape()->getShapeType() == GIMPACT_SHAPE_PROXYTYPE)
		{
			gimpactshape1 = static_cast<const btGImpactShapeInterface*>(body1Wrap->getCollisionShape());

			gimpact_vs_gimpact(body0Wrap, body1Wrap, gimpactshape0, gimpactshape1);
		}
		else
		{
			gimpact_vs_shape(body0Wrap, body1Wrap, gimpactshape0, body1Wrap->getCollisionShape(), false);
		}
	}
	else if (body1Wrap->getCollisionShape()->getShapeType() == GIMPACT_SHAPE_PROXYTYPE)
	{
		gimpactshape1 = static_cast<const btGImpactShapeInterface*>(body1Wrap->getCollisionShape());

		gimpact_vs_shape(body1Wrap, body0Wrap, gimpactshape1, body0Wrap->getCollisionShape(), true);
	}

	// Ensure that gContactProcessedCallback is called for concave shapes.
	if (getLastManifold())
	{
		m_resultOut->refreshContactPoints();
	}
}
void btGImpactCollisionAlgorithm::gimpact_vs_compoundshape(const btCollisionObjectWrapper* body0Wrap,
														   const btCollisionObjectWrapper* body1Wrap,
														   const btGImpactShapeInterface* shape0,
														   const btCompoundShape* shape1, bool swapped)
{
	btTransform orgtrans1 = body1Wrap->getWorldTransform();

	int i = shape1->getNumChildShapes();
	while (i--)
	{
		const btCollisionShape* colshape1 = shape1->getChildShape(i);
		btTransform childtrans1 = orgtrans1 * shape1->getChildTransform(i);

		btCollisionObjectWrapper ob1(body1Wrap, colshape1, body1Wrap->getCollisionObject(), childtrans1, -1, i);

		const btCollisionObjectWrapper* tmp = 0;
		if (m_resultOut->getBody0Wrap()->getCollisionObject() == ob1.getCollisionObject())
		{
			tmp = m_resultOut->getBody0Wrap();
			m_resultOut->setBody0Wrap(&ob1);
		}
		else
		{
			tmp = m_resultOut->getBody1Wrap();
			m_resultOut->setBody1Wrap(&ob1);
		}
		//collide child shape
		gimpact_vs_shape(body0Wrap, &ob1,
						 shape0, colshape1, swapped);

		if (m_resultOut->getBody0Wrap()->getCollisionObject() == ob1.getCollisionObject())
		{
			m_resultOut->setBody0Wrap(tmp);
		}
		else
		{
			m_resultOut->setBody1Wrap(tmp);
		}
	}
}
void btGImpactCollisionAlgorithm::gimpact_vs_shape(btCollisionObject * body0,
				  btCollisionObject * body1,
				  btGImpactShapeInterface * shape0,
				  btCollisionShape * shape1,bool swapped)
{
	if(shape0->getGImpactShapeType()==CONST_GIMPACT_TRIMESH_SHAPE)
	{
		btGImpactMeshShape * meshshape0 = static_cast<btGImpactMeshShape *>(shape0);
		int& part = swapped ? m_part1 : m_part0;
		part = meshshape0->getMeshPartCount();

		while(part--)
		{

			gimpact_vs_shape(body0,
				  body1,
				  meshshape0->getMeshPart(part),
				  shape1,swapped);

		}

		return;
	}

	#ifdef GIMPACT_VS_PLANE_COLLISION
	if(shape0->getGImpactShapeType() == CONST_GIMPACT_TRIMESH_SHAPE_PART &&
		shape1->getShapeType() == STATIC_PLANE_PROXYTYPE)
	{
		btGImpactMeshShapePart * shapepart = static_cast<btGImpactMeshShapePart *>(shape0);
		btStaticPlaneShape * planeshape = static_cast<btStaticPlaneShape * >(shape1);
		gimpacttrimeshpart_vs_plane_collision(body0,body1,shapepart,planeshape,swapped);
		return;
	}

	#endif



	if(shape1->isCompound())
	{
		btCompoundShape * compoundshape = static_cast<btCompoundShape *>(shape1);
		gimpact_vs_compoundshape(body0,body1,shape0,compoundshape,swapped);
		return;
	}
	else if(shape1->isConcave())
	{
		btConcaveShape * concaveshape = static_cast<btConcaveShape *>(shape1);
		gimpact_vs_concave(body0,body1,shape0,concaveshape,swapped);
		return;
	}


	btTransform orgtrans0 = body0->getWorldTransform();

	btTransform orgtrans1 = body1->getWorldTransform();

	btAlignedObjectArray<int> collided_results;

	gimpact_vs_shape_find_pairs(orgtrans0,orgtrans1,shape0,shape1,collided_results);

	if(collided_results.size() == 0) return;


	shape0->lockChildShapes();

	GIM_ShapeRetriever retriever0(shape0);


	bool child_has_transform0 = shape0->childrenHasTransform();


	int i = collided_results.size();

	while(i--)
	{
		int child_index = collided_results[i];
        if(swapped)
    		m_triface1 = child_index;
        else
            m_triface0 = child_index;

		btCollisionShape * colshape0 = retriever0.getChildShape(child_index);

		if(child_has_transform0)
		{
			body0->setWorldTransform(orgtrans0*shape0->getChildTransform(child_index));
		}

		//collide two shapes
		if(swapped)
		{
			shape_vs_shape_collision(body1,body0,shape1,colshape0);
		}
		else
		{
			shape_vs_shape_collision(body0,body1,colshape0,shape1);
		}

		//restore transforms
		if(child_has_transform0)
		{
			body0->setWorldTransform(orgtrans0);
		}

	}

	shape0->unlockChildShapes();

}