Code: Select all
var boxes = new List<CompoundShapeEntry>();
BoxShape box = new BoxShape(1f, 1f, 1f);
boxes.Add(new CompoundShapeEntry(box, Vector3.Zero));
CompoundBody body = new CompoundBody(boxes);
Using that, body.Position is Vector3.Zero, as expected. Additionally, body.WorldTransform.Translation is also Vector3.Zero, as expected- the WorldTransform property is just a convenience property that uses the Position and Orientation(Matrix).
Code: Select all
var boxes = new List<CompoundShapeEntry>();
BoxShape box = new BoxShape(1f, 1f, 1f);
boxes.Add(new CompoundShapeEntry(box, new Vector3(1, 1, 1)));
CompoundBody body = new CompoundBody(boxes);
Note the different local translation on the CompoundShapeEntry. If you look at the body.Position on this version, it says (1,1,1), since that's the location of the center of the compound shape (which, in this example, is a single shape at (1,1,1)). Internally, the CompoundShape stores the BoxShape with a local transformation with translation of (0,0,0), since the subshape is perfectly aligned with the compound local origin (because it's the only shape).
Code: Select all
var boxes = new List<CompoundShapeEntry>();
boxes.Add(new CompoundShapeEntry(new BoxShape(1f, 1f, 1f), new Vector3(1, 1, 0)));
boxes.Add(new CompoundShapeEntry(new BoxShape(1f, 1f, 1f), new Vector3(-1, 1, 0)));
CompoundBody body = new CompoundBody(boxes);
The above shows a two-box body. The body.Position is now (0,1,0), since that's the weighted average of the locations of the shapes. The internal local transformations of the box shapes in the compound shape are (1,0,0) and (-1,0,0).
So let's imagine you had a graphic that was created such that its local origin was at (0,0,0) and the box shape models were positioned at (1,1,0) and (-1,1,0). If the compound didn't move and you just directly rendered the graphic without transforming it using the entity's position, the shapes would match.
However, because the entity's transform now includes an offset, you need to apply the reverse offset to the graphic to realign them. In other words, apply a local transform of -InitialCenterOffset (where InitialCenterOffset = body.Position right after initialization) before applying entity.WorldTransform.