If I want to scale the convex hull of a rigid body, what is the correct operation? #28
Replies: 4 comments 2 replies
-
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 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. |
Beta Was this translation helpful? Give feedback.
-
Orientation does not seem to take effect on scaling, my code is: RigidBody = Owner.CurrentLevel.PhyWorld.CreateRigidBody();
RigidBody.Position = new JVector(WorldLocation.X, WorldLocation.Y, WorldLocation.Z);
foreach(var shape in StaticMesh.Shapes)
{
RigidBody.AddShape(shape);
}
var Matrix = MatrixHelper.CreateTransform(Vector3.Zero, WorldRotation, WorldScale);
RigidBody.Orientation = new JMatrix
{
M11 = Matrix.M11,
M12 = Matrix.M12,
M13 = Matrix.M13,
M21 = Matrix.M21,
M22 = Matrix.M22,
M23 = Matrix.M23,
M31 = Matrix.M31,
M32 = Matrix.M32,
M33 = Matrix.M33,
}; |
Beta Was this translation helpful? Give feedback.
-
Modifying the shape every time the scale changes is very resource intensive, and will also generate a lot of objects that generate GC pressure, so I hope to directly modify the matrix of the rigid body. |
Beta Was this translation helpful? Give feedback.
-
You need to wrap your hull-shape in a TransformedShape - see my example from above. You can then change the transforms "on the fly" without much cost, by modifying the "Transformation" property of the TransformedShape. |
Beta Was this translation helpful? Give feedback.
-
Transform all vertices and reconstruct the shape?
Beta Was this translation helpful? Give feedback.
All reactions