From 17f513d30f941b1138e05b53d4fa16a47cacdac9 Mon Sep 17 00:00:00 2001 From: bailwillharr Date: Mon, 16 Jan 2023 11:37:46 +0000 Subject: [PATCH] Add grass, fix sphere gen --- include/resources/material.hpp | 5 +-- src/resources/material.cpp | 3 +- test/src/game.cpp | 12 ++++--- test/src/meshgen.cpp | 66 ++++++++++++++++++---------------- 4 files changed, 48 insertions(+), 38 deletions(-) diff --git a/include/resources/material.hpp b/include/resources/material.hpp index 599d63a..5959faa 100644 --- a/include/resources/material.hpp +++ b/include/resources/material.hpp @@ -7,12 +7,13 @@ namespace engine::resources { class Shader; class Texture; + // copyable class Material { public: Material(std::shared_ptr shader); - ~Material(); - Material(const Material&) = delete; + ~Material() = default; + Material(const Material&); Material& operator=(const Material&) = delete; auto getShader() { return m_shader.get(); } diff --git a/src/resources/material.cpp b/src/resources/material.cpp index 6e8c0b6..8da996e 100644 --- a/src/resources/material.cpp +++ b/src/resources/material.cpp @@ -10,7 +10,8 @@ namespace engine::resources { } - Material::~Material() + Material::Material(const Material& original) + : m_texture(original.m_texture), m_shader(original.m_shader) { } diff --git a/test/src/game.cpp b/test/src/game.cpp index e43cd1c..66afffc 100644 --- a/test/src/game.cpp +++ b/test/src/game.cpp @@ -125,11 +125,15 @@ void playGame() lightRenderable->mesh = genSphereMesh(app.gfx(), 0.5f, 10, false, true); uint32_t floor = myScene->createEntity("floor"); -// myScene->getComponent(floor)->position = glm::vec3{-50.0f, -0.5f, -50.0f}; + myScene->getComponent(floor)->position = glm::vec3{-50.0f, -0.1f, -50.0f}; auto floorRenderable = myScene->addComponent(floor); - floorRenderable->material = sphereRenderable->material; - floorRenderable->mesh = genCuboidMesh(app.gfx(), 1.0f, 1.0f, 1.0f); - myScene->addComponent(floor); + floorRenderable->material = std::make_shared(*sphereRenderable->material); + auto grassTexture = std::make_unique( + app.gfx(), + app.getResourcePath("textures/grass.jpg") + ); + floorRenderable->material->m_texture = std::move(grassTexture); + floorRenderable->mesh = genCuboidMesh(app.gfx(), 100.0f, 0.1f, 100.0f); app.gameLoop(); diff --git a/test/src/meshgen.cpp b/test/src/meshgen.cpp index 57aae85..a3b7952 100644 --- a/test/src/meshgen.cpp +++ b/test/src/meshgen.cpp @@ -68,7 +68,6 @@ std::unique_ptr genSphereMesh(engine::GFXDevice* gfx, f vec3 vector2 = (vertices.end() - 2)->pos - (vertices.end() - 3)->pos; vec3 norm = normalize(cross(vector1, vector2)); - // TODO: FIX NORMALS if (!windInside) norm = -norm; @@ -76,6 +75,9 @@ std::unique_ptr genSphereMesh(engine::GFXDevice* gfx, f if (flipNormals) norm = -norm; + if (j == (detail / 2) - 1) + norm = -norm; + for (auto it = vertices.end() - 6; it != vertices.end(); it++) { it->norm = norm; } @@ -97,53 +99,55 @@ std::unique_ptr genCuboidMesh(engine::GFXDevice* gfx, f std::vector v{}; + const float tiling = 128.0f; + // front - v.push_back({{x, 0.0f, 0.0f}, {0.0f, 0.0f, -1.0f}, {0.0f, 0.0f}}); + v.push_back({{x, 0.0f, 0.0f}, {0.0f, 0.0f, -1.0f}, {tiling, 0.0f}}); v.push_back({{0.0f, 0.0f, 0.0f}, {0.0f, 0.0f, -1.0f}, {0.0f, 0.0f}}); - v.push_back({{0.0f, y, 0.0f}, {0.0f, 0.0f, -1.0f}, {0.0f, 0.0f}}); - v.push_back({{x, 0.0f, 0.0f}, {0.0f, 0.0f, -1.0f}, {0.0f, 0.0f}}); - v.push_back({{0.0f, y, 0.0f}, {0.0f, 0.0f, -1.0f}, {0.0f, 0.0f}}); - v.push_back({{x, y, 0.0f}, {0.0f, 0.0f, -1.0f}, {0.0f, 0.0f}}); + v.push_back({{0.0f, y, 0.0f}, {0.0f, 0.0f, -1.0f}, {0.0f, tiling}}); + v.push_back({{x, 0.0f, 0.0f}, {0.0f, 0.0f, -1.0f}, {tiling, 0.0f}}); + v.push_back({{0.0f, y, 0.0f}, {0.0f, 0.0f, -1.0f}, {0.0f, tiling}}); + v.push_back({{x, y, 0.0f}, {0.0f, 0.0f, -1.0f}, {tiling, tiling}}); // back v.push_back({{0.0f, 0.0f, z}, {0.0f, 0.0f, 1.0f}, {0.0f, 0.0f}}); - v.push_back({{x, 0.0f, z}, {0.0f, 0.0f, 1.0f}, {0.0f, 0.0f}}); - v.push_back({{0.0f, y, z}, {0.0f, 0.0f, 1.0f}, {0.0f, 0.0f}}); - v.push_back({{x, 0.0f, z}, {0.0f, 0.0f, 1.0f}, {0.0f, 0.0f}}); - v.push_back({{x, y, z}, {0.0f, 0.0f, 1.0f}, {0.0f, 0.0f}}); - v.push_back({{0.0f, y, z}, {0.0f, 0.0f, 1.0f}, {0.0f, 0.0f}}); + v.push_back({{x, 0.0f, z}, {0.0f, 0.0f, 1.0f}, {tiling, 0.0f}}); + v.push_back({{0.0f, y, z}, {0.0f, 0.0f, 1.0f}, {0.0f, tiling}}); + v.push_back({{x, 0.0f, z}, {0.0f, 0.0f, 1.0f}, {tiling, 0.0f}}); + v.push_back({{x, y, z}, {0.0f, 0.0f, 1.0f}, {tiling, tiling}}); + v.push_back({{0.0f, y, z}, {0.0f, 0.0f, 1.0f}, {0.0f, tiling}}); // left v.push_back({{0.0f, 0.0f, 0.0f}, {-1.0f, 0.0f, 0.0f}, {0.0f, 0.0f}}); - v.push_back({{0.0f, 0.0f, x}, {-1.0f, 0.0f, 0.0f}, {0.0f, 0.0f}}); - v.push_back({{0.0f, y, 0.0f}, {-1.0f, 0.0f, 0.0f}, {0.0f, 0.0f}}); - v.push_back({{0.0f, 0.0f, x}, {-1.0f, 0.0f, 0.0f}, {0.0f, 0.0f}}); - v.push_back({{0.0f, y, x}, {-1.0f, 0.0f, 0.0f}, {0.0f, 0.0f}}); - v.push_back({{0.0f, y, 0.0f}, {-1.0f, 0.0f, 0.0f}, {0.0f, 0.0f}}); + v.push_back({{0.0f, 0.0f, x}, {-1.0f, 0.0f, 0.0f}, {0.0f, tiling}}); + v.push_back({{0.0f, y, 0.0f}, {-1.0f, 0.0f, 0.0f}, {tiling, 0.0f}}); + v.push_back({{0.0f, 0.0f, x}, {-1.0f, 0.0f, 0.0f}, {0.0f, tiling}}); + v.push_back({{0.0f, y, x}, {-1.0f, 0.0f, 0.0f}, {tiling, tiling}}); + v.push_back({{0.0f, y, 0.0f}, {-1.0f, 0.0f, 0.0f}, {tiling, 0.0f}}); // right - v.push_back({{x, y, 0.0f}, {1.0f, 0.0f, 0.0f}, {0.0f, 0.0f}}); - v.push_back({{x, 0.0f, x}, {1.0f, 0.0f, 0.0f}, {0.0f, 0.0f}}); + v.push_back({{x, y, 0.0f}, {1.0f, 0.0f, 0.0f}, {tiling, 0.0f}}); + v.push_back({{x, 0.0f, x}, {1.0f, 0.0f, 0.0f}, {0.0f, tiling}}); v.push_back({{x, 0.0f, 0.0f}, {1.0f, 0.0f, 0.0f}, {0.0f, 0.0f}}); - v.push_back({{x, y, 0.0f}, {1.0f, 0.0f, 0.0f}, {0.0f, 0.0f}}); - v.push_back({{x, y, x}, {1.0f, 0.0f, 0.0f}, {0.0f, 0.0f}}); - v.push_back({{x, 0.0f, x}, {1.0f, 0.0f, 0.0f}, {0.0f, 0.0f}}); + v.push_back({{x, y, 0.0f}, {1.0f, 0.0f, 0.0f}, {tiling, 0.0f}}); + v.push_back({{x, y, x}, {1.0f, 0.0f, 0.0f}, {tiling, tiling}}); + v.push_back({{x, 0.0f, x}, {1.0f, 0.0f, 0.0f}, {0.0f, tiling}}); // bottom - v.push_back({{0.0f, 0.0f, z}, {0.0f, -1.0f, 0.0f}, {0.0f, 0.0f}}); + v.push_back({{0.0f, 0.0f, z}, {0.0f, -1.0f, 0.0f}, {0.0f, tiling}}); v.push_back({{0.0f, 0.0f, 0.0f}, {0.0f, -1.0f, 0.0f}, {0.0f, 0.0f}}); - v.push_back({{x, 0.0f, 0.0f}, {0.0f, -1.0f, 0.0f}, {0.0f, 0.0f}}); - v.push_back({{x, 0.0f, z}, {0.0f, -1.0f, 0.0f}, {0.0f, 0.0f}}); - v.push_back({{0.0f, 0.0f, z}, {0.0f, -1.0f, 0.0f}, {0.0f, 0.0f}}); - v.push_back({{x, 0.0f, 0.0f}, {0.0f, -1.0f, 0.0f}, {0.0f, 0.0f}}); + v.push_back({{x, 0.0f, 0.0f}, {0.0f, -1.0f, 0.0f}, {tiling, 0.0f}}); + v.push_back({{x, 0.0f, z}, {0.0f, -1.0f, 0.0f}, {tiling, tiling}}); + v.push_back({{0.0f, 0.0f, z}, {0.0f, -1.0f, 0.0f}, {0.0f, tiling}}); + v.push_back({{x, 0.0f, 0.0f}, {0.0f, -1.0f, 0.0f}, {tiling, 0.0f}}); // top - v.push_back({{x, y, 0.0f}, {0.0f, 1.0f, 0.0f}, {0.0f, 0.0f}}); + v.push_back({{x, y, 0.0f}, {0.0f, 1.0f, 0.0f}, {tiling, 0.0f}}); v.push_back({{0.0f, y, 0.0f}, {0.0f, 1.0f, 0.0f}, {0.0f, 0.0f}}); - v.push_back({{0.0f, y, z}, {0.0f, 1.0f, 0.0f}, {0.0f, 0.0f}}); - v.push_back({{x, y, 0.0f}, {0.0f, 1.0f, 0.0f}, {0.0f, 0.0f}}); - v.push_back({{0.0f, y, z}, {0.0f, 1.0f, 0.0f}, {0.0f, 0.0f}}); - v.push_back({{x, y, z}, {0.0f, 1.0f, 0.0f}, {0.0f, 0.0f}}); + v.push_back({{0.0f, y, z}, {0.0f, 1.0f, 0.0f}, {0.0f, tiling}}); + v.push_back({{x, y, 0.0f}, {0.0f, 1.0f, 0.0f}, {tiling, 0.0f}}); + v.push_back({{0.0f, y, z}, {0.0f, 1.0f, 0.0f}, {0.0f, tiling}}); + v.push_back({{x, y, z}, {0.0f, 1.0f, 0.0f}, {tiling, tiling}}); return std::make_unique(gfx, v);