Example #1
0
int		CLPhysicsDemo::registerCompoundShape(btAlignedObjectArray<btGpuChildShape>* childShapes)
{
	
	int collidableIndex = m_narrowphaseAndSolver->allocateCollidable();
	btCollidable& col = m_narrowphaseAndSolver->getCollidableCpu(collidableIndex);
	col.m_shapeType = CollisionShape::SHAPE_COMPOUND_OF_CONVEX_HULLS;
	
	col.m_shapeIndex = m_narrowphaseAndSolver->registerCompoundShape(childShapes);
	col.m_numChildShapes = childShapes->size();
	
	
	btAABBHost aabbMin, aabbMax;
	btVector3 myAabbMin(1e30f,1e30f,1e30f);
	btVector3 myAabbMax(-1e30f,-1e30f,-1e30f);
	
	//compute local AABB of the compound of all children
	for (int i=0;i<childShapes->size();i++)
	{
		int childColIndex = childShapes->at(i).m_shapeIndex;
		btCollidable& childCol = m_narrowphaseAndSolver->getCollidableCpu(childColIndex);
		btAABBHost aabbMinLoc =m_data->m_localShapeAABBCPU->at(childColIndex*2);
		btAABBHost aabbMaxLoc =m_data->m_localShapeAABBCPU->at(childColIndex*2+1);

		btVector3 childLocalAabbMin(aabbMinLoc.fx,aabbMinLoc.fy,aabbMinLoc.fz);
		btVector3 childLocalAabbMax(aabbMaxLoc.fx,aabbMaxLoc.fy,aabbMaxLoc.fz);
		btVector3 aMin,aMax;
		btScalar margin(0.f);
		btTransform childTr;
		childTr.setIdentity();

		childTr.setOrigin(btVector3(childShapes->at(i).m_childPosition[0],
									childShapes->at(i).m_childPosition[1],
									childShapes->at(i).m_childPosition[2]));
		childTr.setRotation(btQuaternion(childShapes->at(i).m_childOrientation[0],
										 childShapes->at(i).m_childOrientation[1],
										 childShapes->at(i).m_childOrientation[2],
										 childShapes->at(i).m_childOrientation[3]));
		btTransformAabb(childLocalAabbMin,childLocalAabbMax,margin,childTr,aMin,aMax);
		myAabbMin.setMin(aMin);
		myAabbMax.setMax(aMax);		
	}
	
	aabbMin.fx = myAabbMin[0];//s_convexHeightField->m_aabb.m_min.x;
	aabbMin.fy = myAabbMin[1];//s_convexHeightField->m_aabb.m_min.y;
	aabbMin.fz= myAabbMin[2];//s_convexHeightField->m_aabb.m_min.z;
	aabbMin.uw = 0;
	
	aabbMax.fx = myAabbMax[0];//s_convexHeightField->m_aabb.m_max.x;
	aabbMax.fy = myAabbMax[1];//s_convexHeightField->m_aabb.m_max.y;
	aabbMax.fz= myAabbMax[2];//s_convexHeightField->m_aabb.m_max.z;
	aabbMax.uw = 0;
	
	m_data->m_localShapeAABBCPU->push_back(aabbMin);
	m_data->m_localShapeAABBGPU->push_back(aabbMin);
	
	m_data->m_localShapeAABBCPU->push_back(aabbMax);
	m_data->m_localShapeAABBGPU->push_back(aabbMax);
	clFinish(g_cqCommandQue);
	
	
	
	
	return collidableIndex;
	
}
Example #2
0
int		b3GpuNarrowPhase::registerCompoundShape(b3AlignedObjectArray<b3GpuChildShape>* childShapes)
{
	
	int collidableIndex = allocateCollidable();
	if (collidableIndex<0)
		return collidableIndex;

	b3Collidable& col = getCollidableCpu(collidableIndex);
	col.m_shapeType = SHAPE_COMPOUND_OF_CONVEX_HULLS;
	
	col.m_shapeIndex = m_data->m_cpuChildShapes.size();
	{
		b3Assert(col.m_shapeIndex+childShapes->size()<m_data->m_config.m_maxCompoundChildShapes);
		for (int i=0;i<childShapes->size();i++)
		{
			m_data->m_cpuChildShapes.push_back(childShapes->at(i));
		}
	}



	col.m_numChildShapes = childShapes->size();
	
	
	b3SapAabb aabbWS;
	b3Vector3 myAabbMin(1e30f,1e30f,1e30f);
	b3Vector3 myAabbMax(-1e30f,-1e30f,-1e30f);
	
	//compute local AABB of the compound of all children
	for (int i=0;i<childShapes->size();i++)
	{
		int childColIndex = childShapes->at(i).m_shapeIndex;
		b3Collidable& childCol = getCollidableCpu(childColIndex);
		b3SapAabb aabbLoc =m_data->m_localShapeAABBCPU->at(childColIndex);

		b3Vector3 childLocalAabbMin(aabbLoc.m_min[0],aabbLoc.m_min[1],aabbLoc.m_min[2]);
		b3Vector3 childLocalAabbMax(aabbLoc.m_max[0],aabbLoc.m_max[1],aabbLoc.m_max[2]);
		b3Vector3 aMin,aMax;
		b3Scalar margin(0.f);
		b3Transform childTr;
		childTr.setIdentity();

		childTr.setOrigin(b3Vector3(childShapes->at(i).m_childPosition[0],
									childShapes->at(i).m_childPosition[1],
									childShapes->at(i).m_childPosition[2]));
		childTr.setRotation(b3Quaternion(childShapes->at(i).m_childOrientation[0],
										 childShapes->at(i).m_childOrientation[1],
										 childShapes->at(i).m_childOrientation[2],
										 childShapes->at(i).m_childOrientation[3]));
		b3TransformAabb(childLocalAabbMin,childLocalAabbMax,margin,childTr,aMin,aMax);
		myAabbMin.setMin(aMin);
		myAabbMax.setMax(aMax);		
	}
	
	aabbWS.m_min[0] = myAabbMin[0];//s_convexHeightField->m_aabb.m_min.x;
	aabbWS.m_min[1]= myAabbMin[1];//s_convexHeightField->m_aabb.m_min.y;
	aabbWS.m_min[2]= myAabbMin[2];//s_convexHeightField->m_aabb.m_min.z;
	aabbWS.m_minIndices[3] = 0;
	
	aabbWS.m_max[0] = myAabbMax[0];//s_convexHeightField->m_aabb.m_max.x;
	aabbWS.m_max[1]= myAabbMax[1];//s_convexHeightField->m_aabb.m_max.y;
	aabbWS.m_max[2]= myAabbMax[2];//s_convexHeightField->m_aabb.m_max.z;
	aabbWS.m_signedMaxIndices[3] = 0;
	
	m_data->m_localShapeAABBCPU->push_back(aabbWS);
//	m_data->m_localShapeAABBGPU->push_back(aabbWS);
	clFinish(m_queue);
	return collidableIndex;
	
}