Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 10442 in orxonox.OLD for branches


Ignore:
Timestamp:
Jan 28, 2007, 2:56:01 PM (18 years ago)
Author:
stefalie
Message:

blink: everything(?) done

Location:
branches/blink/src/world_entities/effects
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/blink/src/world_entities/effects/blink.cc

    r10436 r10442  
    3535  if(root)
    3636    this->loadParams(root);
     37
     38  // calculation of the symbolTime
     39  this->symbolTime = this->period / this->blinkSequence.length();
    3740}
    3841
     
    6871  // 10x10 pxl if not defined in xml
    6972  this->size = 10;
    70   // default angular rate
    71   this->omega = 10;
     73  // default period
     74  this->period = 1;
     75  // default blink sequence
     76  this->blinkSequence = "00011234567889998876543211";
    7277
    73   // random start angle, blinkies shouldn't blink synchronous
    74   this->angle = (float)rand()/(float)RAND_MAX * 2 * M_PI;
     78  // start values of non-loadable variables
     79  this->blinkStr = 0;
     80  this->timer = 0;
     81  this->seqCounter = 0;
    7582}
    7683
     
    8794  LoadParam(root, "size", this, Blink, setSize);
    8895  LoadParam(root, "color", this, Blink, setColor);
    89   LoadParam(root, "omega", this, Blink, setOmega);
     96  LoadParam(root, "period", this, Blink, setPeriod);
     97  LoadParam(root, "sequence", this, Blink, loadBlinkSequence);
    9098}
    9199
     
    97105void Blink::tick(float dt)
    98106{
    99   this->angle += dt * this->omega;
     107  timer += dt;
    100108
    101   while (this->angle > 2 * M_PI)
    102     this->angle -= 2 * M_PI;
     109  while(this->timer >= this->symbolTime)
     110  {
     111    this->blinkStr = (float)((int)(blinkSequence[seqCounter]) - 48) / 9;
    103112
    104   // blinkStr should be element of [0, 1]
    105   this->blinkStr = (sinf(angle) + 1) / 2;
     113    this->timer -= symbolTime;
     114
     115    seqCounter++;
     116    seqCounter %= this->blinkSequence.length();
     117  }
    106118
    107119  this->bBoard->colorTexture(Color(color.r(), color.g(), color.b(), this->blinkStr));
  • branches/blink/src/world_entities/effects/blink.h

    r10433 r10442  
    22 * @file blink.h
    33 */
     4 /*! example input in .oxw file with the standard values
     5
     6<Blink>
     7  <name>Blink1</name>
     8  <position>580, 70, -130</position>
     9  <color>0, 255, 255</color>
     10  <size>8</size>
     11  <period>9</period>
     12  <sequence>0123456789</sequence><!-- the number describe the strength of the blink light -->
     13</Blink>
     14
     15*/
    416
    517#ifndef _BLINK_H
     
    2638    void setPosition(float x, float y, float z) { this->bBoard->setAbsCoor(x, y, z); }
    2739    void setSize(float s) { this->size = s; this->bBoard->setSize(this->size, this->size); }
    28     void setOmega(float w) { this->omega = w; }
     40    void setPeriod(float t) { this->period = t; }
    2941    void setColor(float r, float g, float b) { this->color = Color(r/255, g/255, b/255); }
     42    void loadBlinkSequence(const std::string& seq) { this->blinkSequence = seq; }
    3043
    3144    virtual void tick(float dt);
     
    3548    Billboard*        bBoard;
    3649    Color             color;
     50    std::string       blinkSequence;    //! 1 means fully viewable, 0 means fully transparent
    3751    float             angle;
    38     float             omega;
     52    float             period;           //! period in seconds
    3953    float             blinkStr;
    4054    float             size;             //! only one float caus' its quadratical
     55    int               seqCounter;
     56    float             symbolTime;       //! defines how long one symbol of the sequence will be shown in sec
     57    float             timer;
    4158};
    4259
Note: See TracChangeset for help on using the changeset viewer.