notgiven688/jitterphysics2

If I want to scale the convex hull of a rigid body, what is the correct operation?

CeSun opened this issue · 1 comments

CeSun commented

Transform all vertices and reconstruct the shape?

Transform all vertices and reconstruct the shape?

Yes, transforming all vertices and reconstructing the shape would be the method of choice. However, there's an exception: if you have many instances of convex hulls that only differ in their scaling factor. In such cases, you can wrap your ConvexHullShape inside a TransformedShape. To perform the scaling transformation, modify the diagonal entries of the "orientation" matrix in the constructor. I will rename the matrix, as it supports not only orientation but also scaling. In fact, all affine transformations (see Affine Transformation) are supported by TransformedShape.

Here's an example from JitterDemo, in ConvexDecomposition.cs:

Change:

foreach (ConvexHullShape s in shapesToAdd)
{
  body.AddShape(s.Clone(), false);
}

To:

foreach (ConvexHullShape s in shapesToAdd)
{
  body.AddShape(new TransformedShape(s.Clone(), JMatrix.Identity * 0.2f, JVector.Zero), false);
}

This will scale your object by a factor of 0.2.