abstract frustum culling
parent
fc09082f1b
commit
7f986c546a
|
@ -0,0 +1,9 @@
|
||||||
|
using Microsoft.Xna.Framework;
|
||||||
|
|
||||||
|
namespace Kav
|
||||||
|
{
|
||||||
|
public interface ICullable
|
||||||
|
{
|
||||||
|
BoundingBox BoundingBox { get; }
|
||||||
|
}
|
||||||
|
}
|
|
@ -4,7 +4,7 @@ using Microsoft.Xna.Framework.Graphics;
|
||||||
|
|
||||||
namespace Kav
|
namespace Kav
|
||||||
{
|
{
|
||||||
public class MeshSprite
|
public class MeshSprite : ICullable
|
||||||
{
|
{
|
||||||
private static readonly int PixelScale = 40;
|
private static readonly int PixelScale = 40;
|
||||||
private static readonly short[] Indices = new short[]
|
private static readonly short[] Indices = new short[]
|
||||||
|
|
|
@ -2,7 +2,7 @@ using Microsoft.Xna.Framework;
|
||||||
|
|
||||||
namespace Kav
|
namespace Kav
|
||||||
{
|
{
|
||||||
public class Model
|
public class Model : ICullable
|
||||||
{
|
{
|
||||||
public Mesh[] Meshes { get; }
|
public Mesh[] Meshes { get; }
|
||||||
public BoundingBox BoundingBox { get; }
|
public BoundingBox BoundingBox { get; }
|
||||||
|
|
27
Renderer.cs
27
Renderer.cs
|
@ -836,32 +836,17 @@ namespace Kav
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static IEnumerable<(Model, Matrix)> FrustumCull(
|
private static IEnumerable<(T, Matrix)> FrustumCull<T>(
|
||||||
BoundingFrustum boundingFrustum,
|
BoundingFrustum boundingFrustum,
|
||||||
IEnumerable<(Model, Matrix)> modelTransforms
|
IEnumerable<(T, Matrix)> cullableTransforms
|
||||||
) {
|
) where T : ICullable {
|
||||||
foreach (var modelTransform in modelTransforms)
|
foreach (var (cullable, transform) in cullableTransforms)
|
||||||
{
|
{
|
||||||
var boundingBox = TransformedBoundingBox(modelTransform.Item1.BoundingBox, modelTransform.Item2);
|
var boundingBox = TransformedBoundingBox(cullable.BoundingBox, transform);
|
||||||
var containment = boundingFrustum.Contains(boundingBox);
|
var containment = boundingFrustum.Contains(boundingBox);
|
||||||
if (containment != ContainmentType.Disjoint)
|
if (containment != ContainmentType.Disjoint)
|
||||||
{
|
{
|
||||||
yield return modelTransform;
|
yield return (cullable, transform);
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static IEnumerable<(MeshSprite, Matrix)> FrustumCull(
|
|
||||||
BoundingFrustum boundingFrustum,
|
|
||||||
IEnumerable<(MeshSprite, Matrix)> meshSpriteTransforms
|
|
||||||
) {
|
|
||||||
foreach (var (meshSprite, transform) in meshSpriteTransforms)
|
|
||||||
{
|
|
||||||
var boundingBox = TransformedBoundingBox(meshSprite.BoundingBox, transform);
|
|
||||||
var containment = boundingFrustum.Contains(boundingBox);
|
|
||||||
if (containment != ContainmentType.Disjoint)
|
|
||||||
{
|
|
||||||
yield return (meshSprite, transform);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue