Skip to content
Snippets Groups Projects
Commit 137e770c authored by Pascal Engeler's avatar Pascal Engeler
Browse files

Added leveler, loader

parent aa26b3cc
No related branches found
No related tags found
No related merge requests found
#pragma once
#include <glm/glm.hpp>
#include <glm/gtc/type_ptr.hpp>
class Leveler {
public:
static void update_leveler();
static void place(glm::vec2);
static bool fetchingP1;
static bool fetchingP2;
static bool fetchingP3;
static bool transformationValid;
static glm::mat4 transformation; //only rotations and translations along z in here
private:
static glm::vec2 _p1;
static glm::vec2 _p2;
static glm::vec2 _p3;
};
\ No newline at end of file
#pragma once
#include <heightmap.hpp>
#include <resource_manager.h>
#include <memory>
#include <utility.hpp>
class Loader {
public:
static bool load_update();
static std::shared_ptr<Heightmap> getHeightmap();
private:
static std::shared_ptr<Heightmap> _heightmap;
static char _buf[128];
};
\ No newline at end of file
#include <leveler.hpp>
#include <imgui_bundle.hpp>
#include <string>
bool Leveler::fetchingP1 = false;
bool Leveler::fetchingP2 = false;
bool Leveler::fetchingP3 = false;
bool Leveler::transformationValid = false;
glm::vec2 Leveler::_p1;
glm::vec2 Leveler::_p2;
glm::vec2 Leveler::_p3;
void Leveler::update_leveler() {
ImGui::Begin("Leveler", nullptr);
ImGui::Text("Status: ");
if (fetchingP1) {
ImGui::Text("Fetching P1");
}
else if (fetchingP2) {
ImGui::Text("Fetching P2");
}
else if (fetchingP3) {
ImGui::Text("Fetching P3");
}
else {
ImGui::Text("Idle");
}
ImGui::Text("Plane identified: ");
if (transformationValid) {
//Write down plane equation here
}
else {
ImGui::Text("N/A");
}
ImGui::Text("P1: ");
ImGui::SameLine();
std::string pstr = "(" + std::to_string(_p1.x) + ", " + std::to_string(_p1.y) + ")";
if (fetchingP1) {
pstr = "";
}
ImGui::Text(pstr.c_str());
ImGui::Text("P2: ");
ImGui::SameLine();
pstr = "(" + std::to_string(_p2.x) + ", " + std::to_string(_p2.y) + ")";
if (fetchingP1 || fetchingP2) {
pstr = "";
}
ImGui::Text(pstr.c_str());
ImGui::Text("P3: ");
ImGui::SameLine();
pstr = "(" + std::to_string(_p3.x) + ", " + std::to_string(_p3.y) + ")";
if (fetchingP1 || fetchingP2 || fetchingP3) {
pstr = "";
}
ImGui::Text(pstr.c_str());
ImGui::Text("");
if (ImGui::Button("Place")) {
transformationValid = false;
fetchingP1 = true;
fetchingP2 = false;
fetchingP3 = false;
}
ImGui::End();
}
void Leveler::place(glm::vec2 p) {
if (fetchingP1) {
_p1 = p;
fetchingP1 = false;
fetchingP2 = true;
}
else if (fetchingP2) {
_p2 = p;
fetchingP2 = false;
fetchingP3 = true;
}
else if (fetchingP3) {
_p3 = p;
fetchingP3 = false;
//TODO: calculate transformation here
}
}
\ No newline at end of file
#include <loader.hpp>
#include <imgui_bundle.hpp>
#include <string>
std::shared_ptr<Heightmap> Loader::_heightmap;
char Loader::_buf[128] = "";
bool Loader::load_update() {
bool load_successful = false;
ImGui::Begin("Heightmap Loader", nullptr);
ImGui::InputText("Filename", _buf, 128);
ImGui::SameLine();
if (ImGui::Button("Load")) {
//Load heightmap here
try {
_heightmap = ResourceManager::fetch_heightmap(std::string(_buf));
load_successful = true;
}
catch (...) {
std::cerr << "Loader::load_update: Failed to load heightmap from " << std::string(_buf) << ":\n" << std::endl;
return false;
}
}
ImGui::End();
return load_successful;
}
std::shared_ptr<Heightmap> Loader::getHeightmap() {
return _heightmap;
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment