コード例 #1
0
/** Helper to transform a normal when non-uniform scale is present. */
static PxVec3 TransformNormalToShapeSpace(const PxMeshScale& meshScale, const PxVec3& nIn)
{
	// Uniform scale makes this unnecessary
	if (meshScale.scale.x == meshScale.scale.y &&
		meshScale.scale.x == meshScale.scale.z)
	{
		return nIn;
	}
	
	if (PxQuatIsIdentity(meshScale.rotation))
	{
		// Inverse transpose: inverse is 1/scale, transpose = original when rotation is identity.
		const PxVec3 tmp = PxVec3(nIn.x / meshScale.scale.x, nIn.y / meshScale.scale.y, nIn.z / meshScale.scale.z);
		const PxReal denom = 1.0f / tmp.magnitude();
		return tmp * denom;
	}
	else
	{
		const PxMat33 rot(meshScale.rotation);
		const PxMat33 diagonal = PxMat33::createDiagonal(meshScale.scale);
		const PxMat33 vertex2Shape = (rot.getTranspose() * diagonal) * rot;

		const PxMat33 shape2Vertex = vertex2Shape.getInverse();
		const PxVec3 tmp = shape2Vertex.transformTranspose(nIn);
		const PxReal denom = 1.0f / tmp.magnitude();
		return tmp * denom;
	}
}
コード例 #2
0
void scalePlanes(PxPlane* scaledPlaneBuf, const Gu::ConvexHullData* convexHullData, const PxMat33& invScaling)
{
	PxU32 numPlanes = convexHullData->mNbPolygons;
	PxPlane* planeIt = scaledPlaneBuf; 
	const Gu::HullPolygonData* polygonIt = convexHullData->mPolygons;
	for(; numPlanes>0; --numPlanes, ++planeIt, ++polygonIt) 
	{
		PxVec3 normal=polygonIt->mPlane.n;		
		PxF32 d=polygonIt->mPlane.d;
		normal = invScaling.transformTranspose(normal);		
		PxReal magnitude = normal.normalize();
		*planeIt = PxPlane(normal, d / magnitude);
	}
}