你好,我正在编写关于 XNA 4.0 中 Ants 的小 RPG。我已将 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 个球体,它们都在同一个地方。谢谢你的任何提示。