Files
sbox-public/engine/Sandbox.Engine/Scene/GameObjectSystems/DebugOverlay/DebugOverlaySystem.DrawBox.cs
s&box team 71f266059a Open source release
This commit imports the C# engine code and game files, excluding C++ source code.

[Source-Commit: ceb3d758046e50faa6258bc3b658a30c97743268]
2025-11-24 09:05:18 +00:00

63 lines
2.4 KiB
C#

namespace Sandbox;
public partial class DebugOverlaySystem
{
/// <summary>
/// Draw a box
/// </summary>
public void Box( Vector3 position, Vector3 size, Color color = new Color(), float duration = 0, Transform transform = default, bool overlay = false )
=> Box( BBox.FromPositionAndSize( position, size ), color, duration, transform, overlay );
/// <summary>
/// Draw a box
/// </summary>
public void Box( BBox box, Color color = new Color(), float duration = 0, Transform transform = default, bool overlay = false )
{
if ( transform == default ) transform = Transform.Zero;
if ( color == default ) color = Color.White;
var c0 = new Vector3( box.Mins.x, box.Mins.y, box.Mins.z );
var c1 = new Vector3( box.Maxs.x, box.Mins.y, box.Mins.z );
var c2 = new Vector3( box.Maxs.x, box.Maxs.y, box.Mins.z );
var c3 = new Vector3( box.Mins.x, box.Maxs.y, box.Mins.z );
var c4 = new Vector3( box.Mins.x, box.Mins.y, box.Maxs.z );
var c5 = new Vector3( box.Maxs.x, box.Mins.y, box.Maxs.z );
var c6 = new Vector3( box.Maxs.x, box.Maxs.y, box.Maxs.z );
var c7 = new Vector3( box.Mins.x, box.Maxs.y, box.Maxs.z );
var so = new SceneDynamicObject( Scene.SceneWorld );
so.Transform = transform;
so.Material = LineMaterial;
so.Flags.CastShadows = false;
so.RenderLayer = overlay ? SceneRenderLayer.OverlayWithoutDepth : SceneRenderLayer.OverlayWithDepth;
so.Init( Graphics.PrimitiveType.Lines );
so.AddVertex( new Vertex( c0, color ) );
so.AddVertex( new Vertex( c1, color ) );
so.AddVertex( new Vertex( c1, color ) );
so.AddVertex( new Vertex( c2, color ) );
so.AddVertex( new Vertex( c2, color ) );
so.AddVertex( new Vertex( c3, color ) );
so.AddVertex( new Vertex( c3, color ) );
so.AddVertex( new Vertex( c0, color ) );
so.AddVertex( new Vertex( c0, color ) );
so.AddVertex( new Vertex( c4, color ) );
so.AddVertex( new Vertex( c1, color ) );
so.AddVertex( new Vertex( c5, color ) );
so.AddVertex( new Vertex( c2, color ) );
so.AddVertex( new Vertex( c6, color ) );
so.AddVertex( new Vertex( c3, color ) );
so.AddVertex( new Vertex( c7, color ) );
so.AddVertex( new Vertex( c4, color ) );
so.AddVertex( new Vertex( c5, color ) );
so.AddVertex( new Vertex( c5, color ) );
so.AddVertex( new Vertex( c6, color ) );
so.AddVertex( new Vertex( c6, color ) );
so.AddVertex( new Vertex( c7, color ) );
so.AddVertex( new Vertex( c7, color ) );
so.AddVertex( new Vertex( c4, color ) );
Add( duration, so );
}
}