[EDIT] made a grid for the models to load in
Some items still clip through the wall
This commit is contained in:
@@ -20,22 +20,51 @@ namespace entities
|
||||
GenerateFurnitureModels();
|
||||
}
|
||||
|
||||
const FurniturePiece* HouseGenerator::GetRandomFurniturePiece()
|
||||
{
|
||||
FurnitureType random_type = FurnitureType(toolbox::Random(0, furniture_models.size() - 1));
|
||||
|
||||
for(std::deque<FurnitureModel>::iterator it = furniture_models.begin(); it != furniture_models.end(); ++it)
|
||||
{
|
||||
if(it->furniture.type == random_type)
|
||||
{
|
||||
return &it->furniture;
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::deque<std::shared_ptr<Entity>> HouseGenerator::GenerateHouse(const glm::vec3& position, float y_rotation)
|
||||
{
|
||||
std::deque<std::shared_ptr<Entity>> furniture;
|
||||
|
||||
// Add house
|
||||
furniture.push_front(std::make_shared<Entity>(house_model, position, glm::vec3(0, y_rotation, 0), HOUSE_SIZE));
|
||||
int house_size = house_model.raw_model.model_size.x * HOUSE_SIZE;
|
||||
int offset_x = house_model.raw_model.model_size.z * (HOUSE_SIZE/2);
|
||||
int offset_z = house_model.raw_model.model_size.x *( HOUSE_SIZE/2);
|
||||
double multiplier_x = house_size/2;
|
||||
double multiplier_z = house_size / 3;
|
||||
|
||||
for (int z = 1; z < 4; z++) {
|
||||
for (int x = 1; x < 3; x++)
|
||||
{
|
||||
if (toolbox::Random(0, 100) < 50) {
|
||||
const FurniturePiece* furniture_piece = GetRandomFurniturePiece();
|
||||
models::TexturedModel model = GetFurnitureModel(furniture_piece);
|
||||
//if (//check of size van furniture nog past in huidige grid vlakje, of ie geen 2 size op t laatste vakje neerzet) {
|
||||
glm::vec3 model_pos = glm::vec3(position.x + (x * multiplier_x) - (multiplier_x/2) - offset_x, position.y, position.z + (z * multiplier_z) - (multiplier_z / 2) + offset_z);
|
||||
|
||||
for(int i = 0; i<toolbox::Random(1,4);i++)
|
||||
{
|
||||
FurnitureType type = FurnitureType(toolbox::Random(0, furniture_models.size() - 1));
|
||||
models::TexturedModel model = GetFurnitureModel(type);
|
||||
glm::vec3 model_pos = glm::vec3(position.x, position.y, position.z);
|
||||
collision::Box model_box = { model_pos, model.raw_model.model_size };
|
||||
model_box.SetRotation(-90);
|
||||
furniture.push_back(std::make_shared<CollisionEntity>(model, model_pos, glm::vec3(0, -90, 0), HOUSE_SIZE * 2, model_box));
|
||||
}
|
||||
collision::Box model_box = { model_pos, model.raw_model.model_size };
|
||||
model_box.SetRotation(-90);
|
||||
furniture.push_back(std::make_shared<CollisionEntity>(model, model_pos, glm::vec3(0, -90, 0), HOUSE_SIZE, model_box));
|
||||
//}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return furniture;
|
||||
|
||||
/*
|
||||
// Add furniture
|
||||
@@ -85,22 +114,31 @@ namespace entities
|
||||
collision::Box misc_box = { misc_pos, misc.raw_model.model_size };
|
||||
furniture.push_back(std::make_shared<CollisionEntity>(misc, misc_pos, glm::vec3(0, 0, 0), HOUSE_SIZE, misc_box));
|
||||
*/
|
||||
return furniture;
|
||||
|
||||
}
|
||||
|
||||
models::TexturedModel HouseGenerator::GetFurnitureModel(FurnitureType furniture)
|
||||
models::TexturedModel HouseGenerator::GetFurnitureModel(const FurniturePiece* furniture)
|
||||
{
|
||||
const auto found = furniture_models.find(furniture);
|
||||
if (found == furniture_models.end())
|
||||
std::deque<models::TexturedModel> *furniture_list = nullptr;
|
||||
|
||||
for (std::deque<FurnitureModel>::iterator it = furniture_models.begin(); it != furniture_models.end(); ++it)
|
||||
{
|
||||
if(it->furniture.type == furniture->type)
|
||||
{
|
||||
furniture_list = &it->texture;
|
||||
}
|
||||
}
|
||||
|
||||
if (furniture_list == nullptr)
|
||||
{
|
||||
std::cerr << "OH NEEEEEEEEEEEEEEE";
|
||||
}
|
||||
|
||||
auto models = found->second;
|
||||
|
||||
const int modelNumber = toolbox::Random(0, models.size() - 1);
|
||||
const int modelNumber = toolbox::Random(0, furniture_list->size() - 1);
|
||||
|
||||
return models[modelNumber];
|
||||
return furniture_list->at(modelNumber);
|
||||
|
||||
//return {};
|
||||
}
|
||||
|
||||
void HouseGenerator::GenerateFurnitureModels()
|
||||
@@ -119,8 +157,13 @@ namespace entities
|
||||
models::RawModel couch_inside_model3 = render_engine::LoadObjModel("res/lawnBenchOne.obj");
|
||||
models::TexturedModel couch_inside3 = { couch_inside_model3, default_texture };
|
||||
couches.push_back(couch_inside3);
|
||||
|
||||
FurnitureModel couch;
|
||||
couch.furniture = {
|
||||
FurnitureType::COUCH, 2 };
|
||||
couch.texture = couches;
|
||||
|
||||
furniture_models.insert(std::pair<FurnitureType, std::deque<models::TexturedModel>>(FurnitureType::COUCH, couches));
|
||||
furniture_models.push_back(couch);
|
||||
|
||||
// Tables
|
||||
std::deque<models::TexturedModel> tables;
|
||||
@@ -137,7 +180,12 @@ namespace entities
|
||||
models::TexturedModel table3 = { table_model3, default_texture };
|
||||
tables.push_back(table3);
|
||||
|
||||
furniture_models.insert(std::pair<FurnitureType, std::deque<models::TexturedModel>>(FurnitureType::TABLE, tables));
|
||||
FurnitureModel table;
|
||||
table.furniture = {
|
||||
FurnitureType::TABLE, 2 };
|
||||
table.texture = tables;
|
||||
|
||||
furniture_models.push_back(table);
|
||||
|
||||
// Chairs
|
||||
std::deque<models::TexturedModel> chairs;
|
||||
@@ -154,8 +202,12 @@ namespace entities
|
||||
models::TexturedModel chair3 = { chair_model3, default_texture };
|
||||
chairs.push_back(chair3);
|
||||
|
||||
furniture_models.insert(std::pair<FurnitureType, std::deque<models::TexturedModel>>(FurnitureType::CHAIR, chairs));
|
||||
FurnitureModel chair;
|
||||
chair.furniture = {
|
||||
FurnitureType::CHAIR, 1 };
|
||||
chair.texture = chairs;
|
||||
|
||||
furniture_models.push_back(chair);
|
||||
|
||||
// Plants
|
||||
std::deque<models::TexturedModel> plants;
|
||||
@@ -171,8 +223,13 @@ namespace entities
|
||||
models::RawModel plant_model3 = render_engine::LoadObjModel("res/plantThree.obj");
|
||||
models::TexturedModel plant3 = { plant_model3, default_texture };
|
||||
plants.push_back(plant3);
|
||||
|
||||
furniture_models.insert(std::pair<FurnitureType, std::deque<models::TexturedModel>>(FurnitureType::PLANT, plants));
|
||||
|
||||
FurnitureModel plant;
|
||||
plant.furniture = {
|
||||
FurnitureType::PLANT, 1 };
|
||||
plant.texture = plants;
|
||||
|
||||
furniture_models.push_back(plant);
|
||||
|
||||
// Guitars
|
||||
std::deque<models::TexturedModel> guitars;
|
||||
@@ -184,8 +241,13 @@ namespace entities
|
||||
models::RawModel guitar_model2 = render_engine::LoadObjModel("res/guitarTwo.obj");
|
||||
models::TexturedModel guitar2 = { guitar_model2, default_texture };
|
||||
guitars.push_back(guitar2);
|
||||
|
||||
furniture_models.insert(std::pair<FurnitureType, std::deque<models::TexturedModel>>(FurnitureType::GUITAR, guitars));
|
||||
|
||||
FurnitureModel guitar;
|
||||
guitar.furniture = {
|
||||
FurnitureType::GUITAR, 1 };
|
||||
guitar.texture = guitars;
|
||||
|
||||
furniture_models.push_back(guitar);
|
||||
|
||||
// Bookshelves
|
||||
std::deque<models::TexturedModel> bookshelves;
|
||||
@@ -202,7 +264,12 @@ namespace entities
|
||||
models::TexturedModel bookshelf3 = { bookshelf_model3, default_texture };
|
||||
bookshelves.push_back(bookshelf3);
|
||||
|
||||
furniture_models.insert(std::pair<FurnitureType, std::deque<models::TexturedModel>>(FurnitureType::BOOKSHELF, bookshelves));
|
||||
FurnitureModel bookshelf;
|
||||
bookshelf.furniture = {
|
||||
FurnitureType::BOOKSHELF, 1 };
|
||||
bookshelf.texture = bookshelves;
|
||||
|
||||
furniture_models.push_back(bookshelf);
|
||||
|
||||
// Lamps
|
||||
std::deque<models::TexturedModel>lamps;
|
||||
@@ -214,8 +281,13 @@ namespace entities
|
||||
models::RawModel lamp_model2 = render_engine::LoadObjModel("res/lampTwo.obj");
|
||||
models::TexturedModel lamp2 = { lamp_model2, default_texture };
|
||||
lamps.push_back(lamp2);
|
||||
|
||||
furniture_models.insert(std::pair<FurnitureType, std::deque<models::TexturedModel>>(FurnitureType::LAMP, lamps));
|
||||
|
||||
FurnitureModel lamp;
|
||||
lamp.furniture = {
|
||||
FurnitureType::LAMP, 1 };
|
||||
lamp.texture = lamps;
|
||||
|
||||
furniture_models.push_back(lamp);
|
||||
|
||||
// Ceiling objects
|
||||
std::deque<models::TexturedModel>ceiling_Objects;
|
||||
@@ -235,8 +307,13 @@ namespace entities
|
||||
models::RawModel ceiling_Obj_model4 = render_engine::LoadObjModel("res/ceilingLampTwo.obj");
|
||||
models::TexturedModel ceiling_Obj4 = { ceiling_Obj_model4, default_texture };
|
||||
ceiling_Objects.push_back(ceiling_Obj4);
|
||||
|
||||
furniture_models.insert(std::pair<FurnitureType, std::deque<models::TexturedModel>>(FurnitureType::CEILING_OBJECTS, ceiling_Objects));
|
||||
|
||||
FurnitureModel ceiling_object;
|
||||
ceiling_object.furniture = {
|
||||
FurnitureType::CEILING_OBJECTS, 1 };
|
||||
ceiling_object.texture = ceiling_Objects;
|
||||
|
||||
furniture_models.push_back(ceiling_object);
|
||||
|
||||
// Miscs
|
||||
std::deque<models::TexturedModel> miscs;
|
||||
@@ -253,6 +330,11 @@ namespace entities
|
||||
models::TexturedModel misc3 = { misc_model3, default_texture };
|
||||
miscs.push_back(misc3);
|
||||
|
||||
furniture_models.insert(std::pair<FurnitureType, std::deque<models::TexturedModel>>(FurnitureType::MISC, miscs));
|
||||
FurnitureModel misc;
|
||||
misc.furniture = {
|
||||
FurnitureType::MISC, 1 };
|
||||
misc.texture = miscs;
|
||||
|
||||
furniture_models.push_back(misc);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,6 +20,24 @@ namespace entities
|
||||
CEILING_OBJECTS,
|
||||
MISC
|
||||
};
|
||||
struct FurniturePiece
|
||||
{
|
||||
FurnitureType type;
|
||||
int size;
|
||||
};
|
||||
|
||||
struct FurnitureModel
|
||||
{
|
||||
FurniturePiece furniture;
|
||||
std::deque<models::TexturedModel> texture;
|
||||
|
||||
bool operator<(FurnitureModel a)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
class HouseGenerator
|
||||
{
|
||||
@@ -29,11 +47,11 @@ namespace entities
|
||||
models::TexturedModel house_model;
|
||||
models::ModelTexture default_texture;
|
||||
|
||||
std::map<FurnitureType, std::deque<models::TexturedModel>> furniture_models;
|
||||
|
||||
//std::map<FurniturePiece, std::deque<models::TexturedModel>> furniture_models;
|
||||
std::deque<FurnitureModel> furniture_models;
|
||||
public:
|
||||
HouseGenerator();
|
||||
|
||||
|
||||
/*
|
||||
* @brief: This function generates a house with furniture at the given position and rotation
|
||||
*
|
||||
@@ -50,6 +68,8 @@ namespace entities
|
||||
float GetHouseDepth() const { return house_model.raw_model.model_size.x * HOUSE_SIZE; }
|
||||
|
||||
private:
|
||||
const FurniturePiece* GetRandomFurniturePiece();
|
||||
|
||||
/*
|
||||
* @brief: This function loads all the 3D furniture models
|
||||
*/
|
||||
@@ -62,6 +82,6 @@ namespace entities
|
||||
*
|
||||
* @return: The model of the random furniture of the chosen furniture type
|
||||
*/
|
||||
models::TexturedModel GetFurnitureModel(FurnitureType furniture);
|
||||
models::TexturedModel GetFurnitureModel(const FurniturePiece* furniture);
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user