Skip to content

Instantly share code, notes, and snippets.

@Jackzmc
Created April 8, 2023 20:31
Show Gist options
  • Save Jackzmc/b022ad593fc1c75d804cf6cb52bae458 to your computer and use it in GitHub Desktop.
Save Jackzmc/b022ad593fc1c75d804cf6cb52bae458 to your computer and use it in GitHub Desktop.
public static void DrawBoundingBoxFromCenter(Vector3 center, Vector3 size, Color color)
{
Vector3 cornerA = new Vector3(center.X - size.X, center.Y - size.Y, center.Z + size.Z);
Vector3 cornerB = new Vector3(center.X + size.X, center.Y - size.Y, center.Z + size.Z);
Vector3 cornerC = new Vector3(center.X + size.X, center.Y + size.Y, center.Z + size.Z);
Vector3 cornerD = new Vector3(center.X - size.X, center.Y + size.Y, center.Z + size.Z);
DrawLine(cornerA, cornerB, color);
DrawLine(cornerB, cornerC, color);
DrawLine(cornerC, cornerD, color);
DrawLine(cornerD, cornerA, color);
DrawSphere(cornerA, 0.1f, Color.White);
DrawSphere(cornerB, 0.1f, Color.Aqua);
DrawSphere(cornerC, 0.1f, Color.Red);
DrawSphere(cornerD, 0.1f, Color.Black);
Vector3 cornerE = new Vector3(center.X - size.X, center.Y - size.Y, center.Z - size.Z);
Vector3 cornerF = new Vector3(center.X + size.X, center.Y - size.Y, center.Z - size.Z);
Vector3 cornerG = new Vector3(center.X + size.X, center.Y + size.Y, center.Z - size.Z);
Vector3 cornerH = new Vector3(center.X - size.X, center.Y + size.Y, center.Z - size.Z);
DrawLine(cornerE, cornerF, color);
DrawLine(cornerF, cornerG, color);
DrawLine(cornerG, cornerH, color);
DrawLine(cornerH, cornerE, color);
// Connect vertical
DrawLine(cornerA, cornerE, color);
DrawLine(cornerB, cornerF, color);
DrawLine(cornerC, cornerG, color);
DrawLine(cornerD, cornerH, color);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment