From 0b1c282921f7d7bf8e3c3567aee918ce640955d3 Mon Sep 17 00:00:00 2001 From: Fisch Date: Sat, 12 May 2018 00:24:02 +0200 Subject: [PATCH] improve airresistance --- achterbahn.ino | 2 +- wagon.cpp | 17 +++++++++++++---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/achterbahn.ino b/achterbahn.ino index a79f9d6..63f68e5 100644 --- a/achterbahn.ino +++ b/achterbahn.ino @@ -17,7 +17,7 @@ long lastRoutineUpdate=0; #define ROUTINEUPDATETIME 20 long lastCheckspawn=0; #define CHECKSPAWNDELAY 4000 //delay in ms to check random spawn -#define SPAWNCHANCE 30 //1 out of x times wagon will spawn +#define SPAWNCHANCE 20 //1 out of x times wagon will spawn #define SPAWNCHANCEDOUBLE 5 //change of spawning a two trains simultaneously long loopmillis=0; diff --git a/wagon.cpp b/wagon.cpp index 9941fd5..56f0821 100644 --- a/wagon.cpp +++ b/wagon.cpp @@ -15,7 +15,7 @@ Wagon::Wagon(int id,int numpixels, Adafruit_NeoPixel *strip,uint8_t *height,floa _height=height; _vel=startvel; _acc=startacc; - _wagonmass=wagonmass; + _wagonmass=wagonmass; //mass of whole train _spawntime=millis(); _lasttimefast=millis(); _wagoncolor=wagoncolor; @@ -46,7 +46,9 @@ void Wagon::updatePhysics(float updatedelayms) #define CONST_G 9.81 #define PIXELDISTANCE 1.6666667 // 1/60.0 * 100 #define C_ROLL 0.001 // = Croll * G https://de.wikipedia.org/wiki/Rollwiderstand 0.001 - #define AIRRES 0.18 //C_w*A*0.5*rho Air resistance: C_w * A * 0.5 * rho (.... *v^2) + #define AIRRESFIRST 0.18 //C_w*A*0.5*rho Air resistance: C_w * A * 0.5 * rho (.... *v^2) + #define AIRRES 0.01 //for slipstream at second wagon + #define AIRRESMUL 0.7 //how much of air resistance the next wagon has //http://www.kfz-tech.de/Biblio/Formelsammlung/Luftwiderstand.htm C_w 0.6 //rho Massendichte luft 1,2041 //A = 1m^2 @@ -55,6 +57,7 @@ void Wagon::updatePhysics(float updatedelayms) _acc=0; int cpos=(int)_pos; + uint8_t wagonnumber=0; for (int cpos=(int)_pos;cpos>(int)(_pos-_trainlength);cpos--){ //for each wagon float hdiff=getHeight((int) (cpos-0.5)) - getHeight((int)(cpos+0.5)); @@ -74,7 +77,13 @@ void Wagon::updatePhysics(float updatedelayms) if (_vel<0){ bb*=-1; } - float cc=AIRRES/m*pow(_vel,2); //air resistance + float cc=0; + if (wagonnumber==0){ //first wagon + cc=AIRRESFIRST/m*pow(_vel,2); //air resistance for first wagon + }else{ + cc=AIRRES/m*pow(_vel,2) *pow(AIRRESMUL,wagonnumber-1); //air resistance + + } if (_vel<0){ cc*=-1; } @@ -86,7 +95,7 @@ void Wagon::updatePhysics(float updatedelayms) _acc += aa - bb - cc; - + wagonnumber++; } _acc*=updatedelayms/1000;