improve airresistance

This commit is contained in:
interfisch 2018-05-12 00:24:02 +02:00
parent 7ece405b8b
commit 0b1c282921
2 changed files with 14 additions and 5 deletions

View File

@ -17,7 +17,7 @@ long lastRoutineUpdate=0;
#define ROUTINEUPDATETIME 20 #define ROUTINEUPDATETIME 20
long lastCheckspawn=0; long lastCheckspawn=0;
#define CHECKSPAWNDELAY 4000 //delay in ms to check random spawn #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 #define SPAWNCHANCEDOUBLE 5 //change of spawning a two trains simultaneously
long loopmillis=0; long loopmillis=0;

View File

@ -15,7 +15,7 @@ Wagon::Wagon(int id,int numpixels, Adafruit_NeoPixel *strip,uint8_t *height,floa
_height=height; _height=height;
_vel=startvel; _vel=startvel;
_acc=startacc; _acc=startacc;
_wagonmass=wagonmass; _wagonmass=wagonmass; //mass of whole train
_spawntime=millis(); _spawntime=millis();
_lasttimefast=millis(); _lasttimefast=millis();
_wagoncolor=wagoncolor; _wagoncolor=wagoncolor;
@ -46,7 +46,9 @@ void Wagon::updatePhysics(float updatedelayms)
#define CONST_G 9.81 #define CONST_G 9.81
#define PIXELDISTANCE 1.6666667 // 1/60.0 * 100 #define PIXELDISTANCE 1.6666667 // 1/60.0 * 100
#define C_ROLL 0.001 // = Croll * G https://de.wikipedia.org/wiki/Rollwiderstand 0.001 #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 //http://www.kfz-tech.de/Biblio/Formelsammlung/Luftwiderstand.htm C_w 0.6
//rho Massendichte luft 1,2041 //rho Massendichte luft 1,2041
//A = 1m^2 //A = 1m^2
@ -55,6 +57,7 @@ void Wagon::updatePhysics(float updatedelayms)
_acc=0; _acc=0;
int cpos=(int)_pos; int cpos=(int)_pos;
uint8_t wagonnumber=0;
for (int cpos=(int)_pos;cpos>(int)(_pos-_trainlength);cpos--){ //for each wagon 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)); float hdiff=getHeight((int) (cpos-0.5)) - getHeight((int)(cpos+0.5));
@ -74,7 +77,13 @@ void Wagon::updatePhysics(float updatedelayms)
if (_vel<0){ if (_vel<0){
bb*=-1; 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){ if (_vel<0){
cc*=-1; cc*=-1;
} }
@ -86,7 +95,7 @@ void Wagon::updatePhysics(float updatedelayms)
_acc += aa - bb - cc; _acc += aa - bb - cc;
wagonnumber++;
} }
_acc*=updatedelayms/1000; _acc*=updatedelayms/1000;