18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-12-02 02:42:46 +01:00

feat(editor): the cab of a vehicle edited in the Models mode, from the seat of the driver

The cab of a vehicle is loaded only by getting in. "Get in the cab" in the Models mode does what the
simulation does then: it makes the train of the vehicle (TTrain::Init loads the cab, its controls and its
sounds), makes it the vehicle driven, and puts the camera in the seat of the driver. While the cab is edited
the editor draws it as from that seat: FreeFlyModeFlag is off and the vehicle owns the camera, which moves
with it by its offset (the sounds read the owner of the camera then). With the body picked, or in another
field of work, the view is free again.

A new self-test command, modelvehicle <name> [cab], picks a vehicle and gets in its cab. Tested on the
EU07-424 (303e-tv) with a light added to its cab.
This commit is contained in:
maj00r
2026-11-29 23:00:52 +01:00
parent 6828e52a45
commit 42e0884606
7 changed files with 173 additions and 8 deletions
+57
View File
@@ -16,6 +16,8 @@ http://mozilla.org/MPL/2.0/.
#include <regex>
#include <optional>
#include "application/editormode.h"
#include "vehicle/DynObj.h"
#include "vehicle/Train.h"
#include "application/editormodeshared.h"
#include "application/editorgestures.h"
#include "scene/scenenodegroups.h"
@@ -566,6 +568,7 @@ editor_mode::editor_mode() {
ui()->set_workspace_bank(editor_ui::workspace::models, [this]() { ui()->model_panel().render_bank(); }, STR("Model"));
ui()->set_edit_model([this]() { choose_work_area(work_area::models); });
ui()->model_panel().place_model = [this](std::string const &File) { place_model_file(File); };
ui()->model_panel().enter_cab = [this](TDynamicObject &Vehicle) { return enter_cab(Vehicle); };
ui()->model_panel().place_vehicle = [this]() {
// the Trainset tool of the tracks: a click on a track, the vehicle picked, Place
choose_work_area(work_area::tracks);
@@ -1744,6 +1747,26 @@ bool editor_mode::update()
update_road_tool();
draw_road_overlay();
// the roads and the terrain are fields of work, their tools are drawn in the tool options window in place of the edit mode ones
// the cab of the vehicle driven is drawn while it's edited in the field of work of the models, as from the seat of the driver
{
auto const &panel{ui()->model_panel()};
auto const cabview{m_models_open && panel.shows_cab() && simulation::Train != nullptr && simulation::Train->Dynamic() == panel.vehicle()};
if (cabview != m_cabview)
{
// the view from the cab has the vehicle as the owner of the camera (the sounds and the drops on the glass go by it), the
// free view none
m_cabview = cabview;
FreeFlyModeFlag = false == cabview;
if (false == cabview)
Camera.m_owner = nullptr;
else if (Camera.m_owner != panel.vehicle())
{
Camera.m_owner = panel.vehicle();
Camera.m_owneroffset = simulation::Train->pMechSittingPosition;
}
Global.pCamera = Camera;
}
}
ui()->set_workspace([this]() {
if (m_models_open)
return editor_ui::workspace::models;
@@ -5826,6 +5849,36 @@ void editor_mode::choose_edit_mode(nodebank_panel::edit_mode const Mode)
ui()->set_mode(Mode);
}
bool editor_mode::enter_cab(TDynamicObject &Vehicle)
{
// the train of the vehicle, made as the simulation makes it when someone gets in: it loads the cab
auto *train{simulation::Trains.find(Vehicle.name())};
if (train == nullptr)
{
train = new TTrain();
if (false == train->Init(&Vehicle))
{
delete train;
ui()->set_status(format(STR_C("The cab of %s couldn't be loaded, the log says why"), Vehicle.name().c_str()), true);
return false;
}
simulation::Trains.insert(train);
}
simulation::Train = train;
if ((Vehicle.mdKabina == nullptr) || (Vehicle.mdKabina == Vehicle.mdModel))
return false;
// in the seat of the driver, looking ahead from the cab taken
auto const side{Vehicle.MoverParameters->CabOccupied < 0 ? -1.0 : 1.0};
auto const look{Vehicle.VectorFront() * side};
Camera.Pos = Vehicle.GetWorldPosition(train->pMechSittingPosition);
Camera.Angle = glm::vec3(0.0f, static_cast<float>(std::atan2(-look.x, -look.z)), 0.0f);
Camera.m_owner = &Vehicle;
Camera.m_owneroffset = train->pMechSittingPosition;
Global.pCamera = Camera;
ui()->set_status(format(STR_C("In the cab of %s; the editor draws it while the cab is edited"), Vehicle.name().c_str()));
return true;
}
void editor_mode::place_model_file(std::string const &File)
{
// on the ground some way ahead of the camera, as far as Insert would put it by a click there
@@ -7549,6 +7602,9 @@ void editor_mode::on_scroll(double const Xoffset, double const Yoffset)
void editor_mode::update_camera(double const Deltatime)
{
Camera.Update();
// in the cab the camera moves with the vehicle, by its offset in it, as the camera of the driver does
if (m_cabview && Camera.m_owner != nullptr)
Camera.Pos = Camera.m_owner->GetWorldPosition(Camera.m_owneroffset);
if (Global.EditorOrtho)
{
Camera.Angle.x = -M_PI_2;
@@ -7642,6 +7698,7 @@ void editor_mode::ride_enter()
void editor_mode::enter()
{
m_statebackup = {Global.pCamera, FreeFlyModeFlag, Global.ControlPicking};
m_cabview = false; // the view from outside to start with, the cab is drawn again once it's edited
// the editor changes the tracks, their sleepers are worked out as they're needed
track_sleepers::lay_in_background(false);
// the editor may remove the tracks and the vehicles the recording refers to: it ends here