mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-07-22 11:39:19 +02:00
engine revolution based cab shake configuration support, rear cab door controls animation fix
This commit is contained in:
44
Spring.cpp
44
Spring.cpp
@@ -10,48 +10,31 @@ http://mozilla.org/MPL/2.0/.
|
|||||||
#include "stdafx.h"
|
#include "stdafx.h"
|
||||||
#include "Spring.h"
|
#include "Spring.h"
|
||||||
|
|
||||||
TSpring::TSpring()
|
void TSpring::Init(double nKs, double nKd) {
|
||||||
{
|
|
||||||
vForce1 = vForce2 = Math3D::vector3(0, 0, 0);
|
|
||||||
Ks = 0;
|
|
||||||
Kd = 0;
|
|
||||||
restLen = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
TSpring::~TSpring()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void TSpring::Init(double nrestLen, double nKs, double nKd)
|
|
||||||
{
|
|
||||||
Ks = nKs;
|
Ks = nKs;
|
||||||
Kd = nKd;
|
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;
|
||||||
Math3D::vector3 springForce, deltaV;
|
|
||||||
// p1 = &system[spring->p1];
|
// p1 = &system[spring->p1];
|
||||||
// p2 = &system[spring->p2];
|
// p2 = &system[spring->p2];
|
||||||
// VectorDifference(&p1->pos,&p2->pos,&deltaP); // Vector distance
|
// VectorDifference(&p1->pos,&p2->pos,&deltaP); // Vector distance
|
||||||
auto deltaP = pPosition1 - pPosition2;
|
auto deltaP = pPosition1 - pPosition2;
|
||||||
// dist = VectorLength(&deltaP); // Magnitude of
|
// dist = VectorLength(&deltaP); // Magnitude of deltaP
|
||||||
// deltaP
|
auto dist = deltaP.Length();
|
||||||
dist = deltaP.Length();
|
if( dist > restLen ) {
|
||||||
if( dist > 0.00001 ) {
|
|
||||||
|
|
||||||
// Hterm = (dist - spring->restLen) * spring->Ks; // Ks * (dist - rest)
|
// 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
|
// 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) * spring->Kd) / dist; // Damping Term
|
||||||
// Dterm = (DotProduct(deltaV,deltaP) * Kd) / dist;
|
auto Dterm = (DotProduct(deltaV,deltaP) * Kd) / dist;
|
||||||
Dterm = 0;
|
//Dterm = 0;
|
||||||
|
|
||||||
// ScaleVector(&deltaP,1.0f / dist, &springForce); // Normalize Distance Vector
|
// ScaleVector(&deltaP,1.0f / dist, &springForce); // Normalize Distance Vector
|
||||||
// ScaleVector(&springForce,-(Hterm + Dterm),&springForce); // Calc Force
|
// 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
|
// VectorDifference(&p2->f,&springForce,&p2->f); // - Force on Particle 2
|
||||||
}
|
}
|
||||||
|
|
||||||
vForce1 = springForce;
|
|
||||||
vForce2 = springForce;
|
|
||||||
|
|
||||||
return springForce;
|
return springForce;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TSpring::Render()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
|||||||
25
Spring.h
25
Spring.h
@@ -11,9 +11,8 @@ http://mozilla.org/MPL/2.0/.
|
|||||||
#define ParticlesH
|
#define ParticlesH
|
||||||
|
|
||||||
#include "dumb3d.h"
|
#include "dumb3d.h"
|
||||||
|
/*
|
||||||
#define STATIC_THRESHOLD 0.17f
|
#define STATIC_THRESHOLD 0.17f
|
||||||
// efine STATIC_THRESHOLD 0.03f
|
|
||||||
const double m_Kd = 0.02f; // DAMPING FACTOR
|
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_Kr = 0.8f; // 1.0 = SUPERBALL BOUNCE 0.0 = DEAD WEIGHT
|
||||||
const double m_Ksh = 5.0f; // HOOK'S SPRING CONSTANT
|
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_Csf = 0.9f; // Default Static Friction
|
||||||
const double m_Ckf = 0.7f; // Default Kinetic Friction
|
const double m_Ckf = 0.7f; // Default Kinetic Friction
|
||||||
|
*/
|
||||||
|
class TSpring {
|
||||||
|
|
||||||
class TSpring
|
public:
|
||||||
{
|
TSpring() = default;
|
||||||
public:
|
|
||||||
TSpring();
|
|
||||||
~TSpring();
|
|
||||||
// void Init(TParticnp1, TParticle *np2, double nKs= 0.5f, double nKd= 0.002f,
|
// void Init(TParticnp1, TParticle *np2, double nKs= 0.5f, double nKd= 0.002f,
|
||||||
// double nrestLen= -1.0f);
|
// 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);
|
Math3D::vector3 ComputateForces( Math3D::vector3 const &pPosition1, Math3D::vector3 const &pPosition2);
|
||||||
void Render();
|
private:
|
||||||
Math3D::vector3 vForce1, vForce2;
|
// members
|
||||||
double restLen; // LENGTH OF SPRING AT REST
|
double restLen { 0.01 }; // LENGTH OF SPRING AT REST
|
||||||
double Ks; // SPRING CONSTANT
|
double Ks { 0.0 }; // SPRING CONSTANT
|
||||||
double Kd; // SPRING DAMPING
|
double Kd { 0.0 }; // SPRING DAMPING
|
||||||
private:
|
|
||||||
};
|
};
|
||||||
|
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
|||||||
55
Train.cpp
55
Train.cpp
@@ -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);
|
vMechVelocity = Math3D::vector3(0, 0, 0);
|
||||||
pMechOffset = Math3D::vector3( 0, 0, 0 );
|
pMechOffset = Math3D::vector3( 0, 0, 0 );
|
||||||
fMechSpringX = 1;
|
fMechSpringX = 1;
|
||||||
@@ -3299,9 +3299,10 @@ void TTrain::OnCommand_doortoggleleft( TTrain *Train, command_data const &Comman
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// in the rear cab sides are reversed
|
// in the rear cab sides are reversed...
|
||||||
if( Train->mvOccupied->DoorRight( true ) ) {
|
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 {
|
else {
|
||||||
// in the rear cab sides are reversed
|
// in the rear cab sides are reversed...
|
||||||
if( Train->mvOccupied->DoorRight( false ) ) {
|
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 {
|
else {
|
||||||
// in the rear cab sides are reversed
|
// in the rear cab sides are reversed...
|
||||||
if( Train->mvOccupied->DoorLeft( true ) ) {
|
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 {
|
else {
|
||||||
// in the rear cab sides are reversed
|
// in the rear cab sides are reversed...
|
||||||
if( Train->mvOccupied->DoorLeft( false ) ) {
|
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;
|
Math3D::vector3 shakevector;
|
||||||
if( ( mvOccupied->EngineType == DieselElectric )
|
if( ( mvOccupied->EngineType == DieselElectric )
|
||||||
|| ( mvOccupied->EngineType == DieselEngine ) ) {
|
|| ( mvOccupied->EngineType == DieselEngine ) ) {
|
||||||
if( std::abs( mvOccupied->enrot ) > 0.0 ) {
|
if( std::abs( mvOccupied->enrot ) > 0.0 ) {
|
||||||
// engine vibration
|
// engine vibration
|
||||||
shakevector.x +=
|
shakevector.x +=
|
||||||
( std::cos( mvOccupied->eAngle * 4.0 ) * dt * 2.0 )
|
( std::cos( mvOccupied->eAngle * 4.0 ) * dt * EngineShake.scale )
|
||||||
// fade in with rpm < 300
|
// fade in with rpm above threshold
|
||||||
* clamp(
|
* clamp(
|
||||||
( mvOccupied->enrot - 1.0 ) * 0.25,
|
( mvOccupied->enrot - EngineShake.fadein_offset ) * EngineShake.fadein_factor,
|
||||||
0.0, 1.0 )
|
0.0, 1.0 )
|
||||||
// fade out with rpm > 600
|
// fade out with rpm above threshold
|
||||||
* interpolate(
|
* interpolate(
|
||||||
1.0, 0.0,
|
1.0, 0.0,
|
||||||
clamp(
|
clamp(
|
||||||
mvOccupied->enrot - 10.0,
|
( mvOccupied->enrot - EngineShake.fadeout_offset ) * EngineShake.fadeout_factor,
|
||||||
0.0, 1.0 ) );
|
0.0, 1.0 ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3704,20 +3708,22 @@ void TTrain::UpdateMechPosition(double dt)
|
|||||||
|
|
||||||
// McZapkie:
|
// McZapkie:
|
||||||
pMechShake += vMechVelocity * dt;
|
pMechShake += vMechVelocity * dt;
|
||||||
|
if( ( pMechShake.y > fMechMaxSpring )
|
||||||
|
|| ( pMechShake.y < -fMechMaxSpring ) ) {
|
||||||
|
vMechVelocity.y = -vMechVelocity.y;
|
||||||
|
}
|
||||||
// Ra 2015-01: dotychczasowe rzucanie
|
// Ra 2015-01: dotychczasowe rzucanie
|
||||||
pMechOffset += vMechMovement * dt;
|
pMechOffset += vMechMovement * dt;
|
||||||
if( ( pMechShake.y > fMechMaxSpring ) || ( pMechShake.y < -fMechMaxSpring ) )
|
|
||||||
vMechVelocity.y = -vMechVelocity.y;
|
|
||||||
// ABu011104: 5*pMechShake.y, zeby ladnie pudlem rzucalo :)
|
// ABu011104: 5*pMechShake.y, zeby ladnie pudlem rzucalo :)
|
||||||
pMechPosition = pMechOffset + Math3D::vector3( 1.5 * pMechShake.x, 2.0 * pMechShake.y, 1.5 * pMechShake.z );
|
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
|
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
|
pMechShake -= pMechShake * std::min( dt, 1.0 ); // po tym chyba potrafią zostać jakieś ułamki, które powodują zjazd
|
||||||
pMechOffset += vMechMovement * dt;
|
pMechOffset += vMechMovement * dt;
|
||||||
vMechVelocity.y = 0.5 * vMechVelocity.y;
|
vMechVelocity.y = 0.5 * vMechVelocity.y;
|
||||||
pMechPosition = pMechOffset + Math3D::vector3( pMechShake.x, 5 * pMechShake.y, pMechShake.z );
|
pMechPosition = pMechOffset + Math3D::vector3( pMechShake.x, 5 * pMechShake.y, pMechShake.z );
|
||||||
// vMechMovement = 0.5 * vMechMovement;
|
|
||||||
}
|
}
|
||||||
// numer kabiny (-1: kabina B)
|
// numer kabiny (-1: kabina B)
|
||||||
if( DynamicObject->Mechanik ) // może nie być?
|
if( DynamicObject->Mechanik ) // może nie być?
|
||||||
@@ -5328,7 +5334,7 @@ bool TTrain::LoadMMediaFile(std::string const &asFileName)
|
|||||||
parser
|
parser
|
||||||
>> ks
|
>> ks
|
||||||
>> kd;
|
>> kd;
|
||||||
MechSpring.Init(MechSpring.restLen, ks, kd);
|
MechSpring.Init(ks, kd);
|
||||||
parser.getTokens(6, false);
|
parser.getTokens(6, false);
|
||||||
parser
|
parser
|
||||||
>> fMechSpringX
|
>> fMechSpringX
|
||||||
@@ -5338,6 +5344,15 @@ bool TTrain::LoadMMediaFile(std::string const &asFileName)
|
|||||||
>> fMechRoll
|
>> fMechRoll
|
||||||
>> fMechPitch;
|
>> 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 != "");
|
} while (token != "");
|
||||||
}
|
}
|
||||||
|
|||||||
7
Train.h
7
Train.h
@@ -501,6 +501,13 @@ public: // reszta może by?publiczna
|
|||||||
double fMechMaxSpring;
|
double fMechMaxSpring;
|
||||||
double fMechRoll;
|
double fMechRoll;
|
||||||
double fMechPitch;
|
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 dsbReverserKey { sound_placement::internal, EU07_SOUND_CABCONTROLSCUTOFFRANGE }; // hunter-121211
|
||||||
sound_source dsbNastawnikJazdy { sound_placement::internal, EU07_SOUND_CABCONTROLSCUTOFFRANGE };
|
sound_source dsbNastawnikJazdy { sound_placement::internal, EU07_SOUND_CABCONTROLSCUTOFFRANGE };
|
||||||
|
|||||||
11
World.cpp
11
World.cpp
@@ -1064,10 +1064,13 @@ TWorld::Update_Camera( double const Deltatime ) {
|
|||||||
else {
|
else {
|
||||||
// patrzenie standardowe
|
// patrzenie standardowe
|
||||||
Camera.Pos = Train->GetWorldMechPosition(); // Train.GetPosition1();
|
Camera.Pos = Train->GetWorldMechPosition(); // Train.GetPosition1();
|
||||||
if( !Global.iPause ) { // podczas pauzy nie przeliczać kątów przypadkowymi wartościami
|
if( !Global.iPause ) {
|
||||||
Camera.Roll = atan( Train->pMechShake.x * Train->fMechRoll ); // hustanie kamery na boki
|
// podczas pauzy nie przeliczać kątów przypadkowymi wartościami
|
||||||
Camera.Pitch -= 0.5 * atan( Train->vMechVelocity.z * Train->fMechPitch ); // hustanie kamery przod tyl //Ra: tu
|
// hustanie kamery na boki
|
||||||
// jest uciekanie kamery w górę!!!
|
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
|
// ABu011104: rzucanie pudlem
|
||||||
/*
|
/*
|
||||||
|
|||||||
Reference in New Issue
Block a user