Simulant  21.12-1292
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
7  * by the Free Software Foundation, either version 3 of the License, or (at your
8  * 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 #pragma once
20 
21 #include "../generic/managed.h"
22 #include "../meshes/mesh.h"
23 #include "../types.h"
24 #include "stage_node.h"
25 
26 namespace smlt {
27 
28 class Debug: public StageNode, public HasMutableRenderPriority {
29 public:
30  S_DEFINE_STAGE_NODE_META(STAGE_NODE_TYPE_DEBUG, "debug");
31 
32  Debug(Scene* owner);
33  virtual ~Debug();
34 
35  void draw_ray(const Vec3& start, const Vec3& dir,
36  const Color& color = Color::white(),
37  Seconds duration = Seconds(), bool depth_test = false);
38 
39  void draw_line(const Vec3& start, const Vec3& end,
40  const Color& color = Color::white(),
41  Seconds duration = Seconds(), bool depth_test = false);
42 
43  void draw_point(const Vec3& position, const Color& color = Color::white(),
44  Seconds duration = Seconds(), bool depth_test = false);
45 
46  bool on_init() override;
47 
48  void set_point_size(float ps);
49  float point_size() const;
50 
51  void set_line_width(float size);
52  float line_width() const;
53 
54 private:
55  void do_generate_renderables(batcher::RenderQueue* render_queue,
56  const Camera* camera, const Viewport*,
57  const DetailLevel detail_level, Light** light,
58  const std::size_t light_count) override;
59 
60  void reset();
61  void build_mesh(const Camera* camera);
62 
63  void push_line(SubMeshPtr& submesh, const Vec3& start, const Vec3& end,
64  const Color& color, const Vec3& camera_pos);
65 
66  void push_point(SubMeshPtr& submesh, const Vec3& position,
67  const Color& color, float size, const Vec3& up,
68  const Vec3& right);
69 
70  enum DebugElementType {
71  DET_LINE,
72  DET_POINT
73  };
74 
75  struct DebugElement {
76  float time_since_created = 0.0;
77  DebugElementType type = DET_LINE;
78  Color color = Color::white();
79  bool depth_test = true;
80  float duration = 0.0f;
81 
82  smlt::Vec3 points[2]; // For lines, or the first one for points
83  float size; // Diameter for spheres + points
84  };
85 
86  std::vector<DebugElement> elements_;
87 
88  SubMesh* without_depth_ = nullptr;
89  SubMesh* with_depth_ = nullptr;
90 
91  MeshPtr mesh_ = nullptr;
92  ActorPtr actor_ = nullptr;
93  MaterialPtr material_;
94  MaterialPtr material_no_depth_;
95 
96  float current_point_size_ = 0.01f;
97  float current_line_width_ = 0.01f;
98 
99  sig::Connection frame_connection_;
100 
101  bool on_create(Params params) override {
102  _S_UNUSED(params);
103  return true;
104  }
105 };
106 
107 } // namespace smlt
smlt::Actor
Definition: actor.h:53
smlt::sig::Connection
Definition: signal.h:65
smlt::Vec3
Definition: vec3.h:25
smlt::Params
Definition: params.h:44
smlt
Definition: animation.cpp:25
smlt::Light
Definition: light.h:34
smlt::HasMutableRenderPriority
Definition: renderable.h:38
smlt::Scene
Definition: scene.h:94
smlt::batcher::RenderQueue
Definition: render_queue.h:169
smlt::Color
Definition: color.h:32
smlt::Camera
Definition: camera.h:17
smlt::StageNode
Definition: stage_node.h:442
smlt::Seconds
Definition: types.h:55
smlt::Debug
Definition: debug.h:28
smlt::SubMesh
Definition: submesh.h:42
smlt::Viewport
Definition: viewport.h:44