Added basic debug lines
This commit is contained in:
@ -1,15 +1,19 @@
|
||||
# Copyright (c) 2022 Dominic Masters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
# Sources
|
||||
target_sources(${DAWN_TARGET_NAME}
|
||||
PRIVATE
|
||||
Scene.cpp
|
||||
SceneItem.cpp
|
||||
SceneItemComponent.cpp
|
||||
)
|
||||
|
||||
# Subdirs
|
||||
add_subdirectory(components)
|
||||
# Copyright (c) 2022 Dominic Masters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
# Sources
|
||||
target_sources(${DAWN_TARGET_NAME}
|
||||
PRIVATE
|
||||
Scene.cpp
|
||||
SceneItem.cpp
|
||||
SceneItemComponent.cpp
|
||||
)
|
||||
|
||||
# Subdirs
|
||||
add_subdirectory(components)
|
||||
|
||||
if(DAWN_DEBUG_BUILD)
|
||||
add_subdirectory(debug)
|
||||
endif()
|
@ -6,6 +6,7 @@
|
||||
#pragma once
|
||||
#include "event/Event.hpp"
|
||||
#include "asset/Asset.hpp"
|
||||
#include "scene/debug/SceneDebugLine.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
class DawnGame;
|
||||
@ -23,7 +24,7 @@ namespace Dawn {
|
||||
sceneitemid_t nextId;
|
||||
std::map<sceneitemid_t, SceneItem*> items;
|
||||
std::map<sceneitemid_t, SceneItem*> itemsNotInitialized;
|
||||
|
||||
|
||||
public:
|
||||
DawnGame *game;
|
||||
Event<> eventSceneUpdate;
|
||||
@ -130,6 +131,13 @@ namespace Dawn {
|
||||
return components;
|
||||
}
|
||||
|
||||
// Scene debugging functions
|
||||
#if DAWN_DEBUG_BUILD
|
||||
std::vector<struct SceneDebugLine> debugLines;
|
||||
void debugLine(struct SceneDebugLine line);
|
||||
void debugCube(struct SceneDebugCube cube);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Destroys a previously initialized Scene.
|
||||
*/
|
||||
|
10
src/dawn/scene/debug/CMakeLists.txt
Normal file
10
src/dawn/scene/debug/CMakeLists.txt
Normal file
@ -0,0 +1,10 @@
|
||||
# Copyright (c) 2023 Dominic Masters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
# Sources
|
||||
target_sources(${DAWN_TARGET_NAME}
|
||||
PRIVATE
|
||||
SceneDebugLine.cpp
|
||||
)
|
100
src/dawn/scene/debug/SceneDebugLine.cpp
Normal file
100
src/dawn/scene/debug/SceneDebugLine.cpp
Normal file
@ -0,0 +1,100 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "SceneDebugLine.hpp"
|
||||
#include "display/shader/SimpleTexturedShader.hpp"
|
||||
#include "scene/components/display/Camera.hpp"
|
||||
#include "scene/Scene.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
struct ShaderPassItem SceneDebugLine::createShaderItem(
|
||||
Mesh *mesh,
|
||||
int32_t *lineIndex,
|
||||
Camera *camera,
|
||||
SimpleTexturedShader *shader
|
||||
) {
|
||||
struct ShaderPassItem item;
|
||||
item.priority = SCENE_DEBUG_LINE_PRIORITY;
|
||||
|
||||
item.shaderProgram = &shader->program;
|
||||
item.colorValues[shader->program.paramColor] = this->color;
|
||||
item.matrixValues[shader->program.paramModel] = this->translation;
|
||||
item.matrixValues[shader->program.paramView] = camera->transform->getWorldTransform();
|
||||
item.matrixValues[shader->program.paramProjection] = camera->projection;
|
||||
item.boolValues[shader->program.paramHasTexture] = false;
|
||||
|
||||
item.renderFlags = 0x00;
|
||||
|
||||
auto i = *lineIndex;
|
||||
item.mesh = mesh;
|
||||
item.drawMode = MESH_DRAW_MODE_LINES;
|
||||
item.start = i * SCENE_DEBUG_LINE_INDICE_COUNT;
|
||||
item.count = SCENE_DEBUG_LINE_INDICE_COUNT;
|
||||
|
||||
glm::vec3 positions[SCENE_DEBUG_LINE_VERTICE_COUNT] = { this->v0, this->v1 };
|
||||
mesh->bufferPositions(
|
||||
i * SCENE_DEBUG_LINE_VERTICE_COUNT,
|
||||
positions,
|
||||
SCENE_DEBUG_LINE_VERTICE_COUNT
|
||||
);
|
||||
|
||||
meshindice_t indices[SCENE_DEBUG_LINE_INDICE_COUNT] = {
|
||||
i * SCENE_DEBUG_LINE_VERTICE_COUNT,
|
||||
(i*SCENE_DEBUG_LINE_VERTICE_COUNT) + 1
|
||||
};
|
||||
mesh->bufferIndices(
|
||||
i * SCENE_DEBUG_LINE_INDICE_COUNT,
|
||||
indices,
|
||||
SCENE_DEBUG_LINE_INDICE_COUNT
|
||||
);
|
||||
|
||||
(*lineIndex)++;
|
||||
return item;
|
||||
}
|
||||
|
||||
// Scene Implementations (done here to keep things cleaner in scene)
|
||||
void Scene::debugLine(struct SceneDebugLine line) {
|
||||
this->debugLines.push_back(line);
|
||||
}
|
||||
|
||||
void Scene::debugCube(struct SceneDebugCube cube) {
|
||||
auto min = cube.min;
|
||||
auto max = cube.max;
|
||||
|
||||
struct SceneDebugLine line;
|
||||
line.color = cube.color;
|
||||
line.translation = cube.translation;
|
||||
|
||||
// Bottom Face
|
||||
line.v0 = glm::vec3(min.x, min.y, min.z), line.v1 = glm::vec3(max.x, min.y, min.z);
|
||||
this->debugLine(line);
|
||||
line.v0 = glm::vec3(min.x, min.y, min.z), line.v1 = glm::vec3(min.x, min.y, max.z);
|
||||
this->debugLine(line);
|
||||
line.v0 = glm::vec3(max.x, min.y, min.z), line.v1 = glm::vec3(max.x, min.y, max.z);
|
||||
this->debugLine(line);
|
||||
line.v0 = glm::vec3(min.x, min.y, max.z), line.v1 = glm::vec3(max.x, min.y, max.z);
|
||||
this->debugLine(line);
|
||||
|
||||
// Top Face
|
||||
line.v0 = glm::vec3(min.x, max.y, min.z), line.v1 = glm::vec3(max.x, max.y, min.z);
|
||||
this->debugLine(line);
|
||||
line.v0 = glm::vec3(min.x, max.y, min.z), line.v1 = glm::vec3(min.x, max.y, max.z);
|
||||
this->debugLine(line);
|
||||
line.v0 = glm::vec3(max.x, max.y, min.z), line.v1 = glm::vec3(max.x, max.y, max.z);
|
||||
this->debugLine(line);
|
||||
line.v0 = glm::vec3(min.x, max.y, max.z), line.v1 = glm::vec3(max.x, max.y, max.z);
|
||||
this->debugLine(line);
|
||||
|
||||
// Rails
|
||||
line.v0 = glm::vec3(min.x, min.y, min.z), line.v1 = glm::vec3(min.x, max.y, min.z);
|
||||
this->debugLine(line);
|
||||
line.v0 = glm::vec3(max.x, min.y, min.z), line.v1 = glm::vec3(max.x, max.y, min.z);
|
||||
this->debugLine(line);
|
||||
line.v0 = glm::vec3(min.x, min.y, max.z), line.v1 = glm::vec3(min.x, max.y, max.z);
|
||||
this->debugLine(line);
|
||||
line.v0 = glm::vec3(max.x, min.y, max.z), line.v1 = glm::vec3(max.x, max.y, max.z);
|
||||
this->debugLine(line);
|
||||
}
|
48
src/dawn/scene/debug/SceneDebugLine.hpp
Normal file
48
src/dawn/scene/debug/SceneDebugLine.hpp
Normal file
@ -0,0 +1,48 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "display/Color.hpp"
|
||||
#include "display/mesh/Mesh.hpp"
|
||||
#include "display/shader/Shader.hpp"
|
||||
|
||||
#define SCENE_DEBUG_LINE_VERTICE_COUNT 2
|
||||
#define SCENE_DEBUG_LINE_INDICE_COUNT 2
|
||||
#define SCENE_DEBUG_LINE_PRIORITY 100
|
||||
|
||||
namespace Dawn {
|
||||
class SimpleTexturedShader;
|
||||
class Camera;
|
||||
|
||||
struct SceneDebugCube {
|
||||
glm::vec3 min;
|
||||
glm::vec3 max;
|
||||
struct Color color = COLOR_RED;
|
||||
glm::mat4 translation = glm::mat4(1.0f);
|
||||
};
|
||||
|
||||
struct SceneDebugLine {
|
||||
glm::vec3 v0 = glm::vec3(0, 0, 0);
|
||||
glm::vec3 v1 = glm::vec3(1, 1, 1);
|
||||
struct Color color = COLOR_RED;
|
||||
glm::mat4 translation = glm::mat4(1.0f);
|
||||
|
||||
/**
|
||||
* Creates a renderable shader item for this debug line.
|
||||
*
|
||||
* @param mesh Mesh that this debug line will buffer its indices in to
|
||||
* @param lineIndex Currently iterated line index.
|
||||
* @param camera Camera for this line index to set the shader params for.
|
||||
* @param shader Shader that the params will be set for.
|
||||
* @return The queueable shader pass item.
|
||||
*/
|
||||
struct ShaderPassItem createShaderItem(
|
||||
Mesh *mesh,
|
||||
int32_t *lineIndex,
|
||||
Camera *camera,
|
||||
SimpleTexturedShader *shader
|
||||
);
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user