Hallo I'm writting little RPG about Ants in XNA 4.0. I have made LoadModel class to fbx model load, and to create bounding spheres. I have one general bounding sphere at the model created by merging model mesh. Now i created model with additional sphere which represent my bounding sphere in game. I just checking if the Mesh name is "BoundingSphere" and when it is I'm adding mesh.BoundingSphere to my array of bs. Now i dont now how to update those bs... My code attempts:
private void buildBoundingSphere()
{
BoundingSphere sphere = new BoundingSphere(Vector3.Zero, 0);
List<BoundingSphere> spheres = new List<BoundingSphere>();
foreach (ModelMesh mesh in Model.Meshes)
{
if (mesh.Name.Contains("BoundingSphere") )
{
BoundingSphere transformed = mesh.BoundingSphere.Transform(modelTransforms[mesh.ParentBone.Index])
spheres.Add(transformed);
sphere = BoundingSphere.CreateMerged(sphere, transformed);
}
}
this.boundingSphere = sphere;
this.spheres = spheres.ToArray();
}
Now the BoundingSphere array get/set:
public BoundingSphere[] spheres
{
get
{
// No need for rotation, as this is a sphere
List<BoundingSphere> spheres = new List<BoundingSphere>();
foreach (ModelMesh mesh in Model.Meshes)
{
Matrix worldTransform = Matrix.CreateScale(Scale)* Matrix.CreateTranslation(Position);
if (mesh.Name.Contains("BoundingSphere")) {
BoundingSphere transformed = mesh.BoundingSphere.Transform(worldTransform);
spheres.Add(transformed);
}
}
return spheres.ToArray();
}
set{}
}
I have 2 spheres in model, and both of them are in the same place. Thank you for any hint.