Created
November 2, 2012 18:00
-
-
Save demonixis/4003211 to your computer and use it in GitHub Desktop.
BoundingBoxRenderer for XNA 4.0 Reach profile
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class BoundingBoxRenderer | |
{ | |
#region Fields | |
static VertexPositionColor[] verts = new VertexPositionColor[8]; | |
static short[] indices = new short[] | |
{ | |
0, 1, | |
1, 2, | |
2, 3, | |
3, 0, | |
0, 4, | |
1, 5, | |
2, 6, | |
3, 7, | |
4, 5, | |
5, 6, | |
6, 7, | |
7, 4, | |
}; | |
static BasicEffect effect; | |
static VertexDeclaration vertDecl; | |
#endregion | |
/// <summary> | |
/// Renders the bounding box for debugging purposes. | |
/// </summary> | |
/// <param name="box">The box to render.</param> | |
/// <param name="graphicsDevice">The graphics device to use when rendering.</param> | |
/// <param name="view">The current view matrix.</param> | |
/// <param name="projection">The current projection matrix.</param> | |
/// <param name="color">The color to use drawing the lines of the box.</param> | |
public static void Render( | |
BoundingBox box, | |
GraphicsDevice graphicsDevice, | |
Matrix view, | |
Matrix projection, | |
Color color) | |
{ | |
if (effect == null) | |
{ | |
effect = new BasicEffect(graphicsDevice); | |
effect.VertexColorEnabled = true; | |
effect.LightingEnabled = false; | |
} | |
Vector3[] corners = box.GetCorners(); | |
for (int i = 0; i < 8; i++) | |
{ | |
verts[i].Position = corners[i]; | |
verts[i].Color = color; | |
} | |
effect.View = view; | |
effect.Projection = projection; | |
foreach (EffectPass pass in effect.CurrentTechnique.Passes) | |
{ | |
pass.Apply(); | |
graphicsDevice.DrawUserIndexedPrimitives( | |
PrimitiveType.LineList, | |
verts, | |
0, | |
8, | |
indices, | |
0, | |
indices.Length / 2); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
this is great stuff! it's gonna make my work flow much easier! thanks!