Skip to content
Snippets Groups Projects
Commit 8cea3388 authored by Martin Štourač's avatar Martin Štourač
Browse files

grid in scene

parent 09de3315
No related branches found
No related tags found
No related merge requests found
......@@ -18,7 +18,7 @@ protected:
frame_weak_ptr frame;
public:
Light(glm::vec3 _color, frame_ptr _pos) : color{_color}, frame{_pos} {}
glm::vec3 getColor() { return color; }
glm::vec3 getColor() const { return color; }
virtual glm::vec3 getPosition() const
{
......
......@@ -26,10 +26,11 @@ public:
Node(frame_ptr _frame, parent_weak_ptr _parent = std::weak_ptr<Node>(), std::vector<node_ptr> _children = {})
: frame{_frame}, parent{_parent}, children{_children} {}
frame_ptr getFrame() { return frame; }
std::vector<node_ptr> &getChildren() { return children; }
parent_weak_ptr getParent() { return parent; }
std::vector<objectbase_ptr> &getObjects() { return objects; };
frame_ptr getFrame() const { return frame; }
parent_weak_ptr getParent() const { return parent; }
const std::vector<node_ptr> &getChildren() const { return children; }
const std::vector<objectbase_ptr> &getObjects() const { return objects; }
void setFrame(frame_ptr _frame) { frame = _frame; }
void addChild(Node child) { children.emplace_back(std::make_shared<Node>(child)); }
......
......@@ -19,6 +19,7 @@ class Object : public ObjectBase
glm::vec3 color;
std::string shader_type;
int draw_mode = GL_TRIANGLES;
public:
Object(std::vector<float> const &_vertices,
......@@ -47,6 +48,9 @@ public:
glm::vec3 getColor() const { return color; }
void setColor(glm::vec3 _color) { color = _color; }
int getDrawMode() const { return draw_mode; }
void setDrawMode(int _draw_mode) { draw_mode = _draw_mode; }
};
#endif
\ No newline at end of file
......@@ -22,9 +22,8 @@ using light_ptr = std::shared_ptr<Light>;
std::vector<float> generate_grid_vertices(int span);
std::vector<unsigned int> generate_grid_indices(int span);
void send_matrices_to_shader(Shader &myShader, glm::mat4 &model, glm::mat4 &view, glm::mat4 &projection);
void gfx_draw(std::map<std::string, shader_ptr> &myShaders, light_ptr light,
void gfx_draw(std::map<std::string, shader_ptr> &myShaders, std::vector<light_ptr> lights,
std::vector<camera_ptr> &cameras, std::vector<frame_ptr> &cam_frames, int active_camera,
std::vector<node_ptr> &scene,
Object &grid, Frame &grid_frame);
std::vector<node_ptr> &scene);
#endif
\ No newline at end of file
......@@ -69,9 +69,9 @@ void send_matrices_to_shader(Shader &myShader, glm::mat4 &model, glm::mat4 &view
ASSUMPTION(glGetError() == GL_NO_ERROR);
}
void draw_objects(std::map<std::string, shader_ptr> &myShaders, light_ptr light,
void draw_objects(std::map<std::string, shader_ptr> &myShaders, std::vector<light_ptr> lights,
std::vector<frame_ptr> &cam_frames, int active_camera,
std::vector<node_ptr> &scene,
const std::vector<node_ptr> &scene,
glm::mat4 &view, glm::mat4 &projection)
{
for (auto &node : scene)
......@@ -89,10 +89,12 @@ void draw_objects(std::map<std::string, shader_ptr> &myShaders, light_ptr light,
if (shader_used == "lit")
{
// FTO DO: enum promennych z shaderu
myShaders[shader_used]->setVec3("lightColor", light->getColor());
myShaders[shader_used]->setVec3("lightPos", light->getPosition());
// Currently 1 light only
myShaders[shader_used]->setVec3("lightColor", lights[0]->getColor());
myShaders[shader_used]->setVec3("lightPos", lights[0]->getPosition());
myShaders[shader_used]->setVec3("viewPos", cam_frames[active_camera]->getPosition());
}
// else if (shader_used == "basic")
// TO DO: children maji relativni frame vuci parentum
glm::mat4 model = node->getFrame()->getModelMat();
......@@ -101,14 +103,14 @@ void draw_objects(std::map<std::string, shader_ptr> &myShaders, light_ptr light,
obj->getVAO()->Bind();
glDrawElements(GL_TRIANGLES,
glDrawElements(obj->getDrawMode(),
static_cast<GLsizei>(obj->getIndices().size()),
GL_UNSIGNED_INT,
0);
ASSUMPTION(glGetError() == GL_NO_ERROR);
}
draw_objects(myShaders, light, cam_frames, active_camera, node->getChildren(), view, projection);
draw_objects(myShaders, lights, cam_frames, active_camera, node->getChildren(), view, projection);
}
}
......@@ -129,7 +131,7 @@ void draw_grid(std::map<std::string, shader_ptr> &myShaders, Object &grid, Frame
ASSUMPTION(glGetError() == GL_NO_ERROR);
}
void find_lights(std::vector<node_ptr> &scene, std::vector<Node*> &lights)
void find_lights(const std::vector<node_ptr> &scene, std::vector<Node*> &lights)
{
for (auto &node : scene)
{
......@@ -142,10 +144,9 @@ void find_lights(std::vector<node_ptr> &scene, std::vector<Node*> &lights)
}
}
void gfx_draw(std::map<std::string, shader_ptr> &myShaders, light_ptr light,
void gfx_draw(std::map<std::string, shader_ptr> &myShaders, std::vector<light_ptr> lights,
std::vector<camera_ptr> &cameras, std::vector<frame_ptr> &cam_frames, int active_camera,
std::vector<node_ptr> &scene,
Object &grid, Frame &grid_frame)
std::vector<node_ptr> &scene)
{
glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
......@@ -187,8 +188,9 @@ void gfx_draw(std::map<std::string, shader_ptr> &myShaders, light_ptr light,
// find_lights(scene, lights);
/* DRAW OBJECTS */
draw_objects(myShaders, light, cam_frames, active_camera, scene, view, projection);
draw_objects(myShaders, lights, cam_frames, active_camera, scene, view, projection);
/* DRAW GRID */
draw_grid(myShaders, grid, grid_frame, view, projection);
//find_grid();
// draw_grid(myShaders, grid, grid_frame, view, projection);
}
......@@ -46,8 +46,8 @@ struct Simulator : public osi::Simulator
void update() override;
void present() override;
void showUI();
void find_lights(std::vector<node_ptr> &scene);
void find_cameras(std::vector<node_ptr> &scene);
void find_lights(const std::vector<node_ptr> &scene);
void find_cameras(const std::vector<node_ptr> &scene);
void create_scene();
void process_input();
void process_mouse();
......@@ -74,10 +74,10 @@ struct Simulator : public osi::Simulator
std::vector<camera_ptr> cameras;
// find cameras, lights zde vektory
Object grid = Object(generate_grid_vertices(100), generate_grid_indices(100), {0, -1, 0},
glm::vec3(0.5f, 0.5f, 0.5f), "basic");
Frame grid_frame = Frame({0, 0, 0});
light_ptr light;
// Object grid = Object(generate_grid_vertices(100), generate_grid_indices(100), {0, -1, 0},
// glm::vec3(0.5f, 0.5f, 0.5f), "basic");
// Frame grid_frame = Frame({0, 0, 0});
// light_ptr light;
std::map<std::string, shader_ptr> myShaders;
};
......
......@@ -170,7 +170,7 @@ void Simulator::present()
cameras[active_camera]->setWindowSize(window().size());
}
gfx_draw(myShaders, lights[0], cameras, cam_frames, active_camera, scene, grid, grid_frame);
gfx_draw(myShaders, lights, cameras, cam_frames, active_camera, scene);
}
void Simulator::showUI()
......@@ -192,7 +192,7 @@ void Simulator::showUI()
ImGui::End();
}
void Simulator::find_lights(std::vector<node_ptr> &scene)
void Simulator::find_lights(const std::vector<node_ptr> &scene)
{
for (auto &node : scene)
{
......@@ -206,7 +206,7 @@ void Simulator::find_lights(std::vector<node_ptr> &scene)
}
}
void Simulator::find_cameras(std::vector<node_ptr> &scene)
void Simulator::find_cameras(const std::vector<node_ptr> &scene)
{
for (auto &node : scene)
{
......@@ -227,8 +227,18 @@ void Simulator::create_scene()
scene.emplace_back(std::make_shared<Node>(obj_frames[i]));
scene[i]->addObject(objects[i]);
}
// scene.emplace_back(std::make_shared<Node>(grid_frame));
// scene.back()->addObject(grid);
/* ADD GRID */
scene.emplace_back(std::make_shared<Node>(std::make_shared<Frame>(glm::vec3(0, 0, 0))));
object_ptr grid = std::make_shared<Object>(generate_grid_vertices(100),
generate_grid_indices(100),
std::vector<float>{0, -1, 0},
glm::vec3(0.5f, 0.5f, 0.5f),
"basic");
grid->setDrawMode(GL_LINES);
scene.back()->addObject(std::move(grid));
/* ADD LIGHT */
scene.emplace_back(std::make_shared<Node>(obj_frames[1]));
scene.back()->addObject(std::make_shared<Light>(glm::vec3(1.0f, 1.0f, 1.0f), scene.back()->getFrame()));
}
......
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