Pie Noon
An open source project by FPL.
 All Classes Pages
scene_description.h
1 // Copyright 2014 Google Inc. All rights reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef PIE_NOON_SCENE_DESCRIPTION_H
16 #define PIE_NOON_SCENE_DESCRIPTION_H
17 
18 #include <memory>
19 #include <vector>
20 #include "mathfu/glsl_mappings.h"
21 
22 namespace fpl {
23 
24 class Renderable {
25  public:
26  Renderable(uint16_t id, uint16_t variant, const mathfu::mat4& world_matrix,
27  const mathfu::vec4& color = mathfu::vec4(1, 1, 1, 1))
28  : id_(id),
29  variant_(variant),
30  world_matrix_(world_matrix),
31  color_(color) {}
32 
33  uint16_t id() const { return id_; }
34  void set_id(uint16_t id) { id_ = id; }
35 
36  uint16_t variant() const { return variant_; }
37  void set_variant(uint16_t variant) { variant_ = variant; }
38 
39  const mathfu::mat4& world_matrix() const { return world_matrix_; }
40  void set_world_matrix(const mathfu::mat4& mat) { world_matrix_ = mat; }
41 
42  const mathfu::vec4& color() const { return color_; }
43  void set_color(const mathfu::vec4& c) { color_ = c; }
44 
45  private:
46  // Unique identifier for item to be rendered.
47  // See renderable_id in timeline_generated.h.
48  uint16_t id_;
49 
50  // Variation of the renderable_id `id_` to be rendered.
51  // Could be an alternate color, for example.
52  uint16_t variant_;
53 
54  // Position and orientation of item.
55  mathfu::mat4 world_matrix_;
56 
57  mathfu::vec4 color_;
58 };
59 
61  public:
62  const mathfu::mat4& camera() const { return camera_; }
63  void set_camera(const mathfu::mat4& camera) { camera_ = camera; }
64 
65  std::vector<std::unique_ptr<Renderable>>& renderables() {
66  return renderables_;
67  }
68  const std::vector<std::unique_ptr<Renderable>>& renderables() const {
69  return renderables_;
70  }
71 
72  std::vector<std::unique_ptr<mathfu::vec3>>& lights() { return lights_; }
73  const std::vector<std::unique_ptr<mathfu::vec3>>& lights() const {
74  return lights_;
75  }
76 
77  // Clear out the render list. Should be called once per frame.
78  void Clear() {
79  renderables_.clear();
80  lights_.clear();
81  }
82 
83  private:
84  // The camera position, orientation, fov.
85  mathfu::mat4 camera_;
86 
87  // Array of items to be rendered and their positions.
88  std::vector<std::unique_ptr<Renderable>> renderables_;
89 
90  // Array of positions for where to place point lights.
91  std::vector<std::unique_ptr<mathfu::vec3>> lights_;
92 };
93 
94 } // namespace fpl
95 
96 #endif // PIE_NOON_SCENE_DESCRIPTION_H
Definition: scene_description.h:60
Definition: scene_description.h:24