UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
DebugDraw.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2// Modified version of Recast/Detour's source file
3
4//
5// Copyright (c) 2009-2010 Mikko Mononen memon@inside.org
6//
7// This software is provided 'as-is', without any express or implied
8// warranty. In no event will the authors be held liable for any damages
9// arising from the use of this software.
10// Permission is granted to anyone to use this software for any purpose,
11// including commercial applications, and to alter it and redistribute it
12// freely, subject to the following restrictions:
13// 1. The origin of this software must not be misrepresented; you must not
14// claim that you wrote the original software. If you use this software
15// in a product, an acknowledgment in the product documentation would be
16// appreciated but is not required.
17// 2. Altered source versions must be plainly marked as such, and must not be
18// misrepresented as being the original software.
19// 3. This notice may not be removed or altered from any source distribution.
20//
21
22#ifndef DEBUGDRAW_H
23#define DEBUGDRAW_H
24
25#include "CoreMinimal.h"
27
28// Some math headers don't have PI defined.
29static const duReal DU_PI = 3.14159265358979323846;
30
31inline float duSin(float x)
32{
33 return sinf(x);
34}
35
36inline double duSin(double x)
37{
38 return sin(x);
39}
40
41inline float duCos(float x)
42{
43 return cosf(x);
44}
45
46inline double duCos(double x)
47{
48 return cos(x);
49}
50
51inline float duAbs(float x)
52{
53 return fabsf(x);
54}
55
56inline double duAbs(double x)
57{
58 return fabs(x);
59}
60
61inline float duSqrt(float x)
62{
63 return sqrtf(x);
64}
65
66inline double duSqrt(double x)
67{
68 return sqrt(x);
69}
70
78
81{
82 NAVMESH_API virtual ~duDebugDraw() = 0;
83
84 virtual void depthMask(bool state) = 0;
85
86 virtual void texture(bool state) = 0;
87
91 virtual void begin(duDebugDrawPrimitives prim, float size = 1.0f) = 0;
92
96 virtual void vertex(const duReal* pos, unsigned int color) = 0;
97//@UE BEGIN Adding support for LWCoords.
98#if !DU_LARGE_WORLD_COORDINATES_DISABLED
99 // float version of this function is now deprecated
100 virtual void vertex(const float* pos, unsigned int color) final {}
101#endif
102//@UE END
103
107 virtual void vertex(const duReal x, const duReal y, const duReal z, unsigned int color) = 0;
108//@UE BEGIN Adding support for LWCoords.
109#if !DU_LARGE_WORLD_COORDINATES_DISABLED
110 // float version of this function is now deprecated
111 virtual void vertex(const float x, const float y, const float z, unsigned int color) final {}
112#endif
113//@UE END
114
118 virtual void vertex(const duReal* pos, unsigned int color, const duReal* uv) = 0;
119//@UE BEGIN Adding support for LWCoords.
120#if !DU_LARGE_WORLD_COORDINATES_DISABLED
121 // float version of this function is now deprecated
122 virtual void vertex(const float* pos, unsigned int color, const float* uv) final {}
123#endif
124//@UE END
125
129 virtual void vertex(const duReal x, const duReal y, const duReal z, unsigned int color, const duReal u, const duReal v) = 0;
130//@UE BEGIN Adding support for LWCoords.
131#if !DU_LARGE_WORLD_COORDINATES_DISABLED
132 // float version of this function is now deprecated
133 virtual void vertex(const float x, const float y, const float z, unsigned int color, const float u, const float v) final {}
134#endif
135//@UE END
136
140 virtual void text(const duReal x, const duReal y, const duReal z, const char* text) = 0;
141//@UE BEGIN Adding support for LWCoords.
142#if !DU_LARGE_WORLD_COORDINATES_DISABLED
143 // float version of this function is now deprecated
144 virtual void text(const float x, const float y, const float z, const char* text) final {}
145#endif
146//@UE END
147
149 virtual void end() = 0;
150};
151
152// Reorder to handle the 0xRRGGBBAA format
153inline unsigned int duRGBA(unsigned int rgba)
154{
155 const unsigned int a = (rgba & 0x000000ff);
156 const unsigned int b = (rgba & 0x0000ff00);
157 const unsigned int g = (rgba & 0x00ff0000);
158 const unsigned int r = (rgba & 0xff000000);
159 return (r >> 24) | (g >> 8) | (b << 8) | a << 24;
160}
161
162inline unsigned int duRGBA(int r, int g, int b, int a)
163{
164 return ((unsigned int)r) | ((unsigned int)g << 8) | ((unsigned int)b << 16) | ((unsigned int)a << 24);
165}
166
167inline unsigned int duRGBAf(float fr, float fg, float fb, float fa)
168{
169 unsigned char r = (unsigned char)(fr*255.0f);
170 unsigned char g = (unsigned char)(fg*255.0f);
171 unsigned char b = (unsigned char)(fb*255.0f);
172 unsigned char a = (unsigned char)(fa*255.0f);
173 return duRGBA(r,g,b,a);
174}
175
176unsigned int duIntToCol(int i, int a);
177void duIntToCol(int i, float* col);
178
179inline unsigned int duMultCol(const unsigned int col, const unsigned int d)
180{
181 const unsigned int r = col & 0xff;
182 const unsigned int g = (col >> 8) & 0xff;
183 const unsigned int b = (col >> 16) & 0xff;
184 const unsigned int a = (col >> 24) & 0xff;
185 return duRGBA((r*d) >> 8, (g*d) >> 8, (b*d) >> 8, a);
186}
187
188inline unsigned int duDarkenCol(unsigned int col)
189{
190 return ((col >> 1) & 0x007f7f7f) | (col & 0xff000000);
191}
192
193inline unsigned int duLerpCol(unsigned int ca, unsigned int cb, unsigned int u)
194{
195 const unsigned int ra = ca & 0xff;
196 const unsigned int ga = (ca >> 8) & 0xff;
197 const unsigned int ba = (ca >> 16) & 0xff;
198 const unsigned int aa = (ca >> 24) & 0xff;
199 const unsigned int rb = cb & 0xff;
200 const unsigned int gb = (cb >> 8) & 0xff;
201 const unsigned int bb = (cb >> 16) & 0xff;
202 const unsigned int ab = (cb >> 24) & 0xff;
203
204 unsigned int r = (ra*(255-u) + rb*u)/255;
205 unsigned int g = (ga*(255-u) + gb*u)/255;
206 unsigned int b = (ba*(255-u) + bb*u)/255;
207 unsigned int a = (aa*(255-u) + ab*u)/255;
208 return duRGBA(r,g,b,a);
209}
210
211inline unsigned int duTransCol(unsigned int c, unsigned int a)
212{
213 return (a<<24) | (c & 0x00ffffff);
214}
215
216//@UE BEGIN
218{
219 // Color palette
220 static unsigned int red;
221 static unsigned int pink;
222 static unsigned int purple;
223 static unsigned int deepPurple;
224 static unsigned int indigo;
225 static unsigned int blue;
226 static unsigned int lightBlue;
227 static unsigned int cyan;
228 static unsigned int teal;
229 static unsigned int green;
230 static unsigned int lightGreen;
231 static unsigned int lime;
232 static unsigned int yellow;
233 static unsigned int amber;
234 static unsigned int orange;
235 static unsigned int orangeRed;
236 static unsigned int brown;
237
238 static unsigned int white;
239 static unsigned int lightGrey;
240 static unsigned int grey;
241 static unsigned int darkGrey;
242 static unsigned int black;
243};
244//@UE END
245
246void duCalcBoxColors(unsigned int* colors, unsigned int colTop, unsigned int colSide);
247
249 duReal maxx, duReal maxy, duReal maxz, unsigned int col, const float lineWidth);
250
251void duDebugDrawBoxWire(struct duDebugDraw* dd, duReal minx, duReal miny, duReal minz,
252 duReal maxx, duReal maxy, duReal maxz, unsigned int col, const float lineWidth);
253
254void duDebugDrawArc(struct duDebugDraw* dd, const duReal x0, const duReal y0, const duReal z0,
255 const duReal x1, const duReal y1, const duReal z1, const duReal h,
256 const duReal as0, const duReal as1, unsigned int col, const float lineWidth);
257
258void duDebugDrawArrow(struct duDebugDraw* dd, const duReal x0, const duReal y0, const duReal z0,
259 const duReal x1, const duReal y1, const duReal z1,
260 const duReal as0, const duReal as1, unsigned int col, const float lineWidth);
261
262void duDebugDrawCircle(struct duDebugDraw* dd, const duReal x, const duReal y, const duReal z,
263 const duReal r, unsigned int col, const float lineWidth);
264
265void duDebugDrawCross(struct duDebugDraw* dd, const duReal x, const duReal y, const duReal z,
266 const duReal size, unsigned int col, const float lineWidth);
267
268void duDebugDrawBox(struct duDebugDraw* dd, duReal minx, duReal miny, duReal minz,
269 duReal maxx, duReal maxy, duReal maxz, const unsigned int* fcol);
270
271void duDebugDrawCylinder(struct duDebugDraw* dd, duReal minx, duReal miny, duReal minz,
272 duReal maxx, duReal maxy, duReal maxz, unsigned int col);
273
274void duDebugDrawGridXZ(struct duDebugDraw* dd, const duReal ox, const duReal oy, const duReal oz,
275 const int w, const int h, const duReal size,
276 const unsigned int col, const float lineWidth);
277
278
279// Versions without begin/end, can be used to draw multiple primitives.
280void duAppendCylinderWire(struct duDebugDraw* dd, duReal minx, duReal miny, duReal minz,
281 duReal maxx, duReal maxy, duReal maxz, unsigned int col);
282
283void duAppendBoxWire(struct duDebugDraw* dd, duReal minx, duReal miny, duReal minz,
284 duReal maxx, duReal maxy, duReal maxz, unsigned int col);
285
286void duAppendBoxPoints(struct duDebugDraw* dd, duReal minx, duReal miny, duReal minz,
287 duReal maxx, duReal maxy, duReal maxz, unsigned int col);
288
289void duAppendArc(struct duDebugDraw* dd, const duReal x0, const duReal y0, const duReal z0,
290 const duReal x1, const duReal y1, const duReal z1, const duReal h,
291 const duReal as0, const duReal as1, unsigned int col);
292
293void duAppendArcSegment(struct duDebugDraw* dd, const duReal xA0, const duReal yA0, const duReal zA0,
294 const duReal xA1, const duReal yA1, const duReal zA1,
295 const duReal xB0, const duReal yB0, const duReal zB0,
296 const duReal xB1, const duReal yB1, const duReal zB1,
297 const duReal h, unsigned int col);
298
299void duAppendArrow(struct duDebugDraw* dd, const duReal x0, const duReal y0, const duReal z0,
300 const duReal x1, const duReal y1, const duReal z1,
301 const duReal as0, const duReal as1, unsigned int col);
302
303void duAppendCircle(struct duDebugDraw* dd, const duReal x, const duReal y, const duReal z,
304 const duReal r, unsigned int col);
305
306void duAppendCross(struct duDebugDraw* dd, const duReal x, const duReal y, const duReal z,
307 const duReal size, unsigned int col);
308
309void duAppendBox(struct duDebugDraw* dd, duReal minx, duReal miny, duReal minz,
310 duReal maxx, duReal maxy, duReal maxz, const unsigned int* fcol);
311
312void duAppendCylinder(struct duDebugDraw* dd, duReal minx, duReal miny, duReal minz,
313 duReal maxx, duReal maxy, duReal maxz, unsigned int col);
314
315
317{
318 duReal* m_pos;
319 unsigned int* m_color;
320 int m_size;
321 int m_cap;
322
323 bool m_depthMask;
325 float m_primSize;
326
327 void resize(int cap);
328
329public:
330 duDisplayList(int cap = 512);
331 virtual ~duDisplayList() override;
332 virtual void depthMask(bool state);
333 virtual void begin(duDebugDrawPrimitives prim, float size = 1.0f);
334 virtual void vertex(const duReal x, const duReal y, const duReal z, unsigned int color);
335 virtual void vertex(const duReal* pos, unsigned int color);
336 virtual void end();
337 void clear();
338 void draw(struct duDebugDraw* dd);
339};
340
341
342#endif // DEBUGDRAW_H
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
double duReal
Definition DebugDrawLargeWorldCoordinates.h:13
void duAppendArrow(struct duDebugDraw *dd, const duReal x0, const duReal y0, const duReal z0, const duReal x1, const duReal y1, const duReal z1, const duReal as0, const duReal as1, unsigned int col)
Definition DebugDraw.cpp:535
float duSin(float x)
Definition DebugDraw.h:31
void duAppendBox(struct duDebugDraw *dd, duReal minx, duReal miny, duReal minz, duReal maxx, duReal maxy, duReal maxz, const unsigned int *fcol)
Definition DebugDraw.cpp:296
void duAppendArc(struct duDebugDraw *dd, const duReal x0, const duReal y0, const duReal z0, const duReal x1, const duReal y1, const duReal z1, const duReal h, const duReal as0, const duReal as1, unsigned int col)
Definition DebugDraw.cpp:448
void duAppendArcSegment(struct duDebugDraw *dd, const duReal xA0, const duReal yA0, const duReal zA0, const duReal xA1, const duReal yA1, const duReal zA1, const duReal xB0, const duReal yB0, const duReal zB0, const duReal xB1, const duReal yB1, const duReal zB1, const duReal h, unsigned int col)
Definition DebugDraw.cpp:490
void duDebugDrawCylinderWire(struct duDebugDraw *dd, duReal minx, duReal miny, duReal minz, duReal maxx, duReal maxy, duReal maxz, unsigned int col, const float lineWidth)
Definition DebugDraw.cpp:95
void duDebugDrawCross(struct duDebugDraw *dd, const duReal x, const duReal y, const duReal z, const duReal size, unsigned int col, const float lineWidth)
Definition DebugDraw.cpp:147
float duAbs(float x)
Definition DebugDraw.h:51
unsigned int duIntToCol(int i, int a)
Definition DebugDraw.cpp:38
float duCos(float x)
Definition DebugDraw.h:41
void duAppendCylinder(struct duDebugDraw *dd, duReal minx, duReal miny, duReal minz, duReal maxx, duReal maxy, duReal maxz, unsigned int col)
Definition DebugDraw.cpp:331
void duDebugDrawArc(struct duDebugDraw *dd, const duReal x0, const duReal y0, const duReal z0, const duReal x1, const duReal y1, const duReal z1, const duReal h, const duReal as0, const duReal as1, unsigned int col, const float lineWidth)
Definition DebugDraw.cpp:115
void duAppendBoxPoints(struct duDebugDraw *dd, duReal minx, duReal miny, duReal minz, duReal maxx, duReal maxy, duReal maxz, unsigned int col)
Definition DebugDraw.cpp:271
void duAppendCross(struct duDebugDraw *dd, const duReal x, const duReal y, const duReal z, const duReal size, unsigned int col)
Definition DebugDraw.cpp:577
void duDebugDrawArrow(struct duDebugDraw *dd, const duReal x0, const duReal y0, const duReal z0, const duReal x1, const duReal y1, const duReal z1, const duReal as0, const duReal as1, unsigned int col, const float lineWidth)
Definition DebugDraw.cpp:126
void duAppendCircle(struct duDebugDraw *dd, const duReal x, const duReal y, const duReal z, const duReal r, unsigned int col)
Definition DebugDraw.cpp:552
void duDebugDrawCylinder(struct duDebugDraw *dd, duReal minx, duReal miny, duReal minz, duReal maxx, duReal maxy, duReal maxz, unsigned int col)
Definition DebugDraw.cpp:167
unsigned int duRGBAf(float fr, float fg, float fb, float fa)
Definition DebugDraw.h:167
unsigned int duDarkenCol(unsigned int col)
Definition DebugDraw.h:188
unsigned int duTransCol(unsigned int c, unsigned int a)
Definition DebugDraw.h:211
void duAppendBoxWire(struct duDebugDraw *dd, duReal minx, duReal miny, duReal minz, duReal maxx, duReal maxy, duReal maxz, unsigned int col)
Definition DebugDraw.cpp:236
void duDebugDrawGridXZ(struct duDebugDraw *dd, const duReal ox, const duReal oy, const duReal oz, const int w, const int h, const duReal size, const unsigned int col, const float lineWidth)
Definition DebugDraw.cpp:177
void duDebugDrawCircle(struct duDebugDraw *dd, const duReal x, const duReal y, const duReal z, const duReal r, unsigned int col, const float lineWidth)
Definition DebugDraw.cpp:137
void duDebugDrawBox(struct duDebugDraw *dd, duReal minx, duReal miny, duReal minz, duReal maxx, duReal maxy, duReal maxz, const unsigned int *fcol)
Definition DebugDraw.cpp:157
void duDebugDrawBoxWire(struct duDebugDraw *dd, duReal minx, duReal miny, duReal minz, duReal maxx, duReal maxy, duReal maxz, unsigned int col, const float lineWidth)
Definition DebugDraw.cpp:105
void duCalcBoxColors(unsigned int *colors, unsigned int colTop, unsigned int colSide)
Definition DebugDraw.cpp:83
void duAppendCylinderWire(struct duDebugDraw *dd, duReal minx, duReal miny, duReal minz, duReal maxx, duReal maxy, duReal maxz, unsigned int col)
Definition DebugDraw.cpp:198
duDebugDrawPrimitives
Definition DebugDraw.h:72
@ DU_DRAW_QUADS
Definition DebugDraw.h:76
@ DU_DRAW_LINES
Definition DebugDraw.h:74
@ DU_DRAW_TRIS
Definition DebugDraw.h:75
@ DU_DRAW_POINTS
Definition DebugDraw.h:73
float duSqrt(float x)
Definition DebugDraw.h:61
unsigned int duLerpCol(unsigned int ca, unsigned int cb, unsigned int u)
Definition DebugDraw.h:193
unsigned int duRGBA(unsigned int rgba)
Definition DebugDraw.h:153
unsigned int duMultCol(const unsigned int col, const unsigned int d)
Definition DebugDraw.h:179
Definition DebugDraw.h:317
virtual void depthMask(bool state)
Definition DebugDraw.cpp:631
virtual ~duDisplayList() override
Definition DebugDraw.cpp:603
void draw(struct duDebugDraw *dd)
Definition DebugDraw.cpp:664
void clear()
Definition DebugDraw.cpp:626
virtual void begin(duDebugDrawPrimitives prim, float size=1.0f)
Definition DebugDraw.cpp:636
virtual void end()
End drawing primitives.
Definition DebugDraw.cpp:660
virtual void vertex(const duReal x, const duReal y, const duReal z, unsigned int color)
Definition DebugDraw.cpp:643
float v
Definition radaudio_mdct.cpp:62
Definition DebugDraw.h:218
static unsigned int grey
Definition DebugDraw.h:240
static unsigned int pink
Definition DebugDraw.h:221
static unsigned int lime
Definition DebugDraw.h:231
static unsigned int black
Definition DebugDraw.h:242
static unsigned int brown
Definition DebugDraw.h:236
static unsigned int white
Definition DebugDraw.h:238
static unsigned int red
Definition DebugDraw.h:220
static unsigned int blue
Definition DebugDraw.h:225
static unsigned int amber
Definition DebugDraw.h:233
static unsigned int lightBlue
Definition DebugDraw.h:226
static unsigned int cyan
Definition DebugDraw.h:227
static unsigned int orange
Definition DebugDraw.h:234
static unsigned int teal
Definition DebugDraw.h:228
static unsigned int purple
Definition DebugDraw.h:222
static unsigned int green
Definition DebugDraw.h:229
static unsigned int lightGrey
Definition DebugDraw.h:239
static unsigned int lightGreen
Definition DebugDraw.h:230
static unsigned int orangeRed
Definition DebugDraw.h:235
static unsigned int deepPurple
Definition DebugDraw.h:223
static unsigned int darkGrey
Definition DebugDraw.h:241
static unsigned int yellow
Definition DebugDraw.h:232
static unsigned int indigo
Definition DebugDraw.h:224
Abstract debug draw interface.
Definition DebugDraw.h:81
virtual void vertex(const duReal x, const duReal y, const duReal z, unsigned int color, const duReal u, const duReal v)=0
virtual void vertex(const duReal *pos, unsigned int color, const duReal *uv)=0
virtual void vertex(const float *pos, unsigned int color) final
Definition DebugDraw.h:100
virtual void vertex(const duReal *pos, unsigned int color)=0
virtual void begin(duDebugDrawPrimitives prim, float size=1.0f)=0
virtual void text(const duReal x, const duReal y, const duReal z, const char *text)=0
virtual void vertex(const float x, const float y, const float z, unsigned int color, const float u, const float v) final
Definition DebugDraw.h:133
virtual void text(const float x, const float y, const float z, const char *text) final
Definition DebugDraw.h:144
virtual void depthMask(bool state)=0
virtual void end()=0
End drawing primitives.
virtual void vertex(const float *pos, unsigned int color, const float *uv) final
Definition DebugDraw.h:122
virtual void vertex(const float x, const float y, const float z, unsigned int color) final
Definition DebugDraw.h:111
virtual void vertex(const duReal x, const duReal y, const duReal z, unsigned int color)=0
virtual NAVMESH_API ~duDebugDraw()=0
Definition DebugDraw.cpp:27
virtual void texture(bool state)=0