Euphoria
world.cc
Go to the documentation of this file.
1 #include "render/world.h"
2 
3 #include "assert/assert.h"
4 #include "core/camera3.h"
5 #include "core/viewport.h"
6 
8 #include "render/gl.h"
9 
10 #include <algorithm>
11 
12 namespace eu::render
13 {
14  void
15  World::add_actor(const std::shared_ptr<Instance>& actor)
16  {
17  actors.push_back(actor);
18  }
19 
21  World::render(const core::Viewport& viewport, const core::Camera3& camera)
22  {
23  const auto compiled = camera.compile(viewport.get_aspect_ratio());
24  render(camera, compiled);
25  return compiled;
26  }
27 
28  void
30  {
31  actors.erase
32  (
33  std::remove_if
34  (
35  actors.begin(),
36  actors.end(),
37  [](const std::shared_ptr<Instance>& instance)
38  {
39  return instance->remove_this;
40  }
41  ),
42  actors.end()
43  );
44  }
45 
46  void
48  (
49  const core::Camera3& camera,
50  const core::CompiledCamera3& compiled
51  )
52  {
53  const auto projection_matrix = compiled.projection;
54  const auto view_matrix = compiled.view;
55 
56  for(const auto& actor: actors)
57  {
58  if(actor->remove_this)
59  {
60  continue;
61  }
62 
63  // todo(Gustav): instead of direct rendering, move to a material sorting/render
64  // command system
65  // general design: http://realtimecollisiondetection.net/blog/?p=86
66  // distance from camera:
67  // https://gamedev.stackexchange.com/questions/56810/how-do-games-deal-with-z-sorting-partially-transparent-foliage-textures
68  // distance in integer:
69  // http://aras-p.info/blog/2014/01/16/rough-sorting-by-depth/
70  // useful?
71  // https://gamedev.stackexchange.com/questions/45626/how-to-organize-rendering
72  actor->render(projection_matrix, view_matrix, camera.position, light);
73  }
74  }
75 
76 }
vec3f position
Definition: camera3.h:30
CompiledCamera3 compile(float aspect) const
Definition: camera3.cc:74
float get_aspect_ratio() const
Definition: viewport.cc:15
void update()
Definition: world.cc:29
std::vector< std::shared_ptr< Instance > > actors
Definition: world.h:50
core::CompiledCamera3 render(const core::Viewport &viewport, const core::Camera3 &camera)
Definition: world.cc:21
render::Light light
Definition: world.h:35
void add_actor(const std::shared_ptr< Instance > &actor)
Definition: world.cc:15