Beispiel #1
0
int		b3GpuNarrowPhase::registerConvexHullShape(b3ConvexUtility* utilPtr)
{
	int collidableIndex = allocateCollidable();
	if (collidableIndex<0)
		return collidableIndex;

	b3Collidable& col = getCollidableCpu(collidableIndex);
	col.m_shapeType = SHAPE_CONVEX_HULL;
	col.m_shapeIndex = -1;
	
	
	{
		b3Vector3 localCenter(0,0,0);
		for (int i=0;i<utilPtr->m_vertices.size();i++)
			localCenter+=utilPtr->m_vertices[i];
		localCenter*= (1.f/utilPtr->m_vertices.size());
		utilPtr->m_localCenter = localCenter;

		col.m_shapeIndex = registerConvexHullShape(utilPtr,col);
	}

	if (col.m_shapeIndex>=0)
	{
		b3SapAabb aabb;
		
		b3Vector3 myAabbMin(1e30f,1e30f,1e30f);
		b3Vector3 myAabbMax(-1e30f,-1e30f,-1e30f);

		for (int i=0;i<utilPtr->m_vertices.size();i++)
		{
			myAabbMin.setMin(utilPtr->m_vertices[i]);
			myAabbMax.setMax(utilPtr->m_vertices[i]);
		}
		aabb.m_min[0] = myAabbMin[0];
		aabb.m_min[1] = myAabbMin[1];
		aabb.m_min[2] = myAabbMin[2];
		aabb.m_minIndices[3] = 0;

		aabb.m_max[0] = myAabbMax[0];
		aabb.m_max[1] = myAabbMax[1];
		aabb.m_max[2] = myAabbMax[2];
		aabb.m_signedMaxIndices[3] = 0;

		m_data->m_localShapeAABBCPU->push_back(aabb);
//		m_data->m_localShapeAABBGPU->push_back(aabb);
	}
	
	return collidableIndex;

}
Beispiel #2
0
Vec2 CPuppet::GetCenterInWorld() const
{
    Vec2 localCenter(0, 0);
    return convertToWorldSpace(localCenter);
}
Beispiel #3
0
int		CLPhysicsDemo::registerConvexShape(btConvexUtility* utilPtr , bool noHeightField)
{
	int collidableIndex = narrowphaseAndSolver->allocateCollidable();

	btCollidable& col = narrowphaseAndSolver->getCollidableCpu(collidableIndex);
	col.m_shapeType = CollisionShape::SHAPE_CONVEX_HULL;
	col.m_shapeIndex = -1;
	
	int numFaces= utilPtr->m_faces.size();
	float4* eqn = new float4[numFaces];
	for (int i=0;i<numFaces;i++)
	{
		eqn[i].x = utilPtr->m_faces[i].m_plane[0];
		eqn[i].y = utilPtr->m_faces[i].m_plane[1];
		eqn[i].z = utilPtr->m_faces[i].m_plane[2];
		eqn[i].w = utilPtr->m_faces[i].m_plane[3];
	}
	printf("numFaces = %d\n", numFaces);

	if (noHeightField)
	{
		s_convexHeightField = 0;
	} else
	{
		s_convexHeightField = new ConvexHeightField(eqn,numFaces);
	}



	if (narrowphaseAndSolver)
	{
		btVector3 localCenter(0,0,0);
		for (int i=0;i<utilPtr->m_vertices.size();i++)
			localCenter+=utilPtr->m_vertices[i];
		localCenter*= (1./utilPtr->m_vertices.size());
		utilPtr->m_localCenter = localCenter;

		if (useConvexHeightfield)
		col.m_shapeIndex = narrowphaseAndSolver->registerConvexHeightfield(s_convexHeightField,col);
		else
			col.m_shapeIndex = narrowphaseAndSolver->registerConvexHullShape(utilPtr,col);
	}

	if (col.m_shapeIndex>=0)
	{
		btAABBHost aabbMin, aabbMax;
		btVector3 myAabbMin(1e30f,1e30f,1e30f);
		btVector3 myAabbMax(-1e30f,-1e30f,-1e30f);

		for (int i=0;i<utilPtr->m_vertices.size();i++)
		{
			myAabbMin.setMin(utilPtr->m_vertices[i]);
			myAabbMax.setMax(utilPtr->m_vertices[i]);
		}
		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);

		//m_data->m_localShapeAABB->copyFromHostPointer(&aabbMin,1,shapeIndex*2);
		//m_data->m_localShapeAABB->copyFromHostPointer(&aabbMax,1,shapeIndex*2+1);
		clFinish(g_cqCommandQue);
	}

	delete[] eqn;
	
	
	
	return collidableIndex;

}