-
Notifications
You must be signed in to change notification settings - Fork 3
/
DebugDraw.h
101 lines (80 loc) · 3.57 KB
/
DebugDraw.h
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
#ifndef __DEBUGDRAW_H__
#define __DEBUGDRAW_H__
#include "MathGeoLib\include\MathGeoLib.h"
#include <list>
#include "Module.h"
struct DebugPrimitive
{
math::float3 color;
float line_width;
bool depth_enabled;
float life = 0; //Life = 0 means the Primitive only lasts one frame
math::float4x4 global_matrix = math::float4x4::identity;
unsigned int vertices_id;
unsigned int indices_id;
unsigned int num_indices;
};
class DebugDraw : public Module
{
public:
DebugDraw(const char* name, bool start_enabled = true);
~DebugDraw();
bool CleanUp();
bool Start();
update_status PreUpdate();
update_status PostUpdate();
void AddCross(const float3& point, math::float3 color, float size, float line_width = 1.0f, float duration = 0.0f, bool depth_enabled = true);
void AddLine(const math::float3& from_position, const math::float3& to_position, math::float3 color, float line_width = 1.0f, float duration = 0.0f, bool depth_enabled = true);
void AddAABB(const math::AABB& aabb, math::float3 color, float line_width = 1.0f, float duration = 0.0f, bool depth_enabled = true);
void AddAABB(const math::float3& min_point,const math::float3& max_point, math::float3 color, float line_width = 1.0f, float duration = 0.0f, bool depth_enabled = true);
void AddRect(const math::float3& center_point, const math::float3& normal, const math::float2 size, math::float3 color, float line_width = 1.0f, float duration = 0.0f, bool depth_enabled = true);
void AddFrustum(const math::Frustum& frustum, float fake_far_dst, math::float3 color, float line_width = 1.0f, float duration = 0.0f, bool depth_enabled = true);
void AddArrow2(const math::float3& from_position, const math::float3& to_position, math::float3 color, float line_width = 1.0f, float duration = 0.0f, bool depth_enabled = true);
void AddArrow(const math::float3& origin, const math::float3& direction, math::float3 color, float line_width = 1.0f, float duration = 0.0f, bool depth_enabled = true);
void AddOBB(const math::OBB& obb, math::float3 color, float size, float line_width = 1.0f, float duration = 0.0f, bool depth_enabled = true);
void Draw();
private:
//Removes the primitive from the list and returns the next element
std::list<DebugPrimitive*>::iterator RemovePrimitive(std::list<DebugPrimitive*>::iterator& it);
void FillCommonPrimitiveValues(DebugPrimitive* primitive, float3 color, float line_width, float duration, bool depth_enabled, unsigned int vertices_id, unsigned int indices_id, unsigned int num_indices);
void CreateBaseLine();
void CreateBaseCube();
void CreateBaseCross();
void CreateBaseRect();
void CreateBaseArrow();
public:
//Some colors to paint the primitives
math::float3 red = float3(1, 0, 0);
math::float3 blue = float3(0, 0, 1);
math::float3 green = float3(0, 1, 0);
math::float3 white = float3(0, 0, 0);
math::float3 black = float3(1, 1, 1);
math::float3 yellow = float3(1, 1, 0);
math::float3 orange = float3(1, 0.5f, 0);
math::float3 pink = float3(1, 0, 0.9f);
private:
std::list<DebugPrimitive*> draw_list;
//Base primitives ids
//Cube
unsigned int id_vertices_cube;
unsigned int id_indices_cube;
unsigned int num_indices_cube;
//Line
unsigned int id_vertices_line;
unsigned int id_indices_line;
unsigned int num_indices_line;
//Cross
unsigned int id_vertices_cross;
unsigned int id_indices_cross;
unsigned int num_indices_cross;
//Rect
unsigned int id_vertices_rect;
unsigned int id_indices_rect;
unsigned int num_indices_rect;
//Arrow
unsigned int id_vertices_arrow;
unsigned int id_indices_arrow;
unsigned int num_indices_arrow;
};
extern DebugDraw* g_Debug;
#endif // !__DEBUGDRAW_H__