-
Notifications
You must be signed in to change notification settings - Fork 44
/
DebugDraw.h
229 lines (178 loc) · 7.49 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
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
#ifndef Magnum_BulletIntegration_DebugDraw_h
#define Magnum_BulletIntegration_DebugDraw_h
/*
This file is part of Magnum.
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019,
2020, 2021 Vladimír Vondruš <mosra@centrum.cz>
Copyright © 2016 Jonathan Hale <squareys@googlemail.com>
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
*/
/** @file
* @brief Implementation of `btIDebugDraw` for physics visualization in Bullet
*/
#include <Corrade/Containers/Array.h>
#include <Corrade/Utility/Macros.h>
#include <LinearMath/btIDebugDraw.h>
#include <Magnum/GL/Buffer.h>
#include <Magnum/GL/Mesh.h>
#include <Magnum/Math/Matrix4.h>
#include <Magnum/Shaders/VertexColorGL.h>
#include "Magnum/BulletIntegration/Integration.h"
namespace Magnum { namespace BulletIntegration {
/**
@brief Bullet physics debug visualization
This class implements `btIDebugDraw`, which allows rendering a visualization
of a Bullet physics world for debugging purposes.
@section BulletIntegration-DebugDraw-usage Usage
Set up an instance and attach it to Bullet world:
@snippet BulletIntegration.cpp DebugDraw-usage
Then, at every frame, call this:
@snippet BulletIntegration.cpp DebugDraw-usage-per-frame
*/
class MAGNUM_BULLETINTEGRATION_EXPORT DebugDraw: public btIDebugDraw {
public:
/**
* @brief Debug mode
*
* @see @ref Modes, @ref setMode()
*/
enum class Mode: Int {
/** Disable debug rendering */
NoDebug = DBG_NoDebug,
/** Draw wireframe of all collision shapes */
DrawWireframe = DBG_DrawWireframe,
/** Draw axis aligned bounding box of all collision object */
DrawAabb = DBG_DrawAabb,
/** Draw text for features */
DrawFeaturesText = DBG_DrawFeaturesText,
/** Draw contact points */
DrawContactPoints = DBG_DrawContactPoints,
/** Disable deactivation of objects */
NoDeactivation = DBG_NoDeactivation,
/** Diable help text */
NoHelpText = DBG_NoHelpText,
/** Enable text drawing */
DrawText = DBG_DrawText,
/** Profile timings */
ProfileTimings = DBG_ProfileTimings,
/** Enable Sat Comparison */
EnableSatComparison = DBG_EnableSatComparison,
/** Disable Bullet LCP */
DisableBulletLCP = DBG_DisableBulletLCP,
/** Enable CCD */
EnableCCD = DBG_EnableCCD,
/** Draw constaints */
DrawConstraints = DBG_DrawConstraints,
/** Draw constraint limits */
DrawConstraintLimits = DBG_DrawConstraintLimits,
/** Draw fast wireframes */
FastWireframe = DBG_FastWireframe,
/** Draw normals */
DrawNormals = DBG_DrawNormals,
#if BT_BULLET_VERSION >= 284
/**
* Draw frames
*
* @note Supported since Bullet 2.83.5.
*/
DrawFrames = DBG_DrawFrames
#endif
};
/**
* @brief Debug modes
*
* @see @ref setMode()
*/
typedef Containers::EnumSet<Mode> Modes;
/**
* @brief Constructor
* @param initialBufferCapacity Amount of lines for which to
* reserve memory in the buffer vector.
*
* Sets up @ref Shaders::VertexColorGL3D, @ref GL::Buffer and
* @ref GL::Mesh for physics debug rendering.
*/
explicit DebugDraw(std::size_t initialBufferCapacity = 0);
/**
* @brief Construct without creating the underlying OpenGL objects
*
* The constructed instance is equivalent to moved-from state. Useful
* for deferring the initialization to a later point, for example if
* the OpenGL context is not yet created. Move another instance over it
* to make it useful.
*/
explicit DebugDraw(NoCreateT) noexcept;
/** @brief Move constructor */
DebugDraw(DebugDraw&&) noexcept;
/** @brief Copying is not allowed */
DebugDraw(const DebugDraw&) = delete;
~DebugDraw();
/** @brief Move assignment */
DebugDraw& operator=(DebugDraw&&) noexcept;
/** @brief Copying is not allowed */
DebugDraw& operator=(const DebugDraw&) = delete;
/** @brief Debug mode */
Modes mode() const { return _mode; }
#ifdef MAGNUM_BUILD_DEPRECATED
/** @brief @copybrief mode()
* @m_deprecated_since{2018,10} Use @ref mode() instead.
*/
CORRADE_DEPRECATED("use mode() instead") Modes debugMode() const {
return mode();
}
#endif
/**
* @brief Set debug mode
* @return Reference to self (for method chaining)
*
* By default, nothing is enabled.
*/
DebugDraw& setMode(Modes mode) {
_mode = mode;
return *this;
}
/** @brief Set transformation projection matrix used for rendering */
DebugDraw& setTransformationProjectionMatrix(const Matrix4& matrix) {
_transformationProjectionMatrix = matrix;
return *this;
}
private:
void setDebugMode(int debugMode) override;
int getDebugMode() const override;
void drawLine(const btVector3& from, const btVector3& to, const btVector3& color) override;
void drawLine(const btVector3& from, const btVector3& to, const btVector3& fromColor, const btVector3& toColor) override;
void drawContactPoint(const btVector3& pointOnB, const btVector3& normalOnB, btScalar distance, int lifeTime, const btVector3& color) override;
void reportErrorWarning(const char *warningString) override;
void draw3dText(const btVector3& location, const char* textString) override;
void flushLines()
/* See comment in drawLine() for detailed rant */
#if BT_BULLET_VERSION >= 284
override
#endif
;
Modes _mode{};
Matrix4 _transformationProjectionMatrix;
Shaders::VertexColorGL3D _shader;
GL::Buffer _buffer;
GL::Mesh _mesh;
Containers::Array<Vector3> _bufferData;
};
CORRADE_ENUMSET_OPERATORS(DebugDraw::Modes)
/** @debugoperatorenum{Magnum::BulletIntegration::DebugDraw::Mode} */
MAGNUM_BULLETINTEGRATION_EXPORT Debug& operator<<(Debug& debug, DebugDraw::Mode value);
}}
#endif