Elaztek Developer Hub
Blamite Game Engine - blam!  00310.02.05.21.0336.blamite
The core library for the Blamite Game Engine.
geometry_test.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include "../../debug_ui.h"
4 #include "components/3rdparty/imgui/extensions/imgui_extensions.h"
5 
7 
8 struct Triangle
9 {
10  uint16_t x;
11  uint16_t y;
12  uint16_t z;
13 };
14 
15 namespace Blam::DebugUI::Windows
16 {
25  {
26  private:
27  std::vector<Triangle> triangles = {
28  {0, 1, 2},
29  {1, 3, 2},
30  {4, 6, 5},
31  {5, 6, 7},
32  {0, 2, 4},
33  {4, 2, 6},
34  {1, 5, 3},
35  {5, 7, 3},
36  {0, 4, 1},
37  {4, 5, 1},
38  {2, 3, 6},
39  {6, 3, 7}
40  };
41 
42  std::vector<PosColorVertex> verticies = {
43  {-1.0f, 1.0f, 1.0f, 0xff000000 },
44  { 1.0f, 1.0f, 1.0f, 0xff0000ff },
45  {-1.0f, -1.0f, 1.0f, 0xff00ff00 },
46  { 1.0f, -1.0f, 1.0f, 0xff00ffff },
47  {-1.0f, 1.0f, -1.0f, 0xffff0000 },
48  { 1.0f, 1.0f, -1.0f, 0xffff00ff },
49  {-1.0f, -1.0f, -1.0f, 0xffffff00 },
50  { 1.0f, -1.0f, -1.0f, 0xffffffff },
51  };
52 
53  bool auto_rebuild = false;
54  int delete_triangle_at = -1;
55  int delete_vertex_at = -1;
56 
57  public:
60 
61  void Draw()
62  {
63  // shows all network info too be noted..
64  if (show)
65  {
66  if (ImGui::Begin("Geometry Test", &show))
67  {
68  ImGui::Checkbox("auto rebuild", &auto_rebuild);
69 
71 
72  if (ImGui::CollapsingHeader("triangles"))
73  {
74  ImGui::PushID("triangle_controls");
75 
76  if (ImGui::Button("+"))
77  {
78  triangles.push_back(Triangle());
79  }
80  ImGui::SameLine();
81  if (ImGui::Button("delete @"))
82  {
83  if (delete_triangle_at < triangles.size() && delete_triangle_at > -1)
84  {
85  triangles.erase(triangles.begin() + delete_triangle_at);
86  }
87  }
88  ImGui::SameLine();
89  ImGui::InputInt("index", &delete_triangle_at);
90 
91  ImGui::PopID();
92 
93  ImGui::Separator();
94 
95  for (int i = 0; i < triangles.size(); i++)
96  {
97  ImGui::PushItemWidth(250.0f);
98  ImGui::PushID(std::string("triangle_i_" + std::to_string(i)).c_str());
99 
100  Triangle* triangle = &triangles.at(i);
101  ImGui::InputShort("x", (short*)&triangle->x, 1, 10, NULL);
102  ImGui::SameLine();
103  ImGui::InputShort("y", (short*)&triangle->y, 1, 10, NULL);
104  ImGui::SameLine();
105  ImGui::InputShort("z", (short*)&triangle->z, 1, 10, NULL);
106 
107  ImGui::PopID();
108  ImGui::PopItemWidth();
109  }
110  }
111 
112  if (ImGui::CollapsingHeader("verticies"))
113  {
114  ImGui::PushID("vertex_controls");
115 
116  if (ImGui::Button("+"))
117  {
118  verticies.push_back(PosColorVertex());
119  }
120  ImGui::SameLine();
121  if (ImGui::Button("delete @"))
122  {
123  if (delete_vertex_at < verticies.size() && delete_vertex_at > -1)
124  {
125  verticies.erase(verticies.begin() + delete_vertex_at);
126  }
127  }
128  ImGui::SameLine();
129  ImGui::InputInt("index", &delete_vertex_at);
130 
131  ImGui::PopID();
132 
133  ImGui::Separator();
134 
135  for (int i = 0; i < verticies.size(); i++)
136  {
137  ImGui::PushItemWidth(250.0f);
138  ImGui::PushID(std::string("vertex_i_" + std::to_string(i)).c_str());
139 
140  PosColorVertex* vertex = &verticies.at(i);
141  ImGui::InputFloat("x", &vertex->x);
142  ImGui::SameLine();
143  ImGui::InputFloat("y", &vertex->y);
144  ImGui::SameLine();
145  ImGui::InputFloat("z", &vertex->z);
146 
147  ImVec4 color = ImGui::ColorConvertU32ToFloat4(vertex->abgr);
148 
149  ImGui::ColorEdit4("color", (float*)&color);
150 
151  vertex->abgr = ImGui::ColorConvertFloat4ToU32(color);
152 
153  ImGui::PopItemWidth();
154  ImGui::PopID();
155  }
156  }
157 
158  if (auto_rebuild)
159  {
160  ImGui::TextDisabled("model data is automatically rebuilt");
161 
162  model->verticies = verticies;
163 
164  std::vector<uint16_t> triangles_raw = {};
165 
166  for (Triangle t : triangles)
167  {
168  triangles_raw.push_back(t.x);
169  triangles_raw.push_back(t.y);
170  triangles_raw.push_back(t.z);
171  }
172 
173  model->triangles = triangles_raw;
174 
175  model->Rebuild();
176  }
177  else
178  {
179  if (ImGui::Button("rebuild model data"))
180  {
181  model->verticies = verticies;
182 
183  std::vector<uint16_t> triangles_raw = {};
184 
185  for (Triangle t : triangles)
186  {
187  triangles_raw.push_back(t.x);
188  triangles_raw.push_back(t.y);
189  triangles_raw.push_back(t.z);
190  }
191 
192  model->triangles = triangles_raw;
193 
194  model->Rebuild();
195  }
196  }
197  }
198 
199  ImGui::End();
200  }
201 
202  }
203  };
204 }
Blam::DebugUI::Windows::GeometryTest::Draw
void Draw()
Draws the contents of the group.
Definition: geometry_test.hpp:61
BlamRenderModel::Rebuild
void Rebuild()
Definition: models.h:93
PosColorVertex::y
float y
Definition: models.h:17
BlamRenderModel
Definition: models.h:22
BlamRenderModel::verticies
std::vector< PosColorVertex > verticies
Definition: models.h:29
color
@ color
Definition: render_model.h:13
Triangle::z
uint16_t z
Definition: geometry_test.hpp:12
Triangle::x
uint16_t x
Definition: geometry_test.hpp:10
PosColorVertex::abgr
uint32_t abgr
Definition: models.h:19
Blam::DebugUI::ImGUIDrawingGroup::show
bool show
Controls whether or not the group should be shown. May not be used in all groups.
Definition: debug_ui.h:362
PosColorVertex
Definition: models.h:14
Blam::DebugUI::ImGUIDrawingGroup
Class representing an ImGUI drawing group/draw list item.
Definition: debug_ui.h:359
BlamRendering::Models::GetTestModel
BLAM BlamRenderModel * GetTestModel()
Definition: models.cpp:15
PosColorVertex::z
float z
Definition: models.h:18
PosColorVertex::x
float x
Definition: models.h:16
Triangle
Definition: geometry_test.hpp:8
Blam::DebugUI::Windows::GeometryTest::~GeometryTest
~GeometryTest()
Definition: geometry_test.hpp:59
models.h
Blam::DebugUI::Windows::GeometryTest::GeometryTest
GeometryTest()
Definition: geometry_test.hpp:58
Blam::DebugUI::Windows::GeometryTest
Class for the Geometry Test dialog.
Definition: geometry_test.hpp:24
Triangle::y
uint16_t y
Definition: geometry_test.hpp:11
Blam::DebugUI::Windows
Legacy namespace to contain data for the legacy ImGUI console.
Definition: debug_ui.h:434
BlamRenderModel::triangles
std::vector< uint16_t > triangles
Definition: models.h:30