Exemple #1
0
PxConvexMesh* createCylinderMesh( const osg::Vec3& c, float radius, float width, unsigned int samples )
{
    PxVec3 center(c[0], c[1], c[2]);
    std::vector<PxVec3> verts;
    float theta = 2.0f * osg::PI / (float)samples;
    for ( unsigned int i=0; i<samples; ++i )
    {
        float cosine = radius * cos(theta * (float)i);
        float sine = radius * sin(theta * (float)i);
        verts.push_back( center + PxVec3(-0.5f * width, cosine, sine) );
        verts.push_back( center + PxVec3(+0.5f * width, cosine, sine) );
    }
    return createConvexMesh( verts );
}
Exemple #2
0
PxConvexMesh* createBoxMesh( const osg::Vec3& c, const osg::Vec3& dim )
{
    PxVec3 center(c[0], c[1], c[2]), halfDim(dim[0] * 0.5f, dim[1] * 0.5f, dim[2] * 0.5f);
    std::vector<PxVec3> verts;
    verts.push_back( center + PxVec3(-halfDim.x, -halfDim.y, -halfDim.z) );
    verts.push_back( center + PxVec3(-halfDim.x, -halfDim.y, +halfDim.z) );
    verts.push_back( center + PxVec3(-halfDim.x, +halfDim.y, -halfDim.z) );
    verts.push_back( center + PxVec3(-halfDim.x, +halfDim.y, +halfDim.z) );
    verts.push_back( center + PxVec3(+halfDim.x, -halfDim.y, -halfDim.z) );
    verts.push_back( center + PxVec3(+halfDim.x, -halfDim.y, +halfDim.z) );
    verts.push_back( center + PxVec3(+halfDim.x, +halfDim.y, -halfDim.z) );
    verts.push_back( center + PxVec3(+halfDim.x, +halfDim.y, +halfDim.z) );
    return createConvexMesh( verts );
}
PxConvexMesh* createWedgeConvexMesh(const PxVec3& halfExtents, PxPhysics& physics, PxCooking& cooking)
{
	PxVec3 verts[6]=
	{
		PxVec3(-halfExtents.x, -halfExtents.y, -halfExtents.z),
		PxVec3(-halfExtents.x, -halfExtents.y, +halfExtents.z),
		PxVec3(-halfExtents.x, +halfExtents.y, -halfExtents.z),
		PxVec3(+halfExtents.x, -halfExtents.y, -halfExtents.z),
		PxVec3(+halfExtents.x, -halfExtents.y, +halfExtents.z),
		PxVec3(+halfExtents.x, +halfExtents.y, -halfExtents.z)
	};	
	PxU32 numVerts=6;

	return createConvexMesh(verts,numVerts,physics,cooking);
}
PxConvexMesh* Vehicle::createWheelMesh(const PxF32 width, const PxF32 radius, PxPhysics& physics, PxCooking& cooking)
{
	PxVec3 points[2 * 16];
	for (PxU32 i = 0; i < 16; i++)
	{
		const PxF32 cosTheta = PxCos(i*PxPi*2.0f / 16.0f);
		const PxF32 sinTheta = PxSin(i*PxPi*2.0f / 16.0f);
		const PxF32 y = radius*cosTheta;
		const PxF32 z = radius*sinTheta;
		points[2 * i + 0] = PxVec3(-width / 2.0f, y, z);
		points[2 * i + 1] = PxVec3(+width / 2.0f, y, z);
	}

	return createConvexMesh(points, 32, physics, cooking);
}
PxConvexMesh* createCylinderConvexMesh(const PxF32 width, const PxF32 radius, const PxU32 numCirclePoints, PxPhysics& physics, PxCooking& cooking)
{
#define  MAX_NUM_VERTS_IN_CIRCLE 16
	PX_ASSERT(numCirclePoints<MAX_NUM_VERTS_IN_CIRCLE);
	PxVec3 verts[2*MAX_NUM_VERTS_IN_CIRCLE];
	PxU32 numVerts=2*numCirclePoints;
	const PxF32 dtheta=2*PxPi/(1.0f*numCirclePoints);
	for(PxU32 i=0;i<MAX_NUM_VERTS_IN_CIRCLE;i++)
	{
		const PxF32 theta=dtheta*i;
		const PxF32 cosTheta=radius*PxCos(theta);
		const PxF32 sinTheta=radius*PxSin(theta);
		verts[2*i+0]=PxVec3(-0.5f*width, cosTheta, sinTheta);
		verts[2*i+1]=PxVec3(+0.5f*width, cosTheta, sinTheta);
	}

	return createConvexMesh(verts,numVerts,physics,cooking);
}
PxConvexMesh* createPrismConvexMesh(const PxF32 baseLength, const PxF32 baseDepth, const PxF32 height, PxPhysics& physics, PxCooking& cooking)
{
	const PxF32 x=baseLength*0.5f;
	const PxF32 z=baseDepth*0.5f;

	PxVec3 verts[6]=
	{
		PxVec3(-x, 0, -z),
		PxVec3(-x, 0, +z),
		PxVec3(+x, 0, -z),
		PxVec3(+x, 0, +z),
		PxVec3(-x, height, 0),
		PxVec3(+x, height, 0),
	};	
	PxU32 numVerts=6;

	return createConvexMesh(verts,numVerts,physics,cooking);
}
PxConvexMesh* createSquashedCuboidMesh(const PxF32 baseLength, const PxF32 baseDepth, const PxF32 height1, const PxF32 height2, PxPhysics& physics, PxCooking& cooking)
{
	const PxF32 x=baseLength*0.5f;
	const PxF32 z=baseDepth*0.5f;
	PxVec3 verts[8]=
	{
		PxVec3(-x,-0.5f*height1,-z),
		PxVec3(-x,-0.5f*height1,+z),
		PxVec3(+x,-0.5f*height1,-z),
		PxVec3(+x,-0.5f*height1,+z),
		PxVec3(-x,-0.5f*height1+height2,-z),
		PxVec3(-x,+0.5f*height1,+z),
		PxVec3(+x,-0.5f*height1+height2,-z),
		PxVec3(+x,+0.5f*height1,+z)
	};
	PxU32 numVerts=8;

	return createConvexMesh(verts,numVerts,physics,cooking);
}
PxConvexMesh* Vehicle::createChassisMesh(const PxVec3 dims, PxPhysics& physics, PxCooking& cooking)
{
	const PxF32 x = dims.x*0.5f;
	const PxF32 y = dims.y*0.5f;
	const PxF32 z = dims.z*0.5f;
	PxVec3 verts[8] =
	{
		PxVec3(x, y, -z),
		PxVec3(x, y, z),
		PxVec3(x, -y, z),
		PxVec3(x, -y, -z),
		PxVec3(-x, y, -z),
		PxVec3(-x, y, z),
		PxVec3(-x, -y, z),
		PxVec3(-x, -y, -z)
	};

	return createConvexMesh(verts, 8, physics, cooking);
}
PxConvexMesh* createChassisConvexMesh(const PxVec3* verts, const PxU32 numVerts, PxPhysics& physics, PxCooking& cooking)
{
	return createConvexMesh(verts,numVerts,physics,cooking);
}