Simulant  21.12-194
A portable game engine for Windows, OSX, Linux, Dreamcast, and PSP
debug.h
1 /* * Copyright (c) 2011-2017 Luke Benstead https://simulant-engine.appspot.com
2  *
3  * This file is part of Simulant.
4  *
5  * Simulant is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Lesser General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * Simulant is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with Simulant. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #ifndef DEBUG_H
20 #define DEBUG_H
21 
22 #include "types.h"
23 #include "generic/managed.h"
24 #include "meshes/mesh.h"
25 
26 namespace smlt {
27 
28 class Debug : public RefCounted<Debug> {
29 public:
30  Debug(Stage& stage);
31  virtual ~Debug();
32 
33  void draw_ray(
34  const Vec3& start,
35  const Vec3& dir,
36  const Colour& colour=Colour::WHITE,
37  double duration=0.0,
38  bool depth_test=true
39  );
40 
41 
42  void draw_line(
43  const Vec3& start,
44  const Vec3& end,
45  const Colour& colour=Colour::WHITE,
46  double duration=0.0,
47  bool depth_test=true
48  );
49 
50  void draw_point(
51  const Vec3& position,
52  const Colour& colour=Colour::WHITE,
53  double duration=0.0,
54  bool depth_test=true
55  );
56 
57  bool init() override;
58 
59  void set_point_size(float ps);
60 
61  float point_size() const;
62 
63  void update(float dt);
64 
65  void set_transform(const Mat4& mat);
66  Mat4 transform() const;
67 
68 private:
69  Mat4 transform_;
70 
71  void frame_finished();
72 
73  bool initialized_ = false;
74 
75  void initialize_actor();
76 
77 
78  Stage& stage_;
79 
80  enum DebugElementType {
81  DET_LINE,
82  DET_POINT
83  };
84 
85  struct DebugElement {
86  float time_since_created = 0.0;
87  DebugElementType type = DET_LINE;
88  Colour colour = Colour::WHITE;
89  bool depth_test = true;
90  float duration = 0.0;
91 
92  smlt::Vec3 points[2]; // For lines, or the first one for points
93  float size; // Diameter for spheres + points
94  };
95 
96  std::list<DebugElement> elements_;
97 
98  SubMesh* lines_without_depth_ = nullptr;
99  SubMesh* lines_with_depth_ = nullptr;
100  SubMesh* points_without_depth_ = nullptr;
101  SubMesh* points_with_depth_ = nullptr;
102 
103  MeshID mesh_;
104  ActorPtr actor_ = nullptr;
105  MaterialID material_;
106  MaterialID material_no_depth_;
107  float current_point_size_ = 0.001f;
108 
109  sig::Connection frame_finished_connection_;
110 };
111 
112 }
113 
114 #endif // DEBUG_H
smlt::Mat4
Definition: mat4.h:25
smlt::sig::Connection
Definition: signal.h:65
smlt::Vec3
Definition: vec3.h:23
smlt::Stage
Definition: stage.h:92
smlt::RefCounted
Definition: managed.h:65
smlt
Definition: animation.cpp:25
smlt::UniqueID< MeshPtr >
smlt::default_init_ptr< Actor >
smlt::Debug
Definition: debug.h:28
smlt::SubMesh
Definition: submesh.h:42
smlt::Colour
Definition: colour.h:29