16
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-07-19 21:29:19 +02:00

engine revolution based cab shake configuration support, rear cab door controls animation fix

This commit is contained in:
tmj-fstate
2018-02-24 02:38:02 +01:00
parent 89f76ff0e2
commit f3b7198246
5 changed files with 70 additions and 72 deletions

View File

@@ -10,48 +10,31 @@ http://mozilla.org/MPL/2.0/.
#include "stdafx.h"
#include "Spring.h"
TSpring::TSpring()
{
vForce1 = vForce2 = Math3D::vector3(0, 0, 0);
Ks = 0;
Kd = 0;
restLen = 0;
}
TSpring::~TSpring()
{
}
void TSpring::Init(double nrestLen, double nKs, double nKd)
{
void TSpring::Init(double nKs, double nKd) {
Ks = nKs;
Kd = nKd;
restLen = nrestLen;
}
Math3D::vector3 TSpring::ComputateForces( Math3D::vector3 const &pPosition1, Math3D::vector3 const &pPosition2)
{
Math3D::vector3 TSpring::ComputateForces( Math3D::vector3 const &pPosition1, Math3D::vector3 const &pPosition2) {
double dist, Hterm, Dterm;
Math3D::vector3 springForce, deltaV;
Math3D::vector3 springForce;
// p1 = &system[spring->p1];
// p2 = &system[spring->p2];
// VectorDifference(&p1->pos,&p2->pos,&deltaP); // Vector distance
auto deltaP = pPosition1 - pPosition2;
// dist = VectorLength(&deltaP); // Magnitude of
// deltaP
dist = deltaP.Length();
if( dist > 0.00001 ) {
// dist = VectorLength(&deltaP); // Magnitude of deltaP
auto dist = deltaP.Length();
if( dist > restLen ) {
// Hterm = (dist - spring->restLen) * spring->Ks; // Ks * (dist - rest)
Hterm = ( dist - restLen ) * Ks; // Ks * (dist - rest)
auto Hterm = ( dist - restLen ) * Ks; // Ks * (dist - rest)
// VectorDifference(&p1->v,&p2->v,&deltaV); // Delta Velocity Vector
deltaV = pPosition1 - pPosition2;
auto deltaV = pPosition1 - pPosition2;
// Dterm = (DotProduct(&deltaV,&deltaP) * spring->Kd) / dist; // Damping Term
// Dterm = (DotProduct(deltaV,deltaP) * Kd) / dist;
Dterm = 0;
auto Dterm = (DotProduct(deltaV,deltaP) * Kd) / dist;
//Dterm = 0;
// ScaleVector(&deltaP,1.0f / dist, &springForce); // Normalize Distance Vector
// ScaleVector(&springForce,-(Hterm + Dterm),&springForce); // Calc Force
@@ -60,14 +43,7 @@ Math3D::vector3 TSpring::ComputateForces( Math3D::vector3 const &pPosition1, Mat
// VectorDifference(&p2->f,&springForce,&p2->f); // - Force on Particle 2
}
vForce1 = springForce;
vForce2 = springForce;
return springForce;
}
void TSpring::Render()
{
}
//---------------------------------------------------------------------------

View File

@@ -11,9 +11,8 @@ http://mozilla.org/MPL/2.0/.
#define ParticlesH
#include "dumb3d.h"
/*
#define STATIC_THRESHOLD 0.17f
// efine STATIC_THRESHOLD 0.03f
const double m_Kd = 0.02f; // DAMPING FACTOR
const double m_Kr = 0.8f; // 1.0 = SUPERBALL BOUNCE 0.0 = DEAD WEIGHT
const double m_Ksh = 5.0f; // HOOK'S SPRING CONSTANT
@@ -21,22 +20,20 @@ const double m_Ksd = 0.1f; // SPRING DAMPING CONSTANT
const double m_Csf = 0.9f; // Default Static Friction
const double m_Ckf = 0.7f; // Default Kinetic Friction
*/
class TSpring {
class TSpring
{
public:
TSpring();
~TSpring();
public:
TSpring() = default;
// void Init(TParticnp1, TParticle *np2, double nKs= 0.5f, double nKd= 0.002f,
// double nrestLen= -1.0f);
void Init(double nrestLen, double nKs = 0.5f, double nKd = 0.002f);
void Init(double nKs = 0.5f, double nKd = 0.002f);
Math3D::vector3 ComputateForces( Math3D::vector3 const &pPosition1, Math3D::vector3 const &pPosition2);
void Render();
Math3D::vector3 vForce1, vForce2;
double restLen; // LENGTH OF SPRING AT REST
double Ks; // SPRING CONSTANT
double Kd; // SPRING DAMPING
private:
private:
// members
double restLen { 0.01 }; // LENGTH OF SPRING AT REST
double Ks { 0.0 }; // SPRING CONSTANT
double Kd { 0.0 }; // SPRING DAMPING
};
//---------------------------------------------------------------------------

View File

@@ -375,7 +375,7 @@ bool TTrain::Init(TDynamicObject *NewDynamicObject, bool e3d)
}
}
*/
MechSpring.Init(0.015, 250);
MechSpring.Init(250);
vMechVelocity = Math3D::vector3(0, 0, 0);
pMechOffset = Math3D::vector3( 0, 0, 0 );
fMechSpringX = 1;
@@ -3299,9 +3299,10 @@ void TTrain::OnCommand_doortoggleleft( TTrain *Train, command_data const &Comman
}
}
else {
// in the rear cab sides are reversed
// in the rear cab sides are reversed...
if( Train->mvOccupied->DoorRight( true ) ) {
Train->ggDoorRightButton.UpdateValue( 1.0, Train->dsbSwitch );
// ...but so are the switches
Train->ggDoorLeftButton.UpdateValue( 1.0, Train->dsbSwitch );
}
}
}
@@ -3313,9 +3314,10 @@ void TTrain::OnCommand_doortoggleleft( TTrain *Train, command_data const &Comman
}
}
else {
// in the rear cab sides are reversed
// in the rear cab sides are reversed...
if( Train->mvOccupied->DoorRight( false ) ) {
Train->ggDoorRightButton.UpdateValue( 0.0, Train->dsbSwitch );
// ...but so are the switches
Train->ggDoorLeftButton.UpdateValue( 0.0, Train->dsbSwitch );
}
}
}
@@ -3340,9 +3342,10 @@ void TTrain::OnCommand_doortoggleright( TTrain *Train, command_data const &Comma
}
}
else {
// in the rear cab sides are reversed
// in the rear cab sides are reversed...
if( Train->mvOccupied->DoorLeft( true ) ) {
Train->ggDoorLeftButton.UpdateValue( 1.0, Train->dsbSwitch );
// ...but so are the switches
Train->ggDoorRightButton.UpdateValue( 1.0, Train->dsbSwitch );
}
}
}
@@ -3354,9 +3357,10 @@ void TTrain::OnCommand_doortoggleright( TTrain *Train, command_data const &Comma
}
}
else {
// in the rear cab sides are reversed
// in the rear cab sides are reversed...
if( Train->mvOccupied->DoorLeft( false ) ) {
Train->ggDoorLeftButton.UpdateValue( 0.0, Train->dsbSwitch );
// ...but so are the switches
Train->ggDoorRightButton.UpdateValue( 0.0, Train->dsbSwitch );
}
}
}
@@ -3659,20 +3663,20 @@ void TTrain::UpdateMechPosition(double dt)
{
Math3D::vector3 shakevector;
if( ( mvOccupied->EngineType == DieselElectric )
|| ( mvOccupied->EngineType == DieselEngine ) ) {
|| ( mvOccupied->EngineType == DieselEngine ) ) {
if( std::abs( mvOccupied->enrot ) > 0.0 ) {
// engine vibration
shakevector.x +=
( std::cos( mvOccupied->eAngle * 4.0 ) * dt * 2.0 )
// fade in with rpm < 300
( std::cos( mvOccupied->eAngle * 4.0 ) * dt * EngineShake.scale )
// fade in with rpm above threshold
* clamp(
( mvOccupied->enrot - 1.0 ) * 0.25,
( mvOccupied->enrot - EngineShake.fadein_offset ) * EngineShake.fadein_factor,
0.0, 1.0 )
// fade out with rpm > 600
// fade out with rpm above threshold
* interpolate(
1.0, 0.0,
clamp(
mvOccupied->enrot - 10.0,
( mvOccupied->enrot - EngineShake.fadeout_offset ) * EngineShake.fadeout_factor,
0.0, 1.0 ) );
}
}
@@ -3704,20 +3708,22 @@ void TTrain::UpdateMechPosition(double dt)
// McZapkie:
pMechShake += vMechVelocity * dt;
if( ( pMechShake.y > fMechMaxSpring )
|| ( pMechShake.y < -fMechMaxSpring ) ) {
vMechVelocity.y = -vMechVelocity.y;
}
// Ra 2015-01: dotychczasowe rzucanie
pMechOffset += vMechMovement * dt;
if( ( pMechShake.y > fMechMaxSpring ) || ( pMechShake.y < -fMechMaxSpring ) )
vMechVelocity.y = -vMechVelocity.y;
// ABu011104: 5*pMechShake.y, zeby ladnie pudlem rzucalo :)
pMechPosition = pMechOffset + Math3D::vector3( 1.5 * pMechShake.x, 2.0 * pMechShake.y, 1.5 * pMechShake.z );
// vMechMovement = 0.5 * vMechMovement;
// pMechShake = interpolate( pMechShake, Math3D::vector3(), clamp( dt, 0.0, 1.0 ) );
}
else { // hamowanie rzucania przy spadku FPS
pMechShake -= pMechShake * std::min( dt, 1.0 ); // po tym chyba potrafią zostać jakieś ułamki, które powodują zjazd
pMechOffset += vMechMovement * dt;
vMechVelocity.y = 0.5 * vMechVelocity.y;
pMechPosition = pMechOffset + Math3D::vector3( pMechShake.x, 5 * pMechShake.y, pMechShake.z );
// vMechMovement = 0.5 * vMechMovement;
}
// numer kabiny (-1: kabina B)
if( DynamicObject->Mechanik ) // może nie być?
@@ -5328,7 +5334,7 @@ bool TTrain::LoadMMediaFile(std::string const &asFileName)
parser
>> ks
>> kd;
MechSpring.Init(MechSpring.restLen, ks, kd);
MechSpring.Init(ks, kd);
parser.getTokens(6, false);
parser
>> fMechSpringX
@@ -5338,6 +5344,15 @@ bool TTrain::LoadMMediaFile(std::string const &asFileName)
>> fMechRoll
>> fMechPitch;
}
else if( token == "enginespring:" ) {
parser.getTokens( 5, false );
parser
>> EngineShake.scale
>> EngineShake.fadein_offset
>> EngineShake.fadein_factor
>> EngineShake.fadeout_offset
>> EngineShake.fadeout_factor;
}
} while (token != "");
}

