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