2019-04-10 19:36:10 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using OpenTK.Graphics.OpenGL;
|
|
|
|
|
using OpenTK;
|
|
|
|
|
|
2019-07-16 21:35:21 +00:00
|
|
|
|
namespace Toolbox.Library.Rendering
|
2019-04-10 19:36:10 +00:00
|
|
|
|
{
|
|
|
|
|
public class DrawableBoundingBox
|
|
|
|
|
{
|
|
|
|
|
public static List<Vector3> GetBoundingVertices(Vector3 Min, Vector3 Max)
|
|
|
|
|
{
|
|
|
|
|
var vertices = new List<Vector3>();
|
|
|
|
|
vertices.Add(new Vector3(Min.X, Min.Y, Min.Z));
|
|
|
|
|
vertices.Add(new Vector3(Min.X, Min.Y, Max.Z));
|
|
|
|
|
vertices.Add(new Vector3(Min.X, Max.Y, Min.Z));
|
|
|
|
|
vertices.Add(new Vector3(Min.X, Max.Y, Max.Z));
|
|
|
|
|
vertices.Add(new Vector3(Max.X, Min.Y, Min.Z));
|
|
|
|
|
vertices.Add(new Vector3(Max.X, Min.Y, Max.Z));
|
|
|
|
|
vertices.Add(new Vector3(Max.X, Max.Y, Min.Z));
|
|
|
|
|
vertices.Add(new Vector3(Max.X, Max.Y, Max.Z));
|
|
|
|
|
return vertices;
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-05 17:25:28 +00:00
|
|
|
|
public static Vector3[] points = new Vector3[]
|
|
|
|
|
{
|
|
|
|
|
new Vector3(-1,-1, 1),
|
|
|
|
|
new Vector3( 1,-1, 1),
|
|
|
|
|
new Vector3(-1, 1, 1),
|
|
|
|
|
new Vector3( 1, 1, 1),
|
|
|
|
|
new Vector3(-1,-1,-1),
|
|
|
|
|
new Vector3( 1,-1,-1),
|
|
|
|
|
new Vector3(-1, 1,-1),
|
|
|
|
|
new Vector3( 1, 1,-1)
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
public static void DrawBoundingBox(Matrix4 mvp, Vector3 Scale, Vector3 Position, System.Drawing.Color color)
|
|
|
|
|
{
|
|
|
|
|
GL.MatrixMode(MatrixMode.Modelview);
|
|
|
|
|
GL.LoadMatrix(ref mvp);
|
|
|
|
|
|
|
|
|
|
GL.Disable(EnableCap.CullFace);
|
|
|
|
|
GL.UseProgram(0);
|
|
|
|
|
|
|
|
|
|
GL.LineWidth(5);
|
|
|
|
|
GL.Color3(color);
|
|
|
|
|
GL.Begin(PrimitiveType.LineStrip);
|
|
|
|
|
GL.Vertex3(Position + points[6] * Scale);
|
|
|
|
|
GL.Vertex3(Position + points[2] * Scale);
|
|
|
|
|
GL.Vertex3(Position + points[3] * Scale);
|
|
|
|
|
GL.Vertex3(Position + points[7] * Scale);
|
|
|
|
|
GL.Vertex3(Position + points[6] * Scale);
|
|
|
|
|
|
|
|
|
|
GL.Vertex3(Position + points[4] * Scale);
|
|
|
|
|
GL.Vertex3(Position + points[5] * Scale);
|
|
|
|
|
GL.Vertex3(Position + points[1] * Scale);
|
|
|
|
|
GL.Vertex3(Position + points[0] * Scale);
|
|
|
|
|
GL.Vertex3(Position + points[4] * Scale);
|
|
|
|
|
GL.End();
|
|
|
|
|
|
|
|
|
|
GL.Begin(PrimitiveType.Lines);
|
|
|
|
|
GL.Color3(color);
|
|
|
|
|
GL.Vertex3(Position + points[2] * Scale);
|
|
|
|
|
GL.Vertex3(Position + points[0] * Scale);
|
|
|
|
|
GL.Vertex3(Position + points[3] * Scale);
|
|
|
|
|
GL.Vertex3(Position + points[1] * Scale);
|
|
|
|
|
GL.Vertex3(Position + points[7] * Scale);
|
|
|
|
|
GL.Vertex3(Position + points[5] * Scale);
|
|
|
|
|
GL.End();
|
|
|
|
|
|
|
|
|
|
GL.LineWidth(1);
|
|
|
|
|
GL.Enable(EnableCap.CullFace);
|
|
|
|
|
GL.UseProgram(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void DrawBoundingBox(Matrix4 mvp, Vector3 Min, Vector3 Max, Vector3 Position, System.Drawing.Color color)
|
2019-04-10 19:36:10 +00:00
|
|
|
|
{
|
2019-04-28 21:14:05 +00:00
|
|
|
|
GL.MatrixMode(MatrixMode.Modelview);
|
2019-10-05 17:25:28 +00:00
|
|
|
|
GL.LoadMatrix(ref mvp);
|
2019-04-28 21:14:05 +00:00
|
|
|
|
|
2019-10-05 17:25:28 +00:00
|
|
|
|
GL.Disable(EnableCap.CullFace);
|
|
|
|
|
GL.UseProgram(0);
|
2019-04-28 21:14:05 +00:00
|
|
|
|
|
2019-04-10 19:36:10 +00:00
|
|
|
|
var vertices = GetBoundingVertices(Min, Max);
|
|
|
|
|
|
2019-10-05 17:25:28 +00:00
|
|
|
|
GL.LineWidth(5);
|
2019-04-10 19:36:10 +00:00
|
|
|
|
GL.Begin(PrimitiveType.LineLoop);
|
2019-10-05 17:25:28 +00:00
|
|
|
|
GL.Color3(color);
|
2019-04-28 21:14:05 +00:00
|
|
|
|
GL.Vertex3(Position + vertices[0]);
|
|
|
|
|
GL.Vertex3(Position + vertices[1]);
|
|
|
|
|
GL.Vertex3(Position + vertices[3]);
|
|
|
|
|
GL.Vertex3(Position + vertices[2]);
|
2019-04-10 19:36:10 +00:00
|
|
|
|
GL.End();
|
|
|
|
|
|
|
|
|
|
GL.Begin(PrimitiveType.LineLoop);
|
2019-10-05 17:25:28 +00:00
|
|
|
|
GL.Color3(color);
|
2019-04-28 21:14:05 +00:00
|
|
|
|
GL.Vertex3(Position + vertices[4]);
|
|
|
|
|
GL.Vertex3(Position + vertices[5]);
|
|
|
|
|
GL.Vertex3(Position + vertices[7]);
|
|
|
|
|
GL.Vertex3(Position + vertices[6]);
|
2019-04-10 19:36:10 +00:00
|
|
|
|
GL.End();
|
|
|
|
|
|
|
|
|
|
GL.Begin(PrimitiveType.Lines);
|
2019-10-05 17:25:28 +00:00
|
|
|
|
GL.Color3(color);
|
2019-04-28 21:14:05 +00:00
|
|
|
|
GL.Vertex3(Position + vertices[0]);
|
|
|
|
|
GL.Vertex3(Position + vertices[4]);
|
|
|
|
|
GL.Vertex3(Position + vertices[1]);
|
|
|
|
|
GL.Vertex3(Position + vertices[5]);
|
|
|
|
|
GL.Vertex3(Position + vertices[3]);
|
|
|
|
|
GL.Vertex3(Position + vertices[7]);
|
|
|
|
|
GL.Vertex3(Position + vertices[2]);
|
|
|
|
|
GL.Vertex3(Position + vertices[6]);
|
2019-04-10 19:36:10 +00:00
|
|
|
|
GL.End();
|
2019-10-05 17:25:28 +00:00
|
|
|
|
|
|
|
|
|
GL.LineWidth(1);
|
|
|
|
|
GL.Enable(EnableCap.CullFace);
|
|
|
|
|
GL.UseProgram(0);
|
2019-04-10 19:36:10 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|