Added some debug tools so I'm ready to start filling in the marching cube table.
This commit is contained in:
parent
01121fe526
commit
6a3b02dc9d
4 changed files with 57 additions and 26 deletions
|
|
@ -1 +1 @@
|
||||||
Subproject commit d1d1c195d789a9815e1585f29b74515b3fd32c72
|
Subproject commit a3ca0c28876aa1b92cd57abd77e7348aaa2ba56e
|
||||||
|
|
@ -18,7 +18,7 @@ void MarchingCubeChunkRenderer::draw(ShaderLoader &shader) {
|
||||||
for (int y = ti.yRange[0]; y < ti.yRange[1]; y++) {
|
for (int y = ti.yRange[0]; y < ti.yRange[1]; y++) {
|
||||||
for (int z = ti.zRange[0]; z < ti.zRange[1]; z++) {
|
for (int z = ti.zRange[0]; z < ti.zRange[1]; z++) {
|
||||||
if (chunk->getNoise(x, y, z) > 0.2f) {
|
if (chunk->getNoise(x, y, z) > 0.2f) {
|
||||||
this->genCubeModel(x, y, z, *chunk);
|
// this->genCubeModel(x, y, z, *chunk);
|
||||||
models.at(0)->setPosition(glm::vec3(x, y, z));
|
models.at(0)->setPosition(glm::vec3(x, y, z));
|
||||||
models.at(0)->draw(shader);
|
models.at(0)->draw(shader);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,15 @@
|
||||||
#include "Error.h"
|
#include "Error.h"
|
||||||
#include "Model.h"
|
#include "Model.h"
|
||||||
#include <glm/glm.hpp>
|
#include <glm/glm.hpp>
|
||||||
|
#include <map>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
// data required for rendring cube in right orientation.
|
||||||
|
struct CubeData {
|
||||||
|
glm::mat4 transform;
|
||||||
|
int modelID;
|
||||||
|
};
|
||||||
|
|
||||||
class MarchingCubeChunkRenderer {
|
class MarchingCubeChunkRenderer {
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
@ -21,6 +28,10 @@ private:
|
||||||
// https://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.545.613
|
// https://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.545.613
|
||||||
std::vector<Model *> models;
|
std::vector<Model *> models;
|
||||||
|
|
||||||
|
// this map will contain all combinations of cube data in order to render the
|
||||||
|
// right model with the right translations
|
||||||
|
std::map<int, CubeData> RenderMap;
|
||||||
|
|
||||||
// Determine Cubes Model and translation.
|
// Determine Cubes Model and translation.
|
||||||
Model *genCubeModel(int x, int y, int z, Chunk &chunk);
|
Model *genCubeModel(int x, int y, int z, Chunk &chunk);
|
||||||
|
|
||||||
|
|
|
||||||
68
src/main.cpp
68
src/main.cpp
|
|
@ -74,20 +74,6 @@ int main(int argc, char **argv) {
|
||||||
ROOT_DIR "data/shaders/fragment.glsl",
|
ROOT_DIR "data/shaders/fragment.glsl",
|
||||||
ROOT_DIR "data/shaders/geometry.glsl");
|
ROOT_DIR "data/shaders/geometry.glsl");
|
||||||
|
|
||||||
// Model backpack(std::string(ROOT_DIR) +
|
|
||||||
// std::string("data/models/backpack/backpack.obj"));
|
|
||||||
// Model cube(ROOT_DIR "data/models/cube/cube.obj");
|
|
||||||
// Model gun(ROOT_DIR "data/models/gun/Cerberus_LP.FBX");
|
|
||||||
// Model boxbarrel(ROOT_DIR
|
|
||||||
// "data/models/wooden_boxbarrel/wooden_box_and_barrel.obj");
|
|
||||||
// boxbarrel.translate(glm::vec3(0.0f, -1.0f, 0.0f));
|
|
||||||
// boxbarrel.setPosition(glm::vec3(0.0f, -1.0f, 0.0f));
|
|
||||||
// cube.translate(glm::vec3(3.0f, 0.0f, -1.0f));
|
|
||||||
// backpack.translate(glm::vec3(-3.0f, 0.0f, 0.0f));
|
|
||||||
// gun.translate(glm::vec3(0.0f, 1.0f, 0.0f));
|
|
||||||
// gun.resize(glm::vec3(0.02f, 0.02f, 0.02f));
|
|
||||||
// gun.rotate(glm::radians(-90.0f), glm::vec3(0.0f, 1.0f, 0.0f));
|
|
||||||
|
|
||||||
// Create player camera object
|
// Create player camera object
|
||||||
PlayerCamera camera;
|
PlayerCamera camera;
|
||||||
|
|
||||||
|
|
@ -100,6 +86,13 @@ int main(int argc, char **argv) {
|
||||||
// Initialise terrain.
|
// Initialise terrain.
|
||||||
Terrain terrain = Terrain();
|
Terrain terrain = Terrain();
|
||||||
|
|
||||||
|
// Debug MC table
|
||||||
|
Model debugSphere =
|
||||||
|
Model(ROOT_DIR "data/game-models/DebugSphere/DebugSphere.obj");
|
||||||
|
debugSphere.resize(glm::vec3(0.1f));
|
||||||
|
bool index[8] = {true, true, true, true, true, true, true, true};
|
||||||
|
Model debugMCsegment = Model(ROOT_DIR "data/game-models/1/MetalFloor.obj");
|
||||||
|
|
||||||
// Game loop
|
// Game loop
|
||||||
bool running = true;
|
bool running = true;
|
||||||
while (running) {
|
while (running) {
|
||||||
|
|
@ -124,24 +117,51 @@ int main(int argc, char **argv) {
|
||||||
|
|
||||||
// Clear screen ready for next loop
|
// Clear screen ready for next loop
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
// Make every shader/rendering call from this point on use our shader
|
|
||||||
// glUseProgram(shaderProgram);
|
|
||||||
|
|
||||||
// Send our glsl shader our camera information
|
// Send our glsl shader our camera information
|
||||||
shader.setMat4("MVP", camera.getMVP());
|
shader.setMat4("MVP", camera.getMVP());
|
||||||
|
|
||||||
shader.setVec3("CameraPos", camera.getCameraPosition());
|
shader.setVec3("CameraPos", camera.getCameraPosition());
|
||||||
// shader.setInt("tick", SDL_GetTicks());
|
|
||||||
// boxbarrel.rotate(0.001, glm::vec3(0, 1, 0));
|
|
||||||
|
|
||||||
terrain.draw(shader);
|
terrain.draw(shader);
|
||||||
|
|
||||||
// Draw Meshes
|
// draw debug sphere at correct config
|
||||||
// cube.draw(shader);
|
debugMCsegment.draw(shader);
|
||||||
// backpack.draw(shader);
|
debugSphere.setPosition(glm::vec3(0));
|
||||||
// gun.draw(shader);
|
debugSphere.draw(shader);
|
||||||
// boxbarrel.draw(shader);
|
if (index[0] == true) {
|
||||||
// Finally render everything
|
debugSphere.setPosition(glm::vec3(-1, -1, -1));
|
||||||
|
debugSphere.draw(shader);
|
||||||
|
}
|
||||||
|
if (index[1] == true) {
|
||||||
|
debugSphere.setPosition(glm::vec3(1, -1, -1));
|
||||||
|
debugSphere.draw(shader);
|
||||||
|
}
|
||||||
|
if (index[2] == true) {
|
||||||
|
debugSphere.setPosition(glm::vec3(1, 1, -1));
|
||||||
|
debugSphere.draw(shader);
|
||||||
|
}
|
||||||
|
if (index[3] == true) {
|
||||||
|
debugSphere.setPosition(glm::vec3(-1, 1, -1));
|
||||||
|
debugSphere.draw(shader);
|
||||||
|
}
|
||||||
|
if (index[4] == true) {
|
||||||
|
debugSphere.setPosition(glm::vec3(-1, -1, 1));
|
||||||
|
debugSphere.draw(shader);
|
||||||
|
}
|
||||||
|
if (index[5] == true) {
|
||||||
|
debugSphere.setPosition(glm::vec3(1, -1, 1));
|
||||||
|
debugSphere.draw(shader);
|
||||||
|
}
|
||||||
|
if (index[6] == true) {
|
||||||
|
debugSphere.setPosition(glm::vec3(1, 1, 1));
|
||||||
|
debugSphere.draw(shader);
|
||||||
|
}
|
||||||
|
if (index[7] == true) {
|
||||||
|
debugSphere.setPosition(glm::vec3(-1, 1, 1));
|
||||||
|
debugSphere.draw(shader);
|
||||||
|
}
|
||||||
|
|
||||||
shader.use();
|
shader.use();
|
||||||
|
|
||||||
SDL_GL_SwapWindow(window);
|
SDL_GL_SwapWindow(window);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue