started rewriting
This commit is contained in:
@@ -8,6 +8,7 @@ public:
|
|||||||
Camera(int w, int h);
|
Camera(int w, int h);
|
||||||
|
|
||||||
void UpdateView();
|
void UpdateView();
|
||||||
|
|
||||||
glm::mat4 GetViewMatrix();
|
glm::mat4 GetViewMatrix();
|
||||||
glm::mat4 GetProjectionMatrix();
|
glm::mat4 GetProjectionMatrix();
|
||||||
glm::vec3 GetPos();
|
glm::vec3 GetPos();
|
||||||
|
|||||||
@@ -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<glm::vec3>& verts, std::vector<glm::vec3>& uvs) {
|
|
||||||
|
|
||||||
verts = m_vertices;
|
|
||||||
|
|
||||||
std::vector<glm::vec3> UVs;
|
|
||||||
|
|
||||||
for (auto& uv : m_uvs) {
|
|
||||||
|
|
||||||
UVs.push_back({ uv.x, uv.y, (float)Texture });
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
uvs = UVs;
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -3,33 +3,112 @@
|
|||||||
|
|
||||||
#include "../common.hpp"
|
#include "../common.hpp"
|
||||||
|
|
||||||
class Camera;
|
std::vector<glm::vec3> CubeTopFace = {
|
||||||
class Shader;
|
{ -0.5f, 0.5f, -0.5f },
|
||||||
|
{ 0.5f, 0.5f, -0.5f },
|
||||||
enum FaceDirection {
|
{ 0.5f, 0.5f, 0.5f },
|
||||||
Top,
|
{ 0.5f, 0.5f, 0.5f },
|
||||||
Bottom,
|
{ -0.5f, 0.5f, 0.5f },
|
||||||
Front,
|
{ -0.5f, 0.5f, -0.5f }
|
||||||
Back,
|
|
||||||
Left,
|
|
||||||
Right
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class Face {
|
std::vector<glm::vec2> CubeTopFaceUVs = {
|
||||||
public:
|
{ 0.0f, 0.0f },
|
||||||
Face(FaceDirection direction, int textureID);
|
{ 1.0f, 0.0f },
|
||||||
|
{ 1.0f, 1.0f },
|
||||||
void GetMesh(std::vector<glm::vec3>& verts, std::vector<glm::vec3>& uvs);
|
{ 1.0f, 1.0f },
|
||||||
|
{ 0.0f, 1.0f },
|
||||||
|
{ 0.0f, 0.0f }
|
||||||
|
};
|
||||||
|
|
||||||
int Texture = 0;
|
std::vector<glm::vec3> 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<glm::vec2> 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<glm::vec3> 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<glm::vec3> m_vertices;
|
std::vector<glm::vec2> CubeFrontFaceUVs = {
|
||||||
std::vector<glm::vec2> 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 }
|
||||||
|
};
|
||||||
|
|
||||||
|
std::vector<glm::vec3> 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<glm::vec2> 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<glm::vec3> 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<glm::vec2> 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<glm::vec3> 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<glm::vec2> 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
|
#endif
|
||||||
|
|||||||
@@ -9,25 +9,25 @@
|
|||||||
Voxel::Voxel(int x, int y, int z) {
|
Voxel::Voxel(int x, int y, int z) {
|
||||||
|
|
||||||
// Texture winding order - top, bottom, left, right, front, back
|
// 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<glm::vec3> Vert;
|
//for (auto& face : Faces) {
|
||||||
std::vector<glm::vec3> UVs;
|
|
||||||
|
|
||||||
face.GetMesh(Vert, UVs);
|
// std::vector<glm::vec3> Vert;
|
||||||
|
// std::vector<glm::vec3> UVs;
|
||||||
m_vertices.insert(m_vertices.end(), Vert.begin(), Vert.end());
|
|
||||||
m_uvs.insert(m_uvs.end(), UVs.begin(), UVs.end());
|
|
||||||
|
|
||||||
}
|
// 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++) {
|
for (int i = 0; i < m_vertices.size(); i++) {
|
||||||
|
|
||||||
|
|||||||
@@ -14,8 +14,6 @@ public:
|
|||||||
|
|
||||||
void GetMesh(std::vector<glm::vec3>& verts, std::vector<glm::vec3>& uvs);
|
void GetMesh(std::vector<glm::vec3>& verts, std::vector<glm::vec3>& uvs);
|
||||||
|
|
||||||
std::vector<Face> Faces;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
std::vector<glm::vec3> m_vertices;
|
std::vector<glm::vec3> m_vertices;
|
||||||
|
|||||||
@@ -2,4 +2,25 @@
|
|||||||
|
|
||||||
#include "../config.hpp"
|
#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<uint16_t> faceTextures) {
|
||||||
|
|
||||||
|
CBlockEntry entry = { block, faceTextures };
|
||||||
|
|
||||||
|
BlockEntries[(uint8_t)block] = entry;
|
||||||
|
|
||||||
|
}
|
||||||
|
|||||||
@@ -3,13 +3,43 @@
|
|||||||
|
|
||||||
#include "../common.hpp"
|
#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 {
|
class CBlockEntry {
|
||||||
public:
|
public:
|
||||||
uint8_t ID;
|
uint8_t ID;
|
||||||
|
// Texture winding order - top, bottom, left, right, front, back
|
||||||
|
std::vector<uint16_t> FaceTextures;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// TODO: Make design of the class data oriented
|
// TODO: Make design of the class data oriented
|
||||||
|
// ie, import all the data used in the build from
|
||||||
|
// files and that
|
||||||
class CBlockDictionary {
|
class CBlockDictionary {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
@@ -26,8 +56,10 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
void registerTexture();
|
// Expects textures to be inserted in order, 0-...
|
||||||
void registerBlock();
|
void registerTexture(std::string texture);
|
||||||
|
|
||||||
|
void registerBlock(EBlockType::Block block, std::vector<uint16_t> faceTextures);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user