F3: Toggle drawing bounding boxes

This commit is contained in:
2014-03-13 16:46:07 +01:00
parent 4905c17ebf
commit 235e9648ad
4 changed files with 38 additions and 19 deletions
+28 -19
View File
@@ -3,8 +3,15 @@
Renderer::Renderer()
{
m_VSync = false;
#ifdef DEBUG
m_DrawNormals = false;
m_DrawWireframe = false;
m_DrawBounds = true;
#else
m_DrawNormals = false;
m_DrawWireframe = false;
m_DrawBounds = false;
#endif
m_ShadowMapRes = 2048*2;
m_SunPosition = glm::vec3(0, 0.3f, 10);
@@ -131,27 +138,29 @@ void Renderer::Draw(double dt)
#ifdef DEBUG
// Draw bounding boxes
glEnable(GL_BLEND);
glBlendFunc(GL_ONE_MINUS_DST_COLOR, GL_ZERO);
m_ShaderProgramDebugAABB.Bind();
for (auto tuple : AABBsToRender) {
glm::mat4 modelMatrix;
bool colliding;
std::tie(modelMatrix, colliding) = tuple;
// Model matrix
glm::mat4 cameraMatrix = m_Camera->ProjectionMatrix() * m_Camera->ViewMatrix();
glm::mat4 MVP = cameraMatrix * modelMatrix;
glUniformMatrix4fv(glGetUniformLocation(m_ShaderProgramDebugAABB.GetHandle(), "MVP"), 1, GL_FALSE, glm::value_ptr(MVP));
// Color
glm::vec4 color(1.f, 1.f, 1.f, 0.f);
if (colliding)
color = glm::vec4(1.f, 0.f, 0.f, 0.f);
glUniform4fv(glGetUniformLocation(m_ShaderProgramDebugAABB.GetHandle(), "Color"), 1, glm::value_ptr(color));
glBindVertexArray(m_DebugAABB);
glDrawArrays(GL_LINES, 0, 24);
if (m_DrawBounds) {
glEnable(GL_BLEND);
glBlendFunc(GL_ONE_MINUS_DST_COLOR, GL_ZERO);
m_ShaderProgramDebugAABB.Bind();
for (auto tuple : AABBsToRender) {
glm::mat4 modelMatrix;
bool colliding;
std::tie(modelMatrix, colliding) = tuple;
// Model matrix
glm::mat4 cameraMatrix = m_Camera->ProjectionMatrix() * m_Camera->ViewMatrix();
glm::mat4 MVP = cameraMatrix * modelMatrix;
glUniformMatrix4fv(glGetUniformLocation(m_ShaderProgramDebugAABB.GetHandle(), "MVP"), 1, GL_FALSE, glm::value_ptr(MVP));
// Color
glm::vec4 color(1.f, 1.f, 1.f, 0.f);
if (colliding)
color = glm::vec4(1.f, 0.f, 0.f, 0.f);
glUniform4fv(glGetUniformLocation(m_ShaderProgramDebugAABB.GetHandle(), "Color"), 1, glm::value_ptr(color));
glBindVertexArray(m_DebugAABB);
glDrawArrays(GL_LINES, 0, 24);
}
}
DrawDebugShadowMap();
//DrawDebugShadowMap();
#endif
ClearStuff();
+3
View File
@@ -69,6 +69,8 @@ public:
void DrawNormals(bool val) { m_DrawNormals = val; }
bool DrawWireframe() const { return m_DrawWireframe; }
void DrawWireframe(bool val) { m_DrawWireframe = val; }
bool DrawBounds() const { return m_DrawBounds; }
void DrawBounds(bool val) { m_DrawBounds = val; }
private:
GLFWwindow* m_Window;
@@ -77,6 +79,7 @@ private:
bool m_VSync;
bool m_DrawNormals;
bool m_DrawWireframe;
bool m_DrawBounds;
int m_ShadowMapRes;
glm::vec3 m_SunPosition;
+4
View File
@@ -47,6 +47,10 @@ void Systems::InputSystem::Update(double dt)
if (m_CurrentKeyState[GLFW_KEY_F2] && !m_LastKeyState[GLFW_KEY_F2]) {
m_Renderer->DrawNormals(!m_Renderer->DrawNormals());
}
// Bounds
if (m_CurrentKeyState[GLFW_KEY_F3] && !m_LastKeyState[GLFW_KEY_F3]) {
m_Renderer->DrawBounds(!m_Renderer->DrawBounds());
}
#endif
}
+3
View File
@@ -77,6 +77,9 @@ void Systems::SoundSystem::UpdateEntity(double dt, EntityID entity, EntityID par
void Systems::SoundSystem::PlaySound(std::shared_ptr<Components::SoundEmitter> emitter, std::string fileName)
{
if (m_Sources.find(emitter.get()) == m_Sources.end())
return;
ALuint buffer = LoadFile(fileName);
ALuint source = m_Sources[emitter.get()];
alSourcei(source, AL_BUFFER, buffer);