mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-07-23 00:29:19 +02:00
map improvements
This commit is contained in:
@@ -6296,7 +6296,7 @@ std::string TController::Relation() const
|
|||||||
return TrainParams->ShowRelation();
|
return TrainParams->ShowRelation();
|
||||||
};
|
};
|
||||||
|
|
||||||
std::string TController::TrainName() const
|
const std::string& TController::TrainName() const
|
||||||
{ // zwraca numer pociągu
|
{ // zwraca numer pociągu
|
||||||
return TrainParams->TrainName;
|
return TrainParams->TrainName;
|
||||||
};
|
};
|
||||||
|
|||||||
2
Driver.h
2
Driver.h
@@ -380,7 +380,7 @@ private:
|
|||||||
// timetable
|
// timetable
|
||||||
// methods
|
// methods
|
||||||
public:
|
public:
|
||||||
std::string TrainName() const;
|
const std::string &TrainName() const;
|
||||||
private:
|
private:
|
||||||
std::string Relation() const;
|
std::string Relation() const;
|
||||||
Mtable::TTrainParameters const * TrainTimetable() const;
|
Mtable::TTrainParameters const * TrainTimetable() const;
|
||||||
|
|||||||
12
Event.cpp
12
Event.cpp
@@ -2230,3 +2230,15 @@ event_manager::export_as_text( std::ostream &Output ) const {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector<TEventLauncher*> event_manager::find_eventlaunchers(glm::vec2 center, float radius) const {
|
||||||
|
std::vector<TEventLauncher *> results;
|
||||||
|
|
||||||
|
for (auto &launcher : m_launchers.sequence()) {
|
||||||
|
glm::dvec3 location = launcher->location();
|
||||||
|
if (glm::distance2(glm::vec2(location.x, location.z), center) < radius)
|
||||||
|
results.push_back(launcher);
|
||||||
|
}
|
||||||
|
|
||||||
|
return results;
|
||||||
|
}
|
||||||
|
|||||||
3
Event.h
3
Event.h
@@ -615,6 +615,9 @@ public:
|
|||||||
// sends basic content of the class in legacy (text) format to provided stream
|
// sends basic content of the class in legacy (text) format to provided stream
|
||||||
void
|
void
|
||||||
export_as_text( std::ostream &Output ) const;
|
export_as_text( std::ostream &Output ) const;
|
||||||
|
// returns all eventlaunchers in radius ignoring height
|
||||||
|
std::vector<TEventLauncher *>
|
||||||
|
find_eventlaunchers(glm::vec2 center, float radius) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// types
|
// types
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ public:
|
|||||||
std::deque<text_line> text_lines;
|
std::deque<text_line> text_lines;
|
||||||
int window_flags = -1;
|
int window_flags = -1;
|
||||||
|
|
||||||
std::string get_name() { return name; }
|
const std::string& get_name() { return name; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// members
|
// members
|
||||||
|
|||||||
222
widgets/map.cpp
222
widgets/map.cpp
@@ -58,74 +58,12 @@ float ui::map_panel::get_vehicle_rotation()
|
|||||||
{
|
{
|
||||||
const TDynamicObject *vehicle = simulation::Train->Dynamic();
|
const TDynamicObject *vehicle = simulation::Train->Dynamic();
|
||||||
glm::vec3 front = glm::dvec3(vehicle->VectorFront()) * (vehicle->DirectionGet() > 0 ? 1.0 : -1.0);
|
glm::vec3 front = glm::dvec3(vehicle->VectorFront()) * (vehicle->DirectionGet() > 0 ? 1.0 : -1.0);
|
||||||
glm::vec2 f2(front.x, front.z);
|
|
||||||
glm::vec2 north_ptr(0.0f, 1.0f);
|
glm::vec2 north_ptr(0.0f, 1.0f);
|
||||||
return glm::atan(f2.y, f2.x) - glm::atan(north_ptr.y, north_ptr.x);
|
return glm::atan(front.z, front.x) - glm::atan(north_ptr.y, north_ptr.x);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ui::map_panel::render_contents()
|
void ui::map_panel::render_map_texture(glm::mat4 transform, glm::vec2 surface_size) {
|
||||||
{
|
cFrustum frustum;
|
||||||
if (!init_done)
|
|
||||||
return;
|
|
||||||
|
|
||||||
scene::basic_region *Region = simulation::Region;
|
|
||||||
|
|
||||||
float prevzoom = zoom;
|
|
||||||
|
|
||||||
if (ImGui::Button("-"))
|
|
||||||
zoom /= 2;
|
|
||||||
ImGui::SameLine();
|
|
||||||
if (ImGui::Button("+"))
|
|
||||||
zoom *= 2;
|
|
||||||
ImGui::SameLine();
|
|
||||||
|
|
||||||
float x = zoom / prevzoom;
|
|
||||||
translate *= x;
|
|
||||||
|
|
||||||
glm::mat4 transform;
|
|
||||||
transform[0][0] = -1.0f;
|
|
||||||
|
|
||||||
static int mode = 0;
|
|
||||||
ImGui::RadioButton("manual", &mode, 0); ImGui::SameLine();
|
|
||||||
ImGui::RadioButton("cam", &mode, 1); ImGui::SameLine();
|
|
||||||
ImGui::RadioButton("vehicle", &mode, 2);
|
|
||||||
|
|
||||||
ImVec2 size = ImGui::GetContentRegionAvail();
|
|
||||||
|
|
||||||
float aspectx = size.y / size.x;
|
|
||||||
float aspectz = size.x / size.y;
|
|
||||||
|
|
||||||
if (aspectx > aspectz)
|
|
||||||
transform = glm::scale(transform, glm::vec3(aspectx, 1.0f, 1.0f));
|
|
||||||
else
|
|
||||||
transform = glm::scale(transform, glm::vec3(1.0f, 1.0f, aspectz));
|
|
||||||
|
|
||||||
if (mode == 2 && simulation::Train && simulation::Train->Dynamic())
|
|
||||||
{
|
|
||||||
float rot = get_vehicle_rotation();
|
|
||||||
|
|
||||||
transform = glm::rotate(transform, rot, glm::vec3(0.0f, 1.0f, 0.0f));
|
|
||||||
|
|
||||||
glm::dvec3 vpos = simulation::Train->Dynamic()->GetPosition();
|
|
||||||
translate = glm::vec2(vpos.x, vpos.z) * -zoom;
|
|
||||||
}
|
|
||||||
else if (mode == 1)
|
|
||||||
{
|
|
||||||
float rot;
|
|
||||||
if (FreeFlyModeFlag)
|
|
||||||
rot = glm::pi<float>() - Global.pCamera.Angle.y;
|
|
||||||
else
|
|
||||||
rot = get_vehicle_rotation() - Global.pCamera.Angle.y;
|
|
||||||
|
|
||||||
transform = glm::rotate(transform, rot, glm::vec3(0.0f, 1.0f, 0.0f));
|
|
||||||
|
|
||||||
glm::dvec3 vpos = Global.pCamera.Pos;
|
|
||||||
translate = glm::vec2(vpos.x, vpos.z) * -zoom;
|
|
||||||
}
|
|
||||||
|
|
||||||
transform = glm::translate(transform, glm::vec3(translate.x, 0.0f, translate.y));
|
|
||||||
transform = glm::scale(transform, glm::vec3(zoom));
|
|
||||||
|
|
||||||
frustum.calculate(transform, glm::mat4());
|
frustum.calculate(transform, glm::mat4());
|
||||||
|
|
||||||
m_section_handles.clear();
|
m_section_handles.clear();
|
||||||
@@ -134,10 +72,10 @@ void ui::map_panel::render_contents()
|
|||||||
{
|
{
|
||||||
for (int column = 0; column < scene::EU07_REGIONSIDESECTIONCOUNT; column++)
|
for (int column = 0; column < scene::EU07_REGIONSIDESECTIONCOUNT; column++)
|
||||||
{
|
{
|
||||||
scene::basic_section *s = Region->get_section(row * scene::EU07_REGIONSIDESECTIONCOUNT + column);
|
scene::basic_section *section = simulation::Region->get_section(row * scene::EU07_REGIONSIDESECTIONCOUNT + column);
|
||||||
if (s && frustum.sphere_inside(s->area().center, s->area().radius) > 0.f)
|
if (section && frustum.sphere_inside(section->area().center, section->area().radius) > 0.f)
|
||||||
{
|
{
|
||||||
const gfx::geometrybank_handle handle = s->get_map_geometry();
|
const gfx::geometrybank_handle handle = section->get_map_geometry();
|
||||||
if (handle != null_handle)
|
if (handle != null_handle)
|
||||||
m_section_handles.push_back(handle);
|
m_section_handles.push_back(handle);
|
||||||
}
|
}
|
||||||
@@ -162,46 +100,152 @@ void ui::map_panel::render_contents()
|
|||||||
|
|
||||||
m_shader->bind();
|
m_shader->bind();
|
||||||
glLineWidth(1.5f);
|
glLineWidth(1.5f);
|
||||||
glViewport(0, 0, size.x, size.y);
|
glViewport(0, 0, surface_size.x, surface_size.y);
|
||||||
|
|
||||||
GfxRenderer.Draw_Geometry(m_section_handles.begin(), m_section_handles.end());
|
GfxRenderer.Draw_Geometry(m_section_handles.begin(), m_section_handles.end());
|
||||||
|
|
||||||
if (Global.iMultisampling)
|
if (Global.iMultisampling)
|
||||||
m_fb->blit_from(m_msaa_fb.get(), size.x, size.y, GL_COLOR_BUFFER_BIT, GL_COLOR_ATTACHMENT0);
|
m_fb->blit_from(m_msaa_fb.get(), surface_size.x, surface_size.y, GL_COLOR_BUFFER_BIT, GL_COLOR_ATTACHMENT0);
|
||||||
|
|
||||||
gl::framebuffer::unbind();
|
gl::framebuffer::unbind();
|
||||||
m_shader->unbind();
|
m_shader->unbind();
|
||||||
|
|
||||||
ImVec2 origin = ImGui::GetCursorPos();
|
|
||||||
ImGui::ImageButton(reinterpret_cast<void*>(m_tex->id), size, ImVec2(0, size.y / fb_size), ImVec2(size.x / fb_size, 0), 0);
|
|
||||||
if (mode == 0 && ImGui::IsItemHovered() && ImGui::IsMouseDragging())
|
|
||||||
{
|
|
||||||
ImVec2 ivdelta = ImGui::GetMouseDragDelta();
|
|
||||||
ImGui::ResetMouseDragDelta();
|
|
||||||
|
|
||||||
glm::vec2 delta(ivdelta.x, ivdelta.y);
|
|
||||||
delta.x /= size.x;
|
|
||||||
delta.y /= size.y;
|
|
||||||
|
|
||||||
translate -= delta * 2.0f;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ui::map_panel::render_labels(glm::mat4 transform, ImVec2 origin, glm::vec2 surface_size)
|
||||||
|
{
|
||||||
ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(0.7f, 1.0f, 0.7f, 1.0f));
|
ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(0.7f, 1.0f, 0.7f, 1.0f));
|
||||||
for (TDynamicObject *vehicle : simulation::Vehicles.sequence()) {
|
for (TDynamicObject *vehicle : simulation::Vehicles.sequence()) {
|
||||||
if (vehicle->Prev())
|
if (vehicle->Prev() || !vehicle->Mechanik)
|
||||||
|
continue;
|
||||||
|
if (vehicle->Mechanik->TrainName().empty())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
glm::vec4 pos = transform * glm::vec4(glm::vec3(vehicle->GetPosition()), 1.0f);
|
glm::vec4 ndc_pos = transform * glm::vec4(glm::vec3(vehicle->GetPosition()), 1.0f);
|
||||||
if (glm::abs(pos.x) > 1.0f || glm::abs(pos.z) > 1.0f)
|
if (glm::abs(ndc_pos.x) > 1.0f || glm::abs(ndc_pos.z) > 1.0f)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
glm::vec2 textpos = (glm::vec2(pos.x, -pos.z) / 2.0f + 0.5f) * glm::vec2(size.x, size.y);
|
glm::vec2 gui_pos = (glm::vec2(ndc_pos.x, -ndc_pos.z) / 2.0f + 0.5f) * glm::vec2(surface_size.x, surface_size.y);
|
||||||
|
|
||||||
|
TDynamicObject *veh = vehicle;
|
||||||
|
|
||||||
const char *desc = vehicle->Mechanik->TrainName().c_str();
|
const char *desc = vehicle->Mechanik->TrainName().c_str();
|
||||||
ImVec2 textsize = ImGui::CalcTextSize(desc);
|
ImVec2 textsize = ImGui::CalcTextSize(desc);
|
||||||
ImGui::SetCursorPos(ImVec2(origin.x + textpos.x - textsize.x / 2.0f,
|
ImGui::SetCursorPos(ImVec2(origin.x + gui_pos.x - textsize.x / 2.0f,
|
||||||
origin.y + textpos.y - textsize.y / 2.0f));
|
origin.y + gui_pos.y - textsize.y / 2.0f));
|
||||||
ImGui::TextUnformatted(desc);
|
ImGui::TextUnformatted(desc);
|
||||||
}
|
}
|
||||||
ImGui::PopStyleColor();
|
ImGui::PopStyleColor();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ui::map_panel::render_contents()
|
||||||
|
{
|
||||||
|
if (!init_done)
|
||||||
|
return;
|
||||||
|
|
||||||
|
float prev_zoom = zoom;
|
||||||
|
|
||||||
|
if (ImGui::Button("-"))
|
||||||
|
zoom /= 2;
|
||||||
|
ImGui::SameLine();
|
||||||
|
|
||||||
|
if (ImGui::Button("+"))
|
||||||
|
zoom *= 2;
|
||||||
|
ImGui::SameLine();
|
||||||
|
|
||||||
|
float x = zoom / prev_zoom;
|
||||||
|
translate *= x;
|
||||||
|
|
||||||
|
glm::mat4 transform;
|
||||||
|
transform[0][0] = -1.0f;
|
||||||
|
|
||||||
|
static enum {
|
||||||
|
MODE_MANUAL = 0,
|
||||||
|
MODE_CAMERA,
|
||||||
|
MODE_VEHICLE
|
||||||
|
} mode = MODE_MANUAL;
|
||||||
|
|
||||||
|
ImGui::RadioButton("manual", (int*)&mode, 0); ImGui::SameLine();
|
||||||
|
ImGui::RadioButton("cam", (int*)&mode, 1); ImGui::SameLine();
|
||||||
|
ImGui::RadioButton("vehicle", (int*)&mode, 2);
|
||||||
|
|
||||||
|
ImVec2 surface_size_im = ImGui::GetContentRegionAvail();
|
||||||
|
glm::vec2 surface_size(surface_size_im.x, surface_size_im.y);
|
||||||
|
|
||||||
|
float aspect = surface_size.y / surface_size.x;
|
||||||
|
|
||||||
|
if (aspect > 1.0f / aspect)
|
||||||
|
transform = glm::scale(transform, glm::vec3(aspect, 1.0f, 1.0f));
|
||||||
|
else
|
||||||
|
transform = glm::scale(transform, glm::vec3(1.0f, 1.0f, 1.0f / aspect));
|
||||||
|
|
||||||
|
if (mode == MODE_VEHICLE && simulation::Train)
|
||||||
|
{
|
||||||
|
float rotation = get_vehicle_rotation();
|
||||||
|
|
||||||
|
transform = glm::rotate(transform, rotation, glm::vec3(0.0f, 1.0f, 0.0f));
|
||||||
|
|
||||||
|
glm::dvec3 position = simulation::Train->Dynamic()->GetPosition();
|
||||||
|
translate = glm::vec2(position.x, position.z) * -zoom;
|
||||||
|
}
|
||||||
|
if (mode == MODE_CAMERA)
|
||||||
|
{
|
||||||
|
float initial_rotation;
|
||||||
|
if (!FreeFlyModeFlag)
|
||||||
|
initial_rotation = get_vehicle_rotation();
|
||||||
|
else
|
||||||
|
initial_rotation = glm::pi<float>();
|
||||||
|
|
||||||
|
float rotation = initial_rotation - Global.pCamera.Angle.y;
|
||||||
|
|
||||||
|
transform = glm::rotate(transform, rotation, glm::vec3(0.0f, 1.0f, 0.0f));
|
||||||
|
|
||||||
|
glm::dvec3 position = Global.pCamera.Pos;
|
||||||
|
translate = glm::vec2(position.x, position.z) * -zoom;
|
||||||
|
}
|
||||||
|
|
||||||
|
transform = glm::translate(transform, glm::vec3(translate.x, 0.0f, translate.y));
|
||||||
|
transform = glm::scale(transform, glm::vec3(zoom));
|
||||||
|
|
||||||
|
render_map_texture(transform, surface_size);
|
||||||
|
|
||||||
|
ImVec2 window_origin = ImGui::GetCursorPos();
|
||||||
|
ImVec2 screen_origin = ImGui::GetCursorScreenPos();
|
||||||
|
ImGui::ImageButton(reinterpret_cast<void*>(m_tex->id), surface_size_im, ImVec2(0, surface_size.y / fb_size), ImVec2(surface_size.x / fb_size, 0), 0);
|
||||||
|
|
||||||
|
if (ImGui::IsItemHovered())
|
||||||
|
{
|
||||||
|
if (mode == 0 && ImGui::IsMouseDragging(0)) {
|
||||||
|
WriteLog("drag");
|
||||||
|
ImVec2 delta_im = ImGui::GetMouseDragDelta();
|
||||||
|
ImGui::ResetMouseDragDelta();
|
||||||
|
|
||||||
|
glm::vec2 delta(delta_im.x, delta_im.y);
|
||||||
|
delta.x /= surface_size.x;
|
||||||
|
delta.y /= surface_size.y;
|
||||||
|
|
||||||
|
translate -= delta * 2.0f;
|
||||||
|
}
|
||||||
|
if (ImGui::IsMouseClicked(1)) {
|
||||||
|
WriteLog("click");
|
||||||
|
ImVec2 screen_pos = ImGui::GetMousePos();
|
||||||
|
glm::vec2 surface_pos(screen_pos.x - screen_origin.x, screen_pos.y - screen_origin.y);
|
||||||
|
glm::vec2 ndc_pos = surface_pos / surface_size * 2.0f - 1.0f;
|
||||||
|
glm::vec3 world_pos = glm::inverse(transform) * glm::vec4(ndc_pos.x, 0.0f, -ndc_pos.y, 1.0f);
|
||||||
|
|
||||||
|
std::vector<TEventLauncher *> launchers = simulation::Events.find_eventlaunchers(glm::vec2(world_pos.x, world_pos.z), 10.0f);
|
||||||
|
|
||||||
|
for (auto launcher : launchers) {
|
||||||
|
command_relay relay;
|
||||||
|
if (!Global.shiftState && launcher->Event1)
|
||||||
|
relay.post(user_command::queueevent, (double)simulation::Events.GetEventId(launcher->Event1), 0.0, GLFW_PRESS, 0);
|
||||||
|
else if (launcher->Event2)
|
||||||
|
relay.post(user_command::queueevent, (double)simulation::Events.GetEventId(launcher->Event2), 0.0, GLFW_PRESS, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
WriteLog(std::to_string(world_pos.x) + "," + std::to_string(world_pos.z));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
render_labels(transform, window_origin, surface_size);
|
||||||
|
}
|
||||||
|
|||||||
@@ -25,7 +25,8 @@ class map_panel : public ui_panel {
|
|||||||
glm::vec2 translate;
|
glm::vec2 translate;
|
||||||
float zoom = 1.0f / 1000.0f;
|
float zoom = 1.0f / 1000.0f;
|
||||||
float get_vehicle_rotation();
|
float get_vehicle_rotation();
|
||||||
cFrustum frustum;
|
void render_map_texture(glm::mat4 transform, glm::vec2 surface_size);
|
||||||
|
void render_labels(glm::mat4 transform, ImVec2 origin, glm::vec2 surface_size);
|
||||||
|
|
||||||
bool init_done = false;
|
bool init_done = false;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user