-
Notifications
You must be signed in to change notification settings - Fork 0
/
DrawableBoundingBox.cs
126 lines (111 loc) · 4.34 KB
/
DrawableBoundingBox.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using OpenTK.Graphics.OpenGL;
using OpenTK;
namespace CollisionGUI
{
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;
}
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.PushMatrix();
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);
GL.PopMatrix();
}
public static void DrawBoundingBox(Matrix4 mvp, Vector3 Min, Vector3 Max, Vector3 Position, System.Drawing.Color color)
{
GL.PushMatrix();
GL.MatrixMode(MatrixMode.Modelview);
GL.LoadMatrix(ref mvp);
GL.Disable(EnableCap.CullFace);
GL.UseProgram(0);
var vertices = GetBoundingVertices(Min, Max);
GL.LineWidth(5);
GL.Begin(PrimitiveType.LineLoop);
GL.Color3(color);
GL.Vertex3(Position + vertices[0]);
GL.Vertex3(Position + vertices[1]);
GL.Vertex3(Position + vertices[3]);
GL.Vertex3(Position + vertices[2]);
GL.End();
GL.Begin(PrimitiveType.LineLoop);
GL.Color3(color);
GL.Vertex3(Position + vertices[4]);
GL.Vertex3(Position + vertices[5]);
GL.Vertex3(Position + vertices[7]);
GL.Vertex3(Position + vertices[6]);
GL.End();
GL.Begin(PrimitiveType.Lines);
GL.Color3(color);
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]);
GL.End();
GL.LineWidth(1);
GL.Enable(EnableCap.CullFace);
GL.UseProgram(0);
GL.PopMatrix();
}
}
}