diff --git a/achterbahn.ino b/achterbahn.ino index 8a8f8c3..b11824e 100644 --- a/achterbahn.ino +++ b/achterbahn.ino @@ -54,33 +54,40 @@ void setup() { resetHeightmap(); //fixed heightmap - heightraw[0]=7; -heightraw[25]=1; -heightraw[89]=102; -heightraw[140]=159; -heightraw[163]=166; -heightraw[184]=162; -heightraw[229]=131; -heightraw[252]=95; -heightraw[266]=73; -heightraw[282]=65; -heightraw[295]=73; -heightraw[305]=82; -heightraw[321]=107; -heightraw[334]=114; -heightraw[343]=117; -heightraw[363]=107; -heightraw[380]=81; -heightraw[397]=53; -heightraw[409]=35; -heightraw[420]=21; -heightraw[429]=11; -heightraw[444]=1; -heightraw[489]=1; -heightraw[508]=10; -heightraw[524]=27; -heightraw[540]=59; -heightraw[599]=141; +heightraw[0]=199; +heightraw[38]=198; +heightraw[45]=192; +heightraw[60]=180; +heightraw[78]=168; +heightraw[117]=167; +heightraw[160]=115; +heightraw[178]=100; +heightraw[194]=96; +heightraw[215]=105; +heightraw[239]=128; +heightraw[250]=139; +heightraw[266]=127; +heightraw[276]=122; +heightraw[287]=128; +heightraw[299]=117; +heightraw[358]=28; +heightraw[379]=5; +heightraw[388]=1; +heightraw[401]=1; +heightraw[409]=6; +heightraw[425]=20; +heightraw[492]=120; +heightraw[500]=124; +heightraw[531]=120; +heightraw[561]=122; +heightraw[571]=126; +heightraw[578]=136; +heightraw[588]=148; +heightraw[599]=151; + + + + @@ -213,9 +220,9 @@ void spawnWagon(){ //Wagon tmpr = Wagon(maxid++,NUMPIXELS,&strip, height, 35, 6, 0.5,0); //spawn new wagon // pos, wagonlength, startvel, startacc, trainmass, wagoncolor //Wagon tmpr = Wagon(maxid++,NUMPIXELS,&strip, height, random(0, 20), random(3,20), random(0.2, 50)/10.0, 0 , random(5,100) , Wheel(random(0,256))); //spawn new wagon - int _randomlength=random(3,40); //3-> minimum vel 10, 40 -> minium vel 30 + int _randomlength=random(3,40); //Zelt: 3-> minimum vel 10, 40 -> minium vel 30 // pos, wagonlength, startvel , startacc, trainmass, wagoncolor - Wagon tmpr = Wagon(maxid++,NUMPIXELS,&strip, height, random(0, 20), _randomlength, random(map(_randomlength,3,40,10,30), map(_randomlength,3,40, 20,60))/10.0 , 0 , 20 , Wheel((uint8_t)random(0,255))); //spawn new wagon + Wagon tmpr = Wagon(maxid++,NUMPIXELS,&strip, height, random(0, 20), _randomlength, random(map(_randomlength,3,40,1,1), map(_randomlength,3,40, 13,40))/10.0 , 0 , 5 , Wheel((uint8_t)random(0,255))); //spawn new wagon wagon_arr.push_back(tmpr); Serial.println("Spawned Wagon"); diff --git a/wagon.cpp b/wagon.cpp index dec038d..df9cd14 100644 --- a/wagon.cpp +++ b/wagon.cpp @@ -1,14 +1,14 @@ #include "wagon.h" -#define SLOWVELOCITY 0.1 - -#define WAGONLENGTH 5 +#define WAGONLENGTH 3 #define EDGE_WALL //#define EDGE_BOUNCE //#define EDGE_WRAP + #define WRAPLEDPOS _numpixels //standard + //#define WRAPLEDPOS (_numpixels-5) //led index which is also led 0 -uint8_t GammaE[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +/*uint8_t GammaE[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 7, 7, 7, 8, 8, 8, 9, 9, 9, 10, 10, 11, 11, @@ -22,8 +22,8 @@ uint8_t GammaE[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 111,113,114,116,117,119,120,121,123,124,126,128,129,131,132,134, 135,137,138,140,142,143,145,146,148,150,151,153,155,157,158,160, 162,163,165,167,169,170,172,174,176,178,179,181,183,185,187,189, -191,193,194,196,198,200,202,204,206,208,210,212,214,216,218,220, -222,224,227,229,231,233,235,237,239,241,244,246,248,250,252,255}; +191,193,194,196,198,200,202,204,206,208,210,212,214,216,218,220, +222,224,227,229,231,233,235,237,239,241,244,246,248,250,252,255}; */ Wagon::Wagon(int id,int numpixels, Adafruit_NeoPixel *strip,uint8_t *height,float pos, float trainlength,float startvel,float startacc, float wagonmass, uint32_t wagoncolor) { @@ -153,9 +153,10 @@ void Wagon::updatePhysics(float updatedelayms) _lastvel=_vel; - if (_pos>=_numpixels){ + + if (_pos>=WRAPLEDPOS){ #ifdef EDGE_WRAP - _pos-=_numpixels; //Wrap around edges + _pos-=WRAPLEDPOS; //Wrap around edges #endif #ifdef EDGE_BOUNCE _vel*=-1; //bounce at edges @@ -166,7 +167,7 @@ void Wagon::updatePhysics(float updatedelayms) } if (_pos<0){ #ifdef EDGE_WRAP - _pos=_numpixels+_pos; //warp around edges + _pos=WRAPLEDPOS+_pos; //warp around edges #endif #ifdef EDGE_BOUNCE _vel*=-1;; //bounce at edges @@ -188,14 +189,14 @@ float Wagon::getHeight(int p){ if (p<0){ #ifdef EDGE_WRAP - p=numpixels+p; //wrap edge + p=_numpixels+p; //wrap edge #endif #ifdef EDGE_WALL return _height[0]+p*-100.0; //edges as wall #endif }else if(p>=_numpixels){ #ifdef EDGE_WRAP - p=p-numpixels; //wrap edge + p=p-_numpixels; //wrap edge #endif #ifdef EDGE_WALL return _height[_numpixels-1]+(p-_numpixels)*100.0; //edges as wall @@ -244,11 +245,18 @@ void Wagon::updateGraphics() _g*=featherbrightness; _b*=featherbrightness; - _r=GammaE[_r]; + /*_r=GammaE[_r]; _g=GammaE[_g]; - _b=GammaE[_b]; + _b=GammaE[_b];*/ - uint32_t _pxcolor=_strip->getPixelColor(i); //get current color of that pixel + int iCorrected=i; + #ifdef EDGE_WRAP + if (i<0){ + iCorrected=WRAPLEDPOS+i+1; //Wrap around edges + } + #endif + + uint32_t _pxcolor=_strip->getPixelColor(iCorrected); //get current color of that pixel uint8_t _pxr = _pxcolor >> 16; uint8_t _pxg = _pxcolor >> 8; uint8_t _pxb = _pxcolor; @@ -264,7 +272,7 @@ void Wagon::updateGraphics() if (_tmpb>255){ _tmpb=255; } - _strip->setPixelColor(i,_tmpr,_tmpg,_tmpb); //draw pixel + _strip->setPixelColor(iCorrected,_tmpr,_tmpg,_tmpb); //draw pixel } }