0

这是我显示边界框的代码

 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);
        }

如果没有旋转,上面的代码就可以工作。随着旋转,事情会变得一团糟。知道为什么以及如何解决它吗?

4

1 回答 1

-1

您不能在 Xna 中旋转 BoundingBox 对象。BoundingBox 类的内置碰撞检测方法将始终根据轴对齐中的框的最小值和最大值计算。通过转换最小值和最大值,您不会旋转框,您只是更改轴对齐框的 x、y、z 尺寸。

You might be better off studying up on "oriented bounding boxes". You would draw an oriented box by using the corners as verts and choosing 'LineList' as your PrimitiveType instead of 'TriangleList' in the 'DrawIndexedPrimitives' method. Collision detection for an oriented box is different & more complex than for an axis aligned box.

于 2012-12-08T17:41:57.243 回答