diff --git a/src/renderer/camera.hpp b/src/renderer/camera.hpp index 4ca8147..f5131ed 100644 --- a/src/renderer/camera.hpp +++ b/src/renderer/camera.hpp @@ -8,6 +8,7 @@ public: Camera(int w, int h); void UpdateView(); + glm::mat4 GetViewMatrix(); glm::mat4 GetProjectionMatrix(); glm::vec3 GetPos(); diff --git a/src/renderer/face.cpp b/src/renderer/face.cpp deleted file mode 100644 index 5e0ca91..0000000 --- a/src/renderer/face.cpp +++ /dev/null @@ -1,122 +0,0 @@ -#include "face.hpp" - -#include "shader.hpp" -#include "camera.hpp" - -Face::Face(FaceDirection direction, int textureID) { - - Direction = direction; - Texture = textureID; - - m_uvs = { - { 0.0f, 0.0f }, - { 1.0f, 0.0f }, - { 1.0f, 1.0f }, - { 1.0f, 1.0f }, - { 0.0f, 1.0f }, - { 0.0f, 0.0f } - }; - - if (Direction == FaceDirection::Top) { - - m_vertices = { - { -0.5f, 0.5f, -0.5f }, - { 0.5f, 0.5f, -0.5f }, - { 0.5f, 0.5f, 0.5f }, - { 0.5f, 0.5f, 0.5f }, - { -0.5f, 0.5f, 0.5f }, - { -0.5f, 0.5f, -0.5f }, - }; - - } else if (Direction == FaceDirection::Bottom) { - - m_vertices = { - { -0.5f, -0.5f, -0.5f }, - { 0.5f, -0.5f, -0.5f }, - { 0.5f, -0.5f, 0.5f }, - { 0.5f, -0.5f, 0.5f }, - { -0.5f, -0.5f, 0.5f }, - { -0.5f, -0.5f, -0.5f }, - }; - - } else if (Direction == FaceDirection::Front) { - - m_vertices = { - { -0.5f, -0.5f, 0.5f }, - { 0.5f, -0.5f, 0.5f }, - { 0.5f, 0.5f, 0.5f }, - { 0.5f, 0.5f, 0.5f }, - { -0.5f, 0.5f, 0.5f }, - { -0.5f, -0.5f, 0.5f }, - }; - - m_uvs = { - { 1.0f, 1.0f }, - { 0.0f, 1.0f }, - { 0.0f, 0.0f }, - { 0.0f, 0.0f }, - { 1.0f, 0.0f }, - { 1.0f, 1.0f }, - }; - - } else if (Direction == FaceDirection::Back) { - - m_vertices = { - { -0.5f, -0.5f, -0.5f }, - { 0.5f, -0.5f, -0.5f }, - { 0.5f, 0.5f, -0.5f }, - { 0.5f, 0.5f, -0.5f }, - { -0.5f, 0.5f, -0.5f }, - { -0.5f, -0.5f, -0.5f }, - }; - - m_uvs = { - { 1.0f, 1.0f }, - { 0.0f, 1.0f }, - { 0.0f, 0.0f }, - { 0.0f, 0.0f }, - { 1.0f, 0.0f }, - { 1.0f, 1.0f }, - }; - - } else if (Direction == FaceDirection::Left) { - - m_vertices = { - { -0.5f, 0.5f, 0.5f }, - { -0.5f, 0.5f, -0.5f }, - { -0.5f, -0.5f, -0.5f }, - { -0.5f, -0.5f, -0.5f }, - { -0.5f, -0.5f, 0.5f }, - { -0.5f, 0.5f, 0.5f }, - }; - - } else if (Direction == FaceDirection::Right) { - - m_vertices = { - { 0.5f, 0.5f, 0.5f }, - { 0.5f, 0.5f, -0.5f }, - { 0.5f, -0.5f, -0.5f }, - { 0.5f, -0.5f, -0.5f }, - { 0.5f, -0.5f, 0.5f }, - { 0.5f, 0.5f, 0.5f }, - }; - - } - -} - -void Face::GetMesh(std::vector& verts, std::vector& uvs) { - - verts = m_vertices; - - std::vector UVs; - - for (auto& uv : m_uvs) { - - UVs.push_back({ uv.x, uv.y, (float)Texture }); - - } - - uvs = UVs; - -} diff --git a/src/renderer/face.hpp b/src/renderer/face.hpp index 9c2500d..fa4fb6d 100644 --- a/src/renderer/face.hpp +++ b/src/renderer/face.hpp @@ -3,33 +3,112 @@ #include "../common.hpp" -class Camera; -class Shader; - -enum FaceDirection { - Top, - Bottom, - Front, - Back, - Left, - Right +std::vector CubeTopFace = { + { -0.5f, 0.5f, -0.5f }, + { 0.5f, 0.5f, -0.5f }, + { 0.5f, 0.5f, 0.5f }, + { 0.5f, 0.5f, 0.5f }, + { -0.5f, 0.5f, 0.5f }, + { -0.5f, 0.5f, -0.5f } }; -class Face { -public: - Face(FaceDirection direction, int textureID); - - void GetMesh(std::vector& verts, std::vector& uvs); +std::vector CubeTopFaceUVs = { + { 0.0f, 0.0f }, + { 1.0f, 0.0f }, + { 1.0f, 1.0f }, + { 1.0f, 1.0f }, + { 0.0f, 1.0f }, + { 0.0f, 0.0f } +}; - int Texture = 0; +std::vector CubeBottomFace = { + { -0.5f, -0.5f, -0.5f }, + { 0.5f, -0.5f, -0.5f }, + { 0.5f, -0.5f, 0.5f }, + { 0.5f, -0.5f, 0.5f }, + { -0.5f, -0.5f, 0.5f }, + { -0.5f, -0.5f, -0.5f } +}; - FaceDirection Direction = FaceDirection::Top; +std::vector CubeBottomFaceUVs = { + { 0.0f, 0.0f }, + { 1.0f, 0.0f }, + { 1.0f, 1.0f }, + { 1.0f, 1.0f }, + { 0.0f, 1.0f }, + { 0.0f, 0.0f } +}; -private: +std::vector CubeFrontFace = { + { -0.5f, -0.5f, 0.5f }, + { 0.5f, -0.5f, 0.5f }, + { 0.5f, 0.5f, 0.5f }, + { 0.5f, 0.5f, 0.5f }, + { -0.5f, 0.5f, 0.5f }, + { -0.5f, -0.5f, 0.5f } +}; - std::vector m_vertices; - std::vector m_uvs; +std::vector CubeFrontFaceUVs = { + { 1.0f, 1.0f }, + { 0.0f, 1.0f }, + { 0.0f, 0.0f }, + { 0.0f, 0.0f }, + { 1.0f, 0.0f }, + { 1.0f, 1.0f } +}; +std::vector CubeBackFace = { + { -0.5f, -0.5f, -0.5f }, + { 0.5f, -0.5f, -0.5f }, + { 0.5f, 0.5f, -0.5f }, + { 0.5f, 0.5f, -0.5f }, + { -0.5f, 0.5f, -0.5f }, + { -0.5f, -0.5f, -0.5f } +}; + +std::vector CubeBackFaceUVs = { + { 1.0f, 1.0f }, + { 0.0f, 1.0f }, + { 0.0f, 0.0f }, + { 0.0f, 0.0f }, + { 1.0f, 0.0f }, + { 1.0f, 1.0f } +}; + +std::vector CubeLeftFace = { + { -0.5f, 0.5f, 0.5f }, + { -0.5f, 0.5f, -0.5f }, + { -0.5f, -0.5f, -0.5f }, + { -0.5f, -0.5f, -0.5f }, + { -0.5f, -0.5f, 0.5f }, + { -0.5f, 0.5f, 0.5f } +}; + +std::vector CubeLeftFaceUVs = { + { 0.0f, 0.0f }, + { 1.0f, 0.0f }, + { 1.0f, 1.0f }, + { 1.0f, 1.0f }, + { 0.0f, 1.0f }, + { 0.0f, 0.0f } +}; + +std::vector CubeRightFace = { + { 0.5f, 0.5f, 0.5f }, + { 0.5f, 0.5f, -0.5f }, + { 0.5f, -0.5f, -0.5f }, + { 0.5f, -0.5f, -0.5f }, + { 0.5f, -0.5f, 0.5f }, + { 0.5f, 0.5f, 0.5f }, +}; + +std::vector CubeRightFaceUVs = { + { 0.0f, 0.0f }, + { 1.0f, 0.0f }, + { 1.0f, 1.0f }, + { 1.0f, 1.0f }, + { 0.0f, 1.0f }, + { 0.0f, 0.0f } }; #endif diff --git a/src/renderer/voxel.cpp b/src/renderer/voxel.cpp index 0f74183..6583625 100644 --- a/src/renderer/voxel.cpp +++ b/src/renderer/voxel.cpp @@ -9,25 +9,25 @@ Voxel::Voxel(int x, int y, int z) { // Texture winding order - top, bottom, left, right, front, back - - Faces.push_back(Face((FaceDirection)0, 2)); - Faces.push_back(Face((FaceDirection)1, 0)); - Faces.push_back(Face((FaceDirection)2, 1)); - Faces.push_back(Face((FaceDirection)3, 1)); - Faces.push_back(Face((FaceDirection)4, 1)); - Faces.push_back(Face((FaceDirection)5, 1)); - for (auto& face : Faces) { + //Faces.push_back(Face((FaceDirection)0, 2)); + //Faces.push_back(Face((FaceDirection)1, 0)); + //Faces.push_back(Face((FaceDirection)2, 1)); + //Faces.push_back(Face((FaceDirection)3, 1)); + //Faces.push_back(Face((FaceDirection)4, 1)); + //Faces.push_back(Face((FaceDirection)5, 1)); - std::vector Vert; - std::vector UVs; + //for (auto& face : Faces) { - face.GetMesh(Vert, UVs); - - m_vertices.insert(m_vertices.end(), Vert.begin(), Vert.end()); - m_uvs.insert(m_uvs.end(), UVs.begin(), UVs.end()); + // std::vector Vert; + // std::vector UVs; - } + // face.GetMesh(Vert, UVs); + // + // m_vertices.insert(m_vertices.end(), Vert.begin(), Vert.end()); + // m_uvs.insert(m_uvs.end(), UVs.begin(), UVs.end()); + + //} for (int i = 0; i < m_vertices.size(); i++) { diff --git a/src/renderer/voxel.hpp b/src/renderer/voxel.hpp index e64dac0..df3beec 100644 --- a/src/renderer/voxel.hpp +++ b/src/renderer/voxel.hpp @@ -14,8 +14,6 @@ public: void GetMesh(std::vector& verts, std::vector& uvs); - std::vector Faces; - private: std::vector m_vertices; diff --git a/src/world/block.cpp b/src/world/block.cpp index cbbcb27..d4d55da 100644 --- a/src/world/block.cpp +++ b/src/world/block.cpp @@ -2,4 +2,25 @@ #include "../config.hpp" -// Texture winding order - top, bottom, left, right, front, back +void CBlockDictionary::Build() { + + // Texture winding order - top, bottom, left, right, front, back + registerBlock(EBlockType::Air, { }); + registerBlock(EBlockType::Dirt, { EFaceTexture::Dirt, EFaceTexture::Dirt, FaceTexture::Dirt, EFaceTexture::Dirt, EFaceTexture::Dirt, EFaceTexture::Dirt }); + registerBlock(EBlockType::Grass, { EFaceTexture::Grass, EFaceTexture::Dirt, EFaceTexture::GrassSide, EFaceTexture::GrassSide, EFaceTexture::GrassSide, EFaceTexture::GrassSide }); + +} + +void CBlockDictionary::registerTexture(std::string texture) { + + Textures.push_back(texture); + +} + +void CBlockDictionary::registerBlock(EBlockType::Block block, std::vector faceTextures) { + + CBlockEntry entry = { block, faceTextures }; + + BlockEntries[(uint8_t)block] = entry; + +} diff --git a/src/world/block.hpp b/src/world/block.hpp index 767aa9a..56b02e8 100644 --- a/src/world/block.hpp +++ b/src/world/block.hpp @@ -3,13 +3,43 @@ #include "../common.hpp" + +namespace EBlockType { + + enum Block : uint8_t { + + Air = 0, + Dirt, + Grass + + }; + +} + +namespace EFaceTexture { + + enum Texture : uint16_t { + + Air = 0, + Dirt, + GrassSide, + Grass + + }; + +} + class CBlockEntry { public: uint8_t ID; + // Texture winding order - top, bottom, left, right, front, back + std::vector FaceTextures; }; // TODO: Make design of the class data oriented +// ie, import all the data used in the build from +// files and that class CBlockDictionary { public: @@ -26,8 +56,10 @@ public: private: - void registerTexture(); - void registerBlock(); + // Expects textures to be inserted in order, 0-... + void registerTexture(std::string texture); + + void registerBlock(EBlockType::Block block, std::vector faceTextures); };