i got some difficulties with compoundbody.
I create a tank vehicle, the vehicle body is a compoundobject with the tanks body as convexhull.
That works so far, now i want to add a tank turret, which shall be rotateable on the tanks body.
I want to place the turret on top of the body but it gets always placed in the middle of the tanks body and i don`t understand why...
Code: Select all
modelBody = new CompoundBody(false);
// TANK BODY
List<Vector3> vertices = new List<Vector3>();
Matrix[] transforms = new Matrix[model.Bones.Count];
model.CopyAbsoluteBoneTransformsTo(transforms);
XNAutils.XNAutils.ExtractVectors(model.Meshes[0], vertices, transforms[model.Meshes[0].ParentBone.Index]);
ConvexHull cHull = new ConvexHull(vertices);
modelBody.addBody(cHull);
modelVehicle = new Vehicle(modelBody);
// TANK TURRET
vertices.Clear();
transforms = new Matrix[modelTurret.Bones.Count];
modelTurret.CopyAbsoluteBoneTransformsTo(transforms);
XNAutils.XNAutils.ExtractVectors(modelTurret.Meshes[0], vertices, transforms[modelTurret.Meshes[0].ParentBone.Index]);
Vector3 turretPosition = modelPosition;
turretPosition.Y += 15.0f;
cHull = new ConvexHull(vertices);
cHull.centerPosition = turretPosition;
modelBody.addBody(cHull);
//Matrix turretMatrix = (Matrix.CreateRotationX(MathHelper.ToRadians(modelRotation.X)) * Matrix.CreateRotationY(MathHelper.ToRadians(modelRotation.Y)) * Matrix.CreateRotationZ(MathHelper.ToRadians(modelRotation.Z))) * Matrix.CreateTranslation(turretPosition);
//modelBody.subBodies[1].internalWorldTransform = turretMatrix;
// TANK WHEELs
...
modelBody.becomeDynamic(400f);
modelMatrix = (Matrix.CreateRotationX(MathHelper.ToRadians(modelRotation.X)) * Matrix.CreateRotationY(MathHelper.ToRadians(modelRotation.Y)) * Matrix.CreateRotationZ(MathHelper.ToRadians(modelRotation.Z))) * Matrix.CreateTranslation(modelPosition);
modelVehicle.body.worldTransform = modelMatrix;
space.add(modelVehicle);