-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcollision-debug-drawer.hpp
More file actions
73 lines (56 loc) · 2.39 KB
/
Copy pathcollision-debug-drawer.hpp
File metadata and controls
73 lines (56 loc) · 2.39 KB
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
#pragma once
#ifdef COLLISION_DEBUG_DRAW
#include <LinearMath/btIDebugDraw.h>
#include <glad/gl.h>
#include <glm/glm.hpp>
#include <mesh/mesh.hpp>
#include <vector>
namespace gameplay {
class CollisionDebugDrawer : public btIDebugDraw {
public:
void initialize();
void destroy();
// Call after the main renderer finishes. Uploads the accumulated lines and draws them.
void render(const glm::mat4& VP);
// ---- Manual wireframe generators (used instead of Bullet's debugDrawObject) ----
void drawSphereWireframe(const glm::mat4& transform, float radius, const glm::vec3& color);
void drawCapsuleWireframe(const glm::mat4& transform, float radius, float totalHeight, const glm::vec3& color);
void drawMeshWireframe(our::Mesh* mesh, const glm::mat4& transform, const glm::vec3& color);
// ---- btIDebugDraw overrides (required by interface) ----
void drawLine(const btVector3& from, const btVector3& to, const btVector3& color) override;
void drawContactPoint(const btVector3&, const btVector3&, btScalar, int, const btVector3&) override {}
void reportErrorWarning(const char*) override {}
void draw3dText(const btVector3&, const char*) override {}
void setDebugMode(int mode) override {
debugMode = mode;
}
int getDebugMode() const override {
return debugMode;
}
private:
struct LineVertex {
float x, y, z; // position
float r, g, b; // color
};
std::vector<LineVertex> lineVertices;
struct MeshDrawCommand {
our::Mesh* mesh;
glm::mat4 transform;
glm::vec3 color;
};
std::vector<MeshDrawCommand> meshDrawCommands;
GLuint vao = 0;
GLuint vbo = 0;
GLuint shaderProgram = 0;
GLint vpUniformLoc = -1;
GLuint meshShaderProgram = 0;
GLint meshMVPUniformLoc = -1;
GLint meshColorUniformLoc = -1;
int debugMode = DBG_DrawWireframe;
void createShader();
void addLine(const glm::vec3& from, const glm::vec3& to, const glm::vec3& color);
void addCircle(const glm::vec3& center, const glm::vec3& axisA, const glm::vec3& axisB, float radius,
const glm::vec3& color, int segments = 32);
};
} // namespace gameplay
#endif // COLLISION_DEBUG_DRAW