Здравствуйте, я пишу небольшую ролевую игру про муравьев в XNA 4.0. Я сделал класс LoadModel для загрузки модели fbx и для создания ограничивающих сфер. У меня есть одна общая ограничивающая сфера в модели, созданной путем слияния сетки модели. Теперь я создал модель с дополнительной сферой, которая представляет мою ограничивающую сферу в игре. Я просто проверяю, является ли имя сетки «BoundingSphere», и когда это так, я добавляю mesh.BoundingSphere в свой массив bs. Теперь я не знаю, как обновить эти bs... Мои попытки кода:
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();
}
Теперь получаем/устанавливаем массив BoundingSphere:
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{}
}
У меня в модели 2 сферы, и обе они в одном и том же месте. Спасибо за любую подсказку.