这是我显示边界框的代码
Vector3[] corners = box.GetCorners();
for (int i = 0; i < 8; i++)
{
verts[i].Position = Vector3.Transform(corners[i],modelMatrix);
verts[i].Color = Color.White;
}
vbo.SetData(verts);
ibo.SetData(indices);
foreach (EffectPass pass in effect.CurrentTechnique.Passes)
{
effect.World = Matrix.Identity;
effect.View = view;
effect.Projection = projection;
pass.Apply();
ContentLoader.SetBuffers(ibo, vbo);
}
我想使用BoundingBox
类来实现相同的结果。我试图这样做,但它不起作用
for (int i = 0; i < boundingBoxes.Count; i++)
{
Vector3 min = Vector3.Transform(boundingBoxes[i].Min, modelMatrix);
Vector3 max = Vector3.Transform(boundingBoxes[i].Max, modelMatrix);
boundingBoxes[i] = new BoundingBox(min, max);
}
如果没有旋转,上面的代码就可以工作。随着旋转,事情会变得一团糟。知道为什么以及如何解决它吗?