diff --git a/assets/cabin/20958_Log_Cabin_v1_NEW.mtl b/assets/cabin/20958_Log_Cabin_v1_NEW.mtl new file mode 100644 index 0000000..5eed654 --- /dev/null +++ b/assets/cabin/20958_Log_Cabin_v1_NEW.mtl @@ -0,0 +1,31 @@ +# 3ds Max Wavefront OBJ Exporter v0.97b - (c)2007 guruware +# File Created: 03.06.2013 16:07:05 + +newmtl 20958_Log_Cabin_v1 + Ns 18.0000 + Ni 1.5000 + d 1.0000 + Tr 0.0000 + Tf 1.0000 1.0000 1.0000 + illum 2 + Ka 1.0000 1.0000 1.0000 + Kd 1.0000 1.0000 1.0000 + Ks 0.3240 0.3240 0.3240 + Ke 0.0000 0.0000 0.0000 + map_Ka cabin.jpg + map_Kd cabin.jpg + map_Ks 20958_Log_Cabin_v1_specular.jpg + +newmtl 02___Default + Ns 10.0000 + Ni 1.5000 + d 1.0000 + Tr 0.0000 + Tf 1.0000 1.0000 1.0000 + illum 2 + Ka 1.0000 1.0000 1.0000 + Kd 1.0000 1.0000 1.0000 + Ks 0.0000 0.0000 0.0000 + Ke 0.0000 0.0000 0.0000 + map_Ka disc_diffuse.JPG + map_Kd disc_diffuse.JPG diff --git a/assets/cabin/cabin.jpg b/assets/cabin/cabin.jpg new file mode 100644 index 0000000..09e53a8 Binary files /dev/null and b/assets/cabin/cabin.jpg differ diff --git a/src/game/GameLayer.cpp b/src/game/GameLayer.cpp index 33f24c1..add809d 100644 --- a/src/game/GameLayer.cpp +++ b/src/game/GameLayer.cpp @@ -22,7 +22,7 @@ GameLayer::GameLayer() :texturedModel(0,0) //Platzhalter, echtes Model kommt in void GameLayer::onAttach() { texturedModel = *OBJLoader::loadModel("assets/dragon/dragon.obj", "assets/dragon/dragon.png", loader); - entity = std::make_unique(Entity(std::make_shared(texturedModel), glm::vec3(0,0,-25), 0,0,0, 1.f)); + entities.push_back(std::make_shared(Entity(std::make_shared(texturedModel), glm::vec3(0,0,-25), 0,0,0, 1.f))); camera = std::make_unique(); light = std::make_unique(glm::vec3(0,10,0), glm::vec3(1,1,1)); mousePicker = std::make_unique(renderer->getProjectionMatrix(), MathUtils::createViewMatrix(*camera)); @@ -40,6 +40,9 @@ void GameLayer::onAttach() //treeEntity = std::make_unique(Entity(treeModel, glm::vec3(0,0,0), 0,0,0, 0.5f)); MapGenerator::generateHexMap(*map, 10,10,10.f, mapEntities); printf("Generated Terrain with %lu Tiles!\n", map->tiles.size()); + + auto cabinModel = AssetManager::loadModel("cabin", "assets/cabin/cabin.obj", "assets/cabin/cabin.jpg", loader); + //entities.push_back(std::make_shared(Entity(cabinModel, glm::vec3(0,0,0), 0,0,0, 1.f))); } void GameLayer::onDetach() @@ -58,12 +61,9 @@ void GameLayer::onUpdate() if (InputManager::isKeyPressed(GLFW_KEY_D)) moveDir.x += 1.0f; - - entity->increaseRotation(0,1,0); camera->move(moveDir, 0.5f); - renderer->submitEntity(entity.get()); - for (const auto& entity : mapEntities) { + for (const auto& entity : entities) { renderer->submitEntity(entity.get()); } @@ -71,8 +71,27 @@ void GameLayer::onUpdate() glm::vec3 intersectionPoint; bool highlight = tile.intersect(camera->getPosition(), mousePicker->getCurrentRay(), intersectionPoint); tile.isHighlighted = highlight; + + if (tile.isHighlighted) { + if (InputManager::isMouseButtonPressed(GLFW_MOUSE_BUTTON_1)) { + //On this tile you should build something + if (!tile.building && tile.resourceType == RessourceType::WOOD) { + tile.entitiesOnTile.clear(); + tile.building = std::make_shared(AssetManager::getModel("cabin"), tile.worldPos, 0,0,0,1.f); + } + } + } + + for (const auto& entity: tile.entitiesOnTile) { + renderer->submitEntity(entity.get()); + } + + if (tile.building) { + renderer->submitEntity(tile.building.get()); + } } + std::vector terrainRenderData = map->getTerrainRenderData(hexModelDefault, hexModelWood, hexModelStone); diff --git a/src/game/GameLayer.h b/src/game/GameLayer.h index eaf2990..e09ce0d 100644 --- a/src/game/GameLayer.h +++ b/src/game/GameLayer.h @@ -26,7 +26,6 @@ public: private: Loader loader; TexturedModel texturedModel; - std::unique_ptr entity; std::unique_ptr camera; std::unique_ptr light; std::unique_ptr mousePicker; @@ -36,9 +35,8 @@ private: std::shared_ptr hexModelWood; std::shared_ptr hexModelStone; - std::vector> tileEntities; - std::vector> mapEntities; + std::vector> entities; std::unique_ptr map; }; diff --git a/src/game/hexWorld/HexTile.h b/src/game/hexWorld/HexTile.h index 230ee47..64739c7 100644 --- a/src/game/hexWorld/HexTile.h +++ b/src/game/hexWorld/HexTile.h @@ -27,6 +27,7 @@ struct HexTile { bool isHighlighted = false; std::vector> entitiesOnTile; + std::shared_ptr building; bool intersect(const glm::vec3& rayOrigin, const glm::vec3& rayDirection, glm::vec3& intersectionPoint) const {