Add grass, fix sphere gen

This commit is contained in:
Bailey Harrison 2023-01-16 11:37:46 +00:00
parent 16a522ea92
commit 17f513d30f
4 changed files with 48 additions and 38 deletions

View File

@ -7,12 +7,13 @@ namespace engine::resources {
class Shader; class Shader;
class Texture; class Texture;
// copyable
class Material { class Material {
public: public:
Material(std::shared_ptr<Shader> shader); Material(std::shared_ptr<Shader> shader);
~Material(); ~Material() = default;
Material(const Material&) = delete; Material(const Material&);
Material& operator=(const Material&) = delete; Material& operator=(const Material&) = delete;
auto getShader() { return m_shader.get(); } auto getShader() { return m_shader.get(); }

View File

@ -10,7 +10,8 @@ namespace engine::resources {
} }
Material::~Material() Material::Material(const Material& original)
: m_texture(original.m_texture), m_shader(original.m_shader)
{ {
} }

View File

@ -125,11 +125,15 @@ void playGame()
lightRenderable->mesh = genSphereMesh(app.gfx(), 0.5f, 10, false, true); lightRenderable->mesh = genSphereMesh(app.gfx(), 0.5f, 10, false, true);
uint32_t floor = myScene->createEntity("floor"); uint32_t floor = myScene->createEntity("floor");
// myScene->getComponent<engine::TransformComponent>(floor)->position = glm::vec3{-50.0f, -0.5f, -50.0f}; myScene->getComponent<engine::TransformComponent>(floor)->position = glm::vec3{-50.0f, -0.1f, -50.0f};
auto floorRenderable = myScene->addComponent<engine::RenderableComponent>(floor); auto floorRenderable = myScene->addComponent<engine::RenderableComponent>(floor);
floorRenderable->material = sphereRenderable->material; floorRenderable->material = std::make_shared<engine::resources::Material>(*sphereRenderable->material);
floorRenderable->mesh = genCuboidMesh(app.gfx(), 1.0f, 1.0f, 1.0f); auto grassTexture = std::make_unique<engine::resources::Texture>(
myScene->addComponent<RotateComponent>(floor); 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(); app.gameLoop();

View File

@ -68,7 +68,6 @@ std::unique_ptr<engine::resources::Mesh> genSphereMesh(engine::GFXDevice* gfx, f
vec3 vector2 = (vertices.end() - 2)->pos - (vertices.end() - 3)->pos; vec3 vector2 = (vertices.end() - 2)->pos - (vertices.end() - 3)->pos;
vec3 norm = normalize(cross(vector1, vector2)); vec3 norm = normalize(cross(vector1, vector2));
// TODO: FIX NORMALS // TODO: FIX NORMALS
if (!windInside) if (!windInside)
norm = -norm; norm = -norm;
@ -76,6 +75,9 @@ std::unique_ptr<engine::resources::Mesh> genSphereMesh(engine::GFXDevice* gfx, f
if (flipNormals) if (flipNormals)
norm = -norm; norm = -norm;
if (j == (detail / 2) - 1)
norm = -norm;
for (auto it = vertices.end() - 6; it != vertices.end(); it++) { for (auto it = vertices.end() - 6; it != vertices.end(); it++) {
it->norm = norm; it->norm = norm;
} }
@ -97,53 +99,55 @@ std::unique_ptr<engine::resources::Mesh> genCuboidMesh(engine::GFXDevice* gfx, f
std::vector<engine::Vertex> v{}; std::vector<engine::Vertex> v{};
const float tiling = 128.0f;
// front // 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, 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({{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}, {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, 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, 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}, {tiling, tiling}});
// back // back
v.push_back({{0.0f, 0.0f, z}, {0.0f, 0.0f, 1.0f}, {0.0f, 0.0f}}); 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({{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, 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}, {0.0f, 0.0f}}); 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}, {0.0f, 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, 0.0f}}); v.push_back({{0.0f, y, z}, {0.0f, 0.0f, 1.0f}, {0.0f, tiling}});
// left // 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, 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, 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}, {0.0f, 0.0f}}); 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, 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}, {0.0f, 0.0f}}); 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}, {0.0f, 0.0f}}); v.push_back({{0.0f, y, 0.0f}, {-1.0f, 0.0f, 0.0f}, {tiling, 0.0f}});
// right // right
v.push_back({{x, y, 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}, {tiling, 0.0f}});
v.push_back({{x, 0.0f, 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, tiling}});
v.push_back({{x, 0.0f, 0.0f}, {1.0f, 0.0f, 0.0f}, {0.0f, 0.0f}}); 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, 0.0f}, {1.0f, 0.0f, 0.0f}, {tiling, 0.0f}});
v.push_back({{x, y, x}, {1.0f, 0.0f, 0.0f}, {0.0f, 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, 0.0f}}); v.push_back({{x, 0.0f, x}, {1.0f, 0.0f, 0.0f}, {0.0f, tiling}});
// bottom // 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({{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, 0.0f}, {0.0f, -1.0f, 0.0f}, {tiling, 0.0f}});
v.push_back({{x, 0.0f, z}, {0.0f, -1.0f, 0.0f}, {0.0f, 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, 0.0f}}); 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}, {0.0f, 0.0f}}); v.push_back({{x, 0.0f, 0.0f}, {0.0f, -1.0f, 0.0f}, {tiling, 0.0f}});
// top // 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, 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({{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}, {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, 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, z}, {0.0f, 1.0f, 0.0f}, {0.0f, 0.0f}}); v.push_back({{x, y, z}, {0.0f, 1.0f, 0.0f}, {tiling, tiling}});
return std::make_unique<engine::resources::Mesh>(gfx, v); return std::make_unique<engine::resources::Mesh>(gfx, v);