diff --git a/.idea/editor.xml b/.idea/editor.xml
index f0ef147..03c3e18 100644
--- a/.idea/editor.xml
+++ b/.idea/editor.xml
@@ -81,7 +81,7 @@
-
+
@@ -283,244 +283,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 9c64fcb..0c8d3c8 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -49,7 +49,7 @@ macro(blt_add_project name source type)
project(4p78-final-project)
endmacro()
-project(4p78-final-project VERSION 0.0.6)
+project(4p78-final-project VERSION 0.0.7)
option(ENABLE_ADDRSAN "Enable the address sanitizer" OFF)
option(ENABLE_UBSAN "Enable the ub sanitizer" OFF)
diff --git a/src/main.cpp b/src/main.cpp
index 6be546b..cb45b5d 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -14,14 +14,16 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
+#include
#include
+#include
#include
+#include
+#include
#include
#include "blt/gfx/renderer/batch_2d_renderer.h"
#include "blt/gfx/renderer/camera.h"
#include "blt/gfx/renderer/resource_manager.h"
-#include
-#include
#ifdef __EMSCRIPTEN__
#include
@@ -31,10 +33,14 @@
blt::gfx::matrix_state_manager global_matrices;
blt::gfx::resource_manager resources;
blt::gfx::batch_renderer_2d renderer_2d(resources, global_matrices);
-blt::gfx::first_person_camera camera;
+blt::gfx::font_renderer_t fr2d{};
+blt::gfx::first_person_camera_2d camera;
std::array buffer;
size_t last_time_ran = 0;
+size_t last_time_ran1 = 0;
+
+bool ready = false;
struct everything_t
{
@@ -53,34 +59,97 @@ struct everything_t
blt::vec3f aaWorld;
};
+struct needed_t
+{
+ float yaw = 0;
+ float distance = 0;
+ blt::vec2f position;
+};
+
blt::vec2 current_position;
-void check_for_request()
+struct boy_trust_t
{
+ std::deque point_cloud;
+ std::vector lines;
+
+ void consolidate(const blt::u64 run_time)
+ {
+ const auto cur_time = blt::system::getCurrentTimeMilliseconds();
+ if (cur_time - last_time_ran1 > run_time)
+ {
+ last_time_ran1 = cur_time;
+ // constexpr float min_dist = 5;
+ // for (auto [i, a] : enumerate(point_cloud))
+ // {
+ // for (auto [j, b] : enumerate(point_cloud))
+ // {
+ // if (i == j)
+ // continue;
+ // auto diff = (a - b).abs();
+ // if (diff.x() < min_dist && diff.y() < min_dist)
+ // {
+ //
+ // }
+ // }
+ // }
+ }
+ }
+} point_data;
+
+bool check_for_request(needed_t& data)
+{
+ if (!ready)
+ return false;
const auto cur_time = blt::system::getCurrentTimeMilliseconds();
- if (cur_time - last_time_ran > 250)
+ if (cur_time - last_time_ran > 100)
{
last_time_ran = cur_time;
const std::string_view bad_code{buffer.data()};
+ if (bad_code.empty())
+ return false;
const std::string this_is_terrible{bad_code};
const auto result = blt::requests::send_get_request("http://" + this_is_terrible + "/get_stuff_bin");
- if (result.size() != sizeof(everything_t))
+ if (result.size() != sizeof(needed_t))
{
- BLT_WARN("Size of string from ESP32 ({}) doesn't match the size of the struct ({})", result.size(), sizeof(everything_t));
- return;
+ BLT_WARN("Got string {}", result);
+ BLT_WARN("Size of string from ESP32 ({}) doesn't match the size of the struct ({})", result.size(), sizeof(needed_t));
+ return false;
}
- everything_t data;
- std::memcpy(&data, result.data(), sizeof(everything_t));
+ std::memcpy(&data, result.data(), sizeof(needed_t));
+ data.position *= 25.4;
+ data.yaw = static_cast(2 * blt::PI) - data.yaw;
+ // blt::mem::fromBytes(result.data(), data.yaw);
+ // blt::mem::fromBytes(result.data() + sizeof(float), data.distance);
+ // blt::mem::fromBytes(result.data() + sizeof(float) * 2, data.position);
+ // BLT_TRACE("STRING {}", result);
+ // BLT_TRACE("GOT {} {} {} {}", data.yaw, data.distance, data.position.x(), data.position.y());
+ return true;
}
+ return false;
+}
+
+void handle_data(needed_t& data)
+{
+ if (data.distance > 8000)
+ return;
+ blt::vec2f current_position;
+ current_position[0] = data.position[0] + data.distance * std::cos(data.yaw + static_cast(blt::PI/2.0f));
+ current_position[1] = data.position[1] + data.distance * std::sin(data.yaw + static_cast(blt::PI/2.0f));
+ point_data.point_cloud.push_back(current_position);
}
void init(const blt::gfx::window_data&)
{
using namespace blt::gfx;
+ std::memset(buffer.data(), 0, buffer.size());
+ std::strcpy(buffer.data(), "192.168.5.11");
+
global_matrices.create_internals();
resources.load_resources();
renderer_2d.create();
+ fr2d.create_default(250, 2048);
}
void update(const blt::gfx::window_data& data)
@@ -91,15 +160,49 @@ void update(const blt::gfx::window_data& data)
camera.update_view(global_matrices);
global_matrices.update();
+ static float point_size = 25;
+
ImGui::SetNextWindowSize(ImVec2(300, static_cast(data.height)));
ImGui::SetNextWindowPos(ImVec2(0, 0));
if (ImGui::Begin("Settings", nullptr, ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize))
{
ImGui::InputText("IP Address", buffer.data(), buffer.size());
+ ImGui::Checkbox("Run", &ready);
+ ImGui::InputFloat("Point Size", &point_size);
+
+ if (ImGui::CollapsingHeader("Point Consolidation"))
+ {
+ static bool run_point = false;
+ static int run_time = 100;
+ ImGui::Checkbox("Run", &run_point);
+ ImGui::InputInt("Run Time", &run_time);
+ if (run_point)
+ point_data.consolidate(static_cast(run_time));
+ }
}
ImGui::End();
+ static needed_t robot_data;
+ if (check_for_request(robot_data))
+ {
+ handle_data(robot_data);
+ }
+ renderer_2d.drawPoint(blt::gfx::point2d_t{robot_data.position, 35}, blt::make_color(0, 0, 1), 3);
+ renderer_2d.drawLine(blt::gfx::line2d_t{robot_data.position, {0, 0}}, blt::make_color(0, 0, 1), 2);
+ fr2d.render_text("Yaw " + std::to_string(robot_data.yaw), 32).setPosition(robot_data.position + blt::vec2{10, 0});
+
+ blt::vec2f current_position;
+ current_position[0] = robot_data.position[0] + 100 * std::cos(robot_data.yaw);
+ current_position[1] = robot_data.position[1] + 100 * std::sin(robot_data.yaw);
+ renderer_2d.drawLine(blt::gfx::line2d_t{robot_data.position, current_position}, blt::make_color(1, 0, 0), 2);
+
+ for (const auto& point_cloud : point_data.point_cloud)
+ renderer_2d.drawPoint(blt::gfx::point2d_t{point_cloud, point_size}, blt::make_color(0, 1, 0), 1);
+ for (const auto& line : point_data.lines)
+ renderer_2d.drawLine(line, blt::make_color(1, 0, 0), 0);
+
renderer_2d.render(data.width, data.height);
+ fr2d.render();
}
void destroy(const blt::gfx::window_data&)
@@ -107,6 +210,7 @@ void destroy(const blt::gfx::window_data&)
global_matrices.cleanup();
resources.cleanup();
renderer_2d.cleanup();
+ fr2d.cleanup();
blt::gfx::cleanup();
}