mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-11-21 06:14:58 +01:00
* feat(editor): ~ shows or hides the orthophoto, Ctrl+~ downloads what the camera sees first; the speed of the camera in the View menu ~ (the key left of 1) turns the orthophoto on and off. Ctrl+~ finds what of the ground the camera sees (rays through a grid over the screen down to the level of the ground under the camera, or as far as 2.5 km where they don't come down to it) and puts those tiles at the front of the queue of the downloads, the ones which failed tried again at once; the status line tells how many. Tab is not used, the laying and the switches have it. View > Camera speed: the speed of the free camera of the editor (x0.05 to x10, 1 as it was), how many times faster Ctrl makes it (1 to 30, 30 as it was), and in the top view as fast as the view is zoomed, so the map crosses the screen at the same pace zoomed in or out. Kept in the settings of the editor; the camera of the cab and of the free fly outside the editor unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DDcMn1Q7wdYkbxDUWscNHZ * fix(editor): Ctrl+~ in the top view, over a scenery with no terrain under the camera and with the orthophoto off; "As it was" without the speed going with the zoom In the top view the box is the view itself, its corners on the ground. The ground under the camera is the terrain, else the scenery, else the rays go as far as the reach. The tile of the camera is taken anew by hurry(), it isn't followed while the layer is off. The top view is as fast zoomed in as out by default, as before. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DDcMn1Q7wdYkbxDUWscNHZ * fix(editor): the corners of the top view on the ground put where the camera is (the view matrix is camera-relative) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DDcMn1Q7wdYkbxDUWscNHZ * i18n(editor): Polish for the orthophoto keys and the camera speed, on top of the master's own translations Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DDcMn1Q7wdYkbxDUWscNHZ * fix(editor): Ctrl+~ asks only for the tiles update() would ask for; the tooltip of "Track colours" back in its place After the reviews of #312: - hurry() skips the tiles outside the download area set and marks the ones outside the area the service covers as empty, as update() does, so Ctrl+~ no longer queues downloads update() drops at once (and the workers took anyway, into the disk cache, against the area set), nor requests the service can't answer. - A blank tile hurried takes the standard image first, as in update(); first_level() and outside_area() are shared by both loops, and the body of the loop of hurry() is hurry_tile(). - orthophoto_hurry() takes the level of the terrain only when it's below the camera, as the branch of the scenery already did: a camera under the terrain (a tunnel, under the heightmap) no longer flips the box of the view behind it. - The "Camera speed" menu goes after the tooltip of "Track colours", which it had taken. - #include <set> once in editorOrthophoto.hpp. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QRgQ1K1Qu7TCsa74zsNURd --------- Co-authored-by: Claude <noreply@anthropic.com>
250 lines
8.9 KiB
C++
250 lines
8.9 KiB
C++
/*
|
|
This Source Code Form is subject to the
|
|
terms of the Mozilla Public License, v.
|
|
2.0. If a copy of the MPL was not
|
|
distributed with this file, You can
|
|
obtain one at
|
|
http://mozilla.org/MPL/2.0/.
|
|
*/
|
|
|
|
#include "stdafx.h"
|
|
#include "vehicle/Camera.h"
|
|
|
|
#include "utilities/Globals.h"
|
|
#include "utilities/utilities.h"
|
|
#include "utilities/glmHelpers.h"
|
|
#include "Console.h"
|
|
#include "utilities/Timer.h"
|
|
#include "vehicle/Driver.h"
|
|
#include "vehicle/DynObj.h"
|
|
#include "MOVER.h"
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
void TCamera::Init(glm::dvec3 const &NPos, glm::dvec3 const &NAngle /*, TCameraType const NType*/, TDynamicObject *Owner)
|
|
{
|
|
|
|
vUp = { 0, 1, 0 };
|
|
Velocity = { 0, 0, 0 };
|
|
Angle = NAngle;
|
|
Pos = NPos;
|
|
|
|
m_owner = Owner;
|
|
};
|
|
|
|
void TCamera::Reset() {
|
|
|
|
Angle = {};
|
|
m_rotationoffsets = {};
|
|
};
|
|
|
|
|
|
void TCamera::OnCursorMove(double x, double y) {
|
|
m_rotationoffsets.x += static_cast<float>(y);
|
|
m_rotationoffsets.y += static_cast<float>(x);
|
|
}
|
|
|
|
static double ComputeAxisSpeed(double param, double walkspeed, double maxspeed, double threshold) {
|
|
double absval = std::abs(param);
|
|
// 2/3rd of the stick range lerps walk speed, past that we lerp between max walk and run speed
|
|
double walk = walkspeed * std::min(absval / threshold, 1.0);
|
|
double run = std::max(0.0, absval - threshold) / (1.0 - threshold) * std::max(0.0, maxspeed - walkspeed);
|
|
return (param >= 0.0 ? 1.0 : -1.0) * (walk + run);
|
|
}
|
|
|
|
|
|
bool
|
|
TCamera::OnCommand( command_data const &Command ) {
|
|
|
|
auto const walkspeed { 1.0 };
|
|
auto const runspeed { 10.0 };
|
|
|
|
// threshold position on stick between walk lerp and walk/run lerp
|
|
auto const stickthreshold = 2.0 / 3.0;
|
|
|
|
// the free camera of the editor as fast as its View menu sets it, Ctrl by the multiplier set there, in the top view by how far it reaches
|
|
auto editorscale { 1.0 };
|
|
auto editorfast { -1.0 };
|
|
if( Global.EditorCameraOn && m_owner == nullptr ) {
|
|
editorscale = Global.EditorCameraSpeed;
|
|
if( Global.EditorOrtho && Global.EditorCameraZoomed ) {
|
|
editorscale *= std::clamp( static_cast<double>( Global.EditorOrthoExtent ) / 150.0, 0.02, 200.0 );
|
|
}
|
|
editorfast = Global.EditorCameraFast;
|
|
}
|
|
// how many times faster the fast command of a move makes it: the editor's own, or the free fly's (Default) and the cab's (Cab)
|
|
auto const fastness = [&]( bool const Fast, double const Editor, double const Default, double const Cab ) {
|
|
if( false == Fast ) {
|
|
return 1.0;
|
|
}
|
|
if( editorfast > 0.0 ) {
|
|
return Editor;
|
|
}
|
|
if( false == FreeFlyModeFlag ) {
|
|
return 1.0;
|
|
}
|
|
return m_owner == nullptr ? Default : Cab;
|
|
};
|
|
|
|
bool iscameracommand { true };
|
|
switch( Command.command ) {
|
|
|
|
case user_command::viewturn: {
|
|
|
|
OnCursorMove(
|
|
Command.param1 * 0.005 * Global.fMouseXScale / Global.ZoomFactor,
|
|
Command.param2 * 0.01 * Global.fMouseYScale / Global.ZoomFactor );
|
|
break;
|
|
}
|
|
|
|
case user_command::movehorizontal:
|
|
case user_command::movehorizontalfast: {
|
|
|
|
auto const movespeed = m_owner == nullptr ? runspeed : // free roam
|
|
false == FreeFlyModeFlag ? walkspeed : // vehicle cab
|
|
0.0; // vehicle external
|
|
|
|
// if( movespeed == 0.0 ) { break; } // enable to fix external cameras in place
|
|
|
|
auto const speedmultiplier = editorscale * fastness( Command.command == user_command::movehorizontalfast, editorfast, 30.0, 5.0 );
|
|
|
|
// left-right
|
|
m_moverate.x = ComputeAxisSpeed(Command.param1, walkspeed, movespeed, stickthreshold) * speedmultiplier;
|
|
// forward-back
|
|
m_moverate.z = -ComputeAxisSpeed(Command.param2, walkspeed, movespeed, stickthreshold) * speedmultiplier;
|
|
|
|
break;
|
|
}
|
|
|
|
case user_command::movevertical:
|
|
case user_command::moveverticalfast: {
|
|
|
|
auto const movespeed = m_owner == nullptr ? runspeed * 0.5 : // free roam
|
|
false == FreeFlyModeFlag ? walkspeed : // vehicle cab
|
|
0.0; // vehicle external
|
|
|
|
// if( movespeed == 0.0 ) { break; } // enable to fix external cameras in place
|
|
|
|
auto const speedmultiplier = editorscale * fastness( Command.command == user_command::moveverticalfast, std::max( 1.0, editorfast / 3.0 ), 10.0, 3.0 );
|
|
// up-down
|
|
m_moverate.y = ComputeAxisSpeed(Command.param1, walkspeed, movespeed, stickthreshold) * speedmultiplier;
|
|
|
|
break;
|
|
}
|
|
|
|
default: {
|
|
|
|
iscameracommand = false;
|
|
break;
|
|
}
|
|
} // switch
|
|
|
|
return iscameracommand;
|
|
}
|
|
|
|
static void UpdateVelocityAxis(double& velocity, double moverate, double deltatime)
|
|
{
|
|
velocity = std::clamp(velocity + moverate * 10.0 * deltatime, -std::abs(moverate), std::abs(moverate));
|
|
}
|
|
|
|
|
|
void TCamera::Update()
|
|
{
|
|
// check for sent user commands
|
|
// NOTE: this is a temporary arrangement, for the transition period from old command setup to the new one
|
|
// ultimately we'll need to track position of camera/driver for all human entities present in the scenario
|
|
command_data command;
|
|
// NOTE: currently we're only storing commands for local entity and there's no id system in place,
|
|
// so we're supplying 'default' entity id of 0
|
|
while( simulation::Commands.pop( command, static_cast<std::size_t>( command_target::entity ) | 0 ) ) {
|
|
|
|
OnCommand( command );
|
|
}
|
|
|
|
auto const deltatime { Timer::GetDeltaRenderTime() }; // czas bez pauzy
|
|
|
|
// update rotation
|
|
auto const rotationfactor { std::min( 1.0, 20 * deltatime ) };
|
|
|
|
Angle.y -= static_cast<float>(m_rotationoffsets.y * rotationfactor);
|
|
m_rotationoffsets.y *= static_cast<float>(1.0 - rotationfactor);
|
|
Angle.y = static_cast<float>(std::remainder(Angle.y, 2.0 * M_PI));
|
|
|
|
// Limit the camera pitch to +/- 90°.
|
|
Angle.x = static_cast<float>(std::clamp(Angle.x - m_rotationoffsets.x * rotationfactor, -M_PI_2, M_PI_2));
|
|
m_rotationoffsets.x *= static_cast<float>(1.0 - rotationfactor);
|
|
|
|
// update position
|
|
if( m_owner == nullptr
|
|
|| true == FreeFlyModeFlag
|
|
|| false == Global.ctrlState
|
|
|| true == DebugCameraFlag ) {
|
|
// ctrl is used for mirror view, so we ignore the controls when in vehicle if ctrl is pressed
|
|
// McZapkie-170402: poruszanie i rozgladanie we free takie samo jak w follow
|
|
UpdateVelocityAxis(Velocity.x, m_moverate.x, deltatime);
|
|
UpdateVelocityAxis(Velocity.y, m_moverate.y, deltatime);
|
|
UpdateVelocityAxis(Velocity.z, m_moverate.z, deltatime);
|
|
}
|
|
if( m_owner == nullptr
|
|
|| true == DebugCameraFlag ) {
|
|
// free movement position update
|
|
auto movement { Velocity };
|
|
movement = RotateY(movement, (double)Angle.y);
|
|
Pos += movement * 5.0 * deltatime;
|
|
}
|
|
else {
|
|
// attached movement position update
|
|
auto movement { Velocity * -2.0 };
|
|
movement.y = -movement.y;
|
|
if( auto const *owner { ( m_owner->Mechanik ? m_owner->Mechanik : m_owner->ctOwner ) }; owner && owner->Occupied()
|
|
&& owner->Occupied()->CabOccupied < 0 ) {
|
|
movement *= -1.f;
|
|
movement.y = -movement.y;
|
|
}
|
|
/*
|
|
if( ( m_owner->ctOwner )
|
|
&& ( m_owner->ctOwner->Vehicle()->DirectionGet() != m_owner->DirectionGet() ) ) {
|
|
movement *= -1.f;
|
|
movement.y = -movement.y;
|
|
}
|
|
*/
|
|
movement = RotateY(movement, (double)Angle.y);
|
|
|
|
m_owneroffset += movement * deltatime;
|
|
}
|
|
}
|
|
|
|
bool TCamera::SetMatrix( glm::dmat4 &Matrix ) const {
|
|
|
|
// the roll (z) is multiplied in first, so it acts last, about the line of sight: the sway of the cab tilts the view
|
|
// the same way wherever the head is turned, as it did in 26.05. the order matters only with a roll (the cab shake,
|
|
// or the angles of a camera entry of the scenery)
|
|
Matrix = glm::rotate(Matrix, -(double)Angle.z, glm::dvec3(0, 0, 1)); // po wyłączeniu tego kręci się pojazd, a sceneria nie
|
|
Matrix = glm::rotate(Matrix, -(double)Angle.x, glm::dvec3(1, 0, 0));
|
|
Matrix = glm::rotate(Matrix, -(double)Angle.y, glm::dvec3(0, 1, 0)); // w zewnętrznym widoku: kierunek patrzenia
|
|
|
|
if( m_owner != nullptr && false == DebugCameraFlag ) {
|
|
|
|
Matrix *= glm::lookAt(Pos, LookAt, glm::dvec3{ vUp } );
|
|
}
|
|
else {
|
|
Matrix = glm::translate( Matrix, -Pos ); // nie zmienia kierunku patrzenia
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
void TCamera::RaLook()
|
|
{ // zmiana kierunku patrzenia - przelicza Yaw
|
|
auto where = LookAt - Pos /*+ Math3D::vector3(0, 3, 0)*/; // trochę w górę od szyn
|
|
if( where.x != 0.0 || where.z != 0.0 ) {
|
|
Angle.y = static_cast<float>(atan2( -where.x, -where.z )); // kąt horyzontalny
|
|
m_rotationoffsets.y = 0.0;
|
|
}
|
|
double l = glm::length(where);
|
|
if( l > 0.0 ) {
|
|
Angle.x = static_cast<float>(asin( where.y / l )); // kąt w pionie
|
|
m_rotationoffsets.x = 0.0;
|
|
}
|
|
};
|