View File

@@ -501,6 +501,13 @@ public: // reszta może by?publiczna
double fMechMaxSpring;
double fMechRoll;
double fMechPitch;
struct engineshake_config {
float scale { 2.f };
float fadein_offset { 1.5f };
float fadein_factor { 0.3f };
float fadeout_offset { 10.f };
float fadeout_factor { 0.5f };
} EngineShake;
sound_source dsbReverserKey { sound_placement::internal, EU07_SOUND_CABCONTROLSCUTOFFRANGE }; // hunter-121211
sound_source dsbNastawnikJazdy { sound_placement::internal, EU07_SOUND_CABCONTROLSCUTOFFRANGE };

View File

@@ -1064,10 +1064,13 @@ TWorld::Update_Camera( double const Deltatime ) {
else {
// patrzenie standardowe
Camera.Pos = Train->GetWorldMechPosition(); // Train.GetPosition1();
if( !Global.iPause ) { // podczas pauzy nie przeliczać kątów przypadkowymi wartościami
Camera.Roll = atan( Train->pMechShake.x * Train->fMechRoll ); // hustanie kamery na boki
Camera.Pitch -= 0.5 * atan( Train->vMechVelocity.z * Train->fMechPitch ); // hustanie kamery przod tyl //Ra: tu
// jest uciekanie kamery w górę!!!
if( !Global.iPause ) {
// podczas pauzy nie przeliczać kątów przypadkowymi wartościami
// hustanie kamery na boki
Camera.Roll = atan( Train->vMechVelocity.x * Train->fMechRoll );
// hustanie kamery przod tyl
// Ra: tu jest uciekanie kamery w górę!!!
Camera.Pitch -= 0.5 * atan( Train->vMechVelocity.z * Train->fMechPitch );
}
// ABu011104: rzucanie pudlem
/*