ADD: Trees on Forest Tiles
This commit is contained in:
parent
6833f899b4
commit
d4489f5631
BIN
assets/trees/lowPolyTree.png
Normal file
BIN
assets/trees/lowPolyTree.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 461 B |
@ -27,10 +27,13 @@ void GameLayer::onAttach()
|
|||||||
mousePicker = std::make_unique<MousePicker>(renderer->getProjectionMatrix(), MathUtils::createViewMatrix(*camera));
|
mousePicker = std::make_unique<MousePicker>(renderer->getProjectionMatrix(), MathUtils::createViewMatrix(*camera));
|
||||||
|
|
||||||
//Map Generation
|
//Map Generation
|
||||||
hexModelDefault = std::make_shared<TexturedModel>(HexModelFactory::createTexturedHexModel(loader, 1.0f, RessourceType::NONE));
|
hexModelDefault = std::make_shared<TexturedModel>(HexModelFactory::createTexturedHexModel(loader, 10.0f, RessourceType::NONE));
|
||||||
hexModelWood = std::make_shared<TexturedModel>(HexModelFactory::createTexturedHexModel(loader, 1.0f, RessourceType::WOOD));
|
hexModelWood = std::make_shared<TexturedModel>(HexModelFactory::createTexturedHexModel(loader, 10.0f, RessourceType::WOOD));
|
||||||
map = std::make_unique<Map>();
|
map = std::make_unique<Map>();
|
||||||
MapGenerator::generateHexMap(*map, 10,10,1.f);
|
|
||||||
|
treeModel = std::make_unique<TexturedModel>(*OBJLoader::loadModel("assets/trees/lowPolyTree.obj", "assets/trees/lowPolyTree.png", loader));
|
||||||
|
treeEntity = std::make_unique<Entity>(Entity(treeModel, glm::vec3(0,0,0), 0,0,0, 0.5f));
|
||||||
|
MapGenerator::generateHexMap(*map, 10,10,10.f, mapEntities, treeModel);
|
||||||
printf("Generated Terrain with %lu Tiles!\n", map->tiles.size());
|
printf("Generated Terrain with %lu Tiles!\n", map->tiles.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -55,6 +58,9 @@ void GameLayer::onUpdate()
|
|||||||
camera->move(moveDir, 0.5f);
|
camera->move(moveDir, 0.5f);
|
||||||
|
|
||||||
renderer->submitEntity(entity.get());
|
renderer->submitEntity(entity.get());
|
||||||
|
for (const auto& entity : mapEntities) {
|
||||||
|
renderer->submitEntity(entity.get());
|
||||||
|
}
|
||||||
|
|
||||||
for (HexTile& tile : map->tiles) {
|
for (HexTile& tile : map->tiles) {
|
||||||
glm::vec3 intersectionPoint;
|
glm::vec3 intersectionPoint;
|
||||||
|
|||||||
@ -34,6 +34,12 @@ private:
|
|||||||
|
|
||||||
std::shared_ptr<TexturedModel> hexModelDefault;
|
std::shared_ptr<TexturedModel> hexModelDefault;
|
||||||
std::shared_ptr<TexturedModel> hexModelWood;
|
std::shared_ptr<TexturedModel> hexModelWood;
|
||||||
|
|
||||||
|
std::vector<std::shared_ptr<Entity>> tileEntities;
|
||||||
|
std::shared_ptr<TexturedModel> treeModel;
|
||||||
|
std::unique_ptr<Entity> treeEntity;
|
||||||
|
|
||||||
|
std::vector<std::shared_ptr<Entity>> mapEntities;
|
||||||
std::unique_ptr<Map> map;
|
std::unique_ptr<Map> map;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -6,6 +6,7 @@
|
|||||||
#define HEXTILE_H
|
#define HEXTILE_H
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
|
#include "../../engine/layer/entities/Entity.h"
|
||||||
#include "../../engine/renderer/model/TexturedModel.h"
|
#include "../../engine/renderer/model/TexturedModel.h"
|
||||||
#include "glm/vec2.hpp"
|
#include "glm/vec2.hpp"
|
||||||
#include "glm/vec3.hpp"
|
#include "glm/vec3.hpp"
|
||||||
@ -24,6 +25,9 @@ struct HexTile {
|
|||||||
float radius;
|
float radius;
|
||||||
bool isHighlighted = false;
|
bool isHighlighted = false;
|
||||||
|
|
||||||
|
std::vector<std::shared_ptr<Entity>> entitiesOnTile;
|
||||||
|
|
||||||
|
|
||||||
bool intersect(const glm::vec3& rayOrigin, const glm::vec3& rayDirection, glm::vec3& intersectionPoint) const {
|
bool intersect(const glm::vec3& rayOrigin, const glm::vec3& rayDirection, glm::vec3& intersectionPoint) const {
|
||||||
float t = -rayOrigin.y / rayDirection.y;
|
float t = -rayOrigin.y / rayDirection.y;
|
||||||
if (t < 0) return false; // Ray zeigt nach oben, nicht getroffen
|
if (t < 0) return false; // Ray zeigt nach oben, nicht getroffen
|
||||||
|
|||||||
@ -12,7 +12,7 @@
|
|||||||
|
|
||||||
class MapGenerator {
|
class MapGenerator {
|
||||||
public:
|
public:
|
||||||
static void generateHexMap(Map& map, int width, int height, float hexRadius) {
|
static void generateHexMap(Map& map, int width, int height, float hexRadius, std::vector<std::shared_ptr<Entity>>& mapEntities, const std::shared_ptr<TexturedModel>& treeModel) {
|
||||||
// Zufallsgenerator initialisieren (einmal)
|
// Zufallsgenerator initialisieren (einmal)
|
||||||
std::random_device rd; // Zufälliger Seed
|
std::random_device rd; // Zufälliger Seed
|
||||||
std::mt19937 gen(rd()); // Mersenne Twister Generator
|
std::mt19937 gen(rd()); // Mersenne Twister Generator
|
||||||
@ -39,6 +39,21 @@ public:
|
|||||||
float randomValue = dis(gen);
|
float randomValue = dis(gen);
|
||||||
if (randomValue < 0.5f) {
|
if (randomValue < 0.5f) {
|
||||||
tile.resourceType = RessourceType::WOOD;
|
tile.resourceType = RessourceType::WOOD;
|
||||||
|
|
||||||
|
int treeCount = 3 + (int) (dis(gen) * 3);
|
||||||
|
std::uniform_real_distribution<float> offsetDis(-hexRadius * 0.5f, hexRadius * 0.5f);
|
||||||
|
|
||||||
|
for (int i = 0; i < treeCount; ++i) {
|
||||||
|
glm::vec3 treePos = tile.worldPos;
|
||||||
|
treePos.x += offsetDis(gen);
|
||||||
|
treePos.z += offsetDis(gen);
|
||||||
|
|
||||||
|
std::shared_ptr<Entity> treeEntity = std::make_shared<Entity>(Entity(treeModel, treePos, 0,0,0,.4f));
|
||||||
|
|
||||||
|
mapEntities.push_back(treeEntity);
|
||||||
|
tile.entitiesOnTile.push_back(treeEntity);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
map.tiles.push_back(tile);
|
map.tiles.push_back(tile);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user