I have two convex hulls, both of which are created from data which is also used to render the turning part and the barrel part on a turret. I have correctly positioned and rotated the visible version of the turret and barrel, but I can't correctly position the physics parts.
What happens is that they always rotate around their center of mass, rather than rotating around their original origin, which is understandable, but I need to create the illusion that they are rotating around their original origins.
The center point of the renderable version has been explicitly set, so that I can rotate different parts of the model around an arbitrary point, e.g. rotating a cannon barrel around a point at the far end. I cannot use the centre of mass instead, because then I wont be able to correctly animate the model - the arbitrary origin points are staying as they are.
Here is the code I am using to set the position of the renderable and phyics bodies; the renderable body is correctly positioned, and I am now trying to derive the position of the physics body from the position of the renderable. The physics bodies are kinematic bodies with no solver states set on them.
Code: Select all
public void repositionChildren()
{
// update position of renderable meshes
turret_renderable.rotation = this.TargetRotation;
barrel_renderable.rotation = this.TargetElevation;
// barrel renderable is relative to turret renderable
barrel_renderable.setOffset(Matrix.CreateTranslation(this.BarrelOffset) * turret_renderable.getPosition());
// update position of turret detector volumes
this.turret_hull.WorldTransform =
this.turret_renderable.createLocalTransform()
* turret_renderable.offsetFromRoot
* this.Position;
this.barrel_hull.WorldTransform =
this.barrel_renderable.createLocalTransform()
* barrel_renderable.offsetFromRoot
* this.Position;
}