Implemented debug draw for bullet.
This commit is contained in:
parent
4d6ee7093f
commit
ab6d2e4ffd
9
data/shader/debug.fsh
Normal file
9
data/shader/debug.fsh
Normal file
@ -0,0 +1,9 @@
|
||||
#version 150
|
||||
|
||||
in vec3 vColor;
|
||||
|
||||
out vec4 oColor;
|
||||
|
||||
void main() {
|
||||
oColor = vec4(vColor, 1.0);
|
||||
}
|
13
data/shader/debug.vsh
Normal file
13
data/shader/debug.vsh
Normal file
@ -0,0 +1,13 @@
|
||||
#version 150
|
||||
|
||||
uniform mat4 viewProjectionMatrix;
|
||||
|
||||
in vec3 aPosition;
|
||||
in vec3 aColor;
|
||||
|
||||
out vec3 vColor;
|
||||
|
||||
void main() {
|
||||
vColor = aColor;
|
||||
gl_Position = viewProjectionMatrix * vec4(aPosition, 1.0);
|
||||
}
|
64
game/debugDraw.cc
Normal file
64
game/debugDraw.cc
Normal file
@ -0,0 +1,64 @@
|
||||
#include "debugDraw.hh"
|
||||
|
||||
DebugDraw::DebugDraw() : debug_mode(0) {
|
||||
data = std::vector<float>();
|
||||
}
|
||||
|
||||
void DebugDraw::setDebugMode(int debugMode) {
|
||||
this->debug_mode = debugMode;
|
||||
}
|
||||
|
||||
int DebugDraw::getDebugMode() const {
|
||||
return debug_mode;
|
||||
}
|
||||
|
||||
std::vector<float>* DebugDraw::getData() {
|
||||
return &data;
|
||||
}
|
||||
|
||||
void DebugDraw::drawLine (const btVector3 &from, const btVector3 &to, const btVector3 &color) {
|
||||
data.push_back(from.getX());
|
||||
data.push_back(from.getY());
|
||||
data.push_back(from.getZ());
|
||||
data.push_back(color.getX());
|
||||
data.push_back(color.getY());
|
||||
data.push_back(color.getZ());
|
||||
data.push_back(to.getX());
|
||||
data.push_back(to.getY());
|
||||
data.push_back(to.getZ());
|
||||
data.push_back(color.getX());
|
||||
data.push_back(color.getY());
|
||||
data.push_back(color.getZ());
|
||||
}
|
||||
|
||||
void DebugDraw::drawLine (const btVector3 &from, const btVector3 &to, const btVector3 &fromColor,
|
||||
const btVector3 &toColor) {
|
||||
data.push_back(from.getX());
|
||||
data.push_back(from.getY());
|
||||
data.push_back(from.getZ());
|
||||
data.push_back(fromColor.getX());
|
||||
data.push_back(fromColor.getY());
|
||||
data.push_back(fromColor.getZ());
|
||||
data.push_back(to.getX());
|
||||
data.push_back(to.getY());
|
||||
data.push_back(to.getZ());
|
||||
data.push_back(toColor.getX());
|
||||
data.push_back(toColor.getY());
|
||||
data.push_back(toColor.getZ());
|
||||
}
|
||||
|
||||
|
||||
void DebugDraw::drawContactPoint (const btVector3 &PointOnB, const btVector3 &normalOnB,
|
||||
btScalar distance, int lifeTime, const btVector3 &color){
|
||||
}
|
||||
|
||||
void DebugDraw::reportErrorWarning (const char *warningString) {
|
||||
printf("%s\n", warningString);
|
||||
}
|
||||
|
||||
void DebugDraw::draw3dText (const btVector3 &location, const char *textString) {
|
||||
}
|
||||
|
||||
void DebugDraw::clearData() {
|
||||
this->data = std::vector<float>();
|
||||
}
|
25
game/debugDraw.hh
Normal file
25
game/debugDraw.hh
Normal file
@ -0,0 +1,25 @@
|
||||
#pragma once
|
||||
|
||||
#include "LinearMath/btIDebugDraw.h"
|
||||
#include <ACGL/OpenGL/Objects.hh>
|
||||
|
||||
class DebugDraw : public btIDebugDraw {
|
||||
int debug_mode;
|
||||
public:
|
||||
DebugDraw();
|
||||
void setDebugMode(int debugMode);
|
||||
int getDebugMode() const;
|
||||
std::vector<float>* getData();
|
||||
void drawLine (const btVector3 &from, const btVector3 &to, const btVector3 &color);
|
||||
void drawLine (const btVector3 &from, const btVector3 &to, const btVector3 &fromColor,
|
||||
const btVector3 &toColor);
|
||||
void reportErrorWarning (const char *warningString);
|
||||
void clearData();
|
||||
// the following functions don't do anything but are defined to
|
||||
// get the class not to be abstract
|
||||
void drawContactPoint (const btVector3 &PointOnB, const btVector3 &normalOnB,
|
||||
btScalar distance, int lifeTime, const btVector3 &color);
|
||||
void draw3dText (const btVector3 &location, const char *textString);
|
||||
private:
|
||||
std::vector<float> data;
|
||||
};
|
@ -6,6 +6,7 @@
|
||||
#include <functional>
|
||||
|
||||
#include <ACGL/OpenGL/Creator/ShaderProgramCreator.hh>
|
||||
#include "LinearMath/btIDebugDraw.h"
|
||||
|
||||
using namespace ACGL::OpenGL;
|
||||
|
||||
@ -27,6 +28,7 @@ Graphics::Graphics(glm::uvec2 windowSize, float nearPlane,
|
||||
gameStart = false;
|
||||
renderShadows = true;
|
||||
renderFlames = true;
|
||||
renderDebug = false;
|
||||
}
|
||||
|
||||
Graphics::Graphics() {
|
||||
@ -109,6 +111,20 @@ void Graphics::init(Level* level) {
|
||||
flamePostShader = ShaderProgramCreator("flame_post")
|
||||
.attributeLocations(fullscreen_quad->getAttributeLocations()).create();
|
||||
|
||||
debug_ab = SharedArrayBuffer(new ArrayBuffer());
|
||||
debug_ab->defineAttribute("aPosition", GL_FLOAT, 3);
|
||||
debug_ab->defineAttribute("aColor", GL_FLOAT, 3);
|
||||
debug_vao = SharedVertexArrayObject(new VertexArrayObject());
|
||||
debug_vao->attachAllAttributes(debug_ab);
|
||||
debug_vao->setMode(GL_LINES);
|
||||
|
||||
debugShader = ShaderProgramCreator("debug")
|
||||
.attributeLocations(debug_vao->getAttributeLocations()).create();
|
||||
|
||||
debugDrawer = DebugDraw();
|
||||
|
||||
level->getPhysics()->getWorld()->setDebugDrawer(&debugDrawer);
|
||||
|
||||
|
||||
depth_directionalMaps = std::vector<SharedTexture2D>(3);
|
||||
framebuffer_directional = std::vector<SharedFrameBufferObject>(3);
|
||||
@ -508,6 +524,21 @@ void Graphics::render(double time)
|
||||
glBlitFramebuffer(0, 0, windowSize.x, windowSize.y, 0, 0, windowSize.x, windowSize.y,
|
||||
GL_COLOR_BUFFER_BIT, GL_NEAREST);
|
||||
}
|
||||
if (renderDebug) {
|
||||
debugDrawer.setDebugMode(btIDebugDraw::DBG_DrawWireframe);
|
||||
level->getPhysics()->getWorld()->debugDrawWorld();
|
||||
debugDrawer.setDebugMode(btIDebugDraw::DBG_NoDebug);
|
||||
unsigned int data_count = debugDrawer.getData()->size();
|
||||
float* debugData = new float[data_count];
|
||||
for (unsigned int i = 0; i<data_count; i++) {
|
||||
debugData[i] = debugDrawer.getData()->at(i);
|
||||
}
|
||||
debug_ab->setDataElements(data_count/6, debugData);
|
||||
debugDrawer.clearData();
|
||||
debugShader->use();
|
||||
debugShader->setUniform("viewProjectionMatrix", lightingViewProjectionMatrix);
|
||||
debug_vao->render();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -662,3 +693,12 @@ bool Graphics::getRenderShadows() {
|
||||
bool Graphics::getRenderFlames() {
|
||||
return renderFlames;
|
||||
}
|
||||
|
||||
|
||||
void Graphics::setRenderDebug(bool state) {
|
||||
renderDebug = state;
|
||||
}
|
||||
|
||||
bool Graphics::getRenderDebug() {
|
||||
return renderDebug;
|
||||
}
|
||||
|
@ -7,6 +7,7 @@
|
||||
#include <ACGL/OpenGL/Objects/FrameBufferObject.hh>
|
||||
|
||||
#include "level.hh"
|
||||
#include "debugDraw.hh"
|
||||
|
||||
using namespace ACGL::OpenGL;
|
||||
|
||||
@ -26,8 +27,10 @@ class Graphics {
|
||||
void renderLoadingScreen();
|
||||
void setRenderShadows(bool state);
|
||||
void setRenderFlames(bool state);
|
||||
void setRenderDebug(bool state);
|
||||
bool getRenderShadows();
|
||||
bool getRenderFlames();
|
||||
bool getRenderDebug();
|
||||
private:
|
||||
void bindTextureUnits();
|
||||
void updateLights();
|
||||
@ -77,6 +80,12 @@ class Graphics {
|
||||
float loadingScreenHeight;
|
||||
bool renderShadows;
|
||||
bool renderFlames;
|
||||
bool renderDebug;
|
||||
DebugDraw debugDrawer;
|
||||
SharedArrayBuffer debug_ab;
|
||||
SharedVertexArrayObject debug_vao;
|
||||
SharedShaderProgram debugShader;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -29,6 +29,9 @@ static void keyCallback(GLFWwindow* _window, int _key, int, int _action, int)
|
||||
if (_key == GLFW_KEY_F6 && _action == GLFW_PRESS) {
|
||||
app.getGraphics()->setRenderFlames(!app.getGraphics()->getRenderFlames());
|
||||
}
|
||||
if (_key == GLFW_KEY_F7 && _action == GLFW_PRESS) {
|
||||
app.getGraphics()->setRenderDebug(!app.getGraphics()->getRenderDebug());
|
||||
}
|
||||
}
|
||||
|
||||
static void mouseCallback(GLFWwindow* window, int button, int action, int) {
|
||||
|
@ -710,3 +710,7 @@ void Physics::kill() //delete dynamically allocated memory
|
||||
|
||||
//feel like a good little programmer because everything is clean
|
||||
}
|
||||
|
||||
btDynamicsWorld* Physics::getWorld() {
|
||||
return world;
|
||||
}
|
||||
|
@ -79,6 +79,7 @@ class Physics {
|
||||
bool playerWithObject();
|
||||
void activateEndgame();
|
||||
void forcePlayer(glm::vec3 newPosition);
|
||||
btDynamicsWorld* getWorld();
|
||||
|
||||
struct positionConstraint{btRigidBody* body; float strength; btVector3 position;};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user