Skip to content
Snippets Groups Projects
Commit 0f55c89b authored by Joseph Walton-Rivers's avatar Joseph Walton-Rivers
Browse files

add object placement

parent 784b2324
No related branches found
No related tags found
No related merge requests found
......@@ -78,6 +78,20 @@ void process_camera(fggl::ecs3::World& ecs, const InputManager& input) {
fggl::input::process_edgescroll( ecs, *input, cam );
}
void placeObject(fggl::ecs3::World& world, fggl::ecs::entity_t parent, fggl::ecs::entity_t prototype, glm::vec3 targetPos) {
auto obj = world.copy(prototype);
auto result = world.get<fggl::math::Transform>(obj);
int xPos = (int)targetPos.x;
int zPos = (int)targetPos.z * -1;
// figure out the floor height
auto heightMap = world.get<fggl::data::HeightMap>(parent);
targetPos.y = heightMap->getValue(xPos, zPos); // TODO should really be the gradient at the required point
result->origin( targetPos );
}
class MenuScene : public fggl::scenes::Scene {
public:
......@@ -103,8 +117,8 @@ public:
}
private:
InputManager m_inputs;
private:
InputManager m_inputs;
};
......@@ -159,6 +173,23 @@ public:
m_world.set<fggl::data::HeightMap>(terrain, &terrainData);
}
// create foundation object
fggl::ecs3::entity_t foundation;
{
foundation = m_world.create(true);
m_world.add(foundation, types.find(fggl::math::Transform::name));
// plot rendering
fggl::data::Mesh mesh;
fggl::data::make_cube(mesh);
mesh.removeDups();
// add mesh as a component
constexpr char shader[] = "phong";
fggl::gfx::StaticMesh staticMesh{mesh, shader};
m_world.set<fggl::gfx::StaticMesh>(foundation, &staticMesh);
}
// create building prototype
fggl::ecs3::entity_t bunker;
{
......@@ -192,21 +223,17 @@ public:
m_world.set<fggl::gfx::StaticMesh>(bunker, &staticMesh);
}
for (int i=0; i<3; ++i) {
glm::vec3 location(i * 6.5f + 1.0f, 0.0f, -7.0f);
placeObject(m_world, terrain, foundation, location);
}
int nCubes = 3;
for ( int i=0; i<nCubes; i++ ) {
auto bunkerClone = m_world.copy(bunker);
auto result = m_world.get<fggl::math::Transform>(bunkerClone);
float x = (float)i * 6.f + 1.0f;
int xPos = (int)x;
float z = (float)-5.0f + 1.0f;
int zPos = (int)z * -1;
// figure out the floor height
auto heightMap = m_world.get<fggl::data::HeightMap>(terrain);
float y = heightMap->getValue(xPos, zPos); // TODO should really be the gradient at the required point
result->origin( glm::vec3( x, y, z) );
glm::vec3 location;
location.x = i * 6.f + 1.0f;
location.z = -5.0f + 1.0f;
placeObject(m_world, terrain, bunker, location);
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment