Changeset 290


Ignore:
Timestamp:
Jan 26, 2011, 1:33:37 AM (8 years ago)
Author:
sam
Message:

Particle emitter test.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/monsterz/board.cpp

    r289 r290  
    3939    Piece *grabbed;
    4040    Mash *mashes;
     41    Emitter *emitter;
    4142    Int2 src_cell, dst_cell;
    4243
     
    6970    data->whip = Sampler::Register(WAV_WHIP);
    7071
     72    data->emitter = new Emitter(data->tiles, Float3(0, -0.0004, 0));
     73    Ticker::Ref(data->emitter);
     74
    7175    srand(rand() ^ time(NULL));
    7276
     
    103107{
    104108    Entity::TickGame(deltams);
     109
     110    /* Temporary test: add a few particles */
     111    for(int n = 0; n < 10; n++)
     112        data->emitter->AddParticle(110 + 20 * (rand() % 7),
     113               Float3(rand() % 500, rand() % 500, 20),
     114               Float3(1.e-3f * (rand() % 500 - 250),
     115                      1.e-3f * (rand() % 500 - 250), 0));
    105116
    106117    Int2 mouse = Input::GetMousePos();
     
    365376        data->mashes = data->mashes->nextmash;
    366377    }
     378    Ticker::Unref(data->emitter);
    367379    Tiler::Deregister(data->board);
    368380    Tiler::Deregister(data->screen);
  • trunk/src/emitter.cpp

    r288 r290  
    4949void Emitter::TickGame(float deltams)
    5050{
     51    for (int i = 0; i < data->nparticles; i++)
     52    {
     53        data->velocities[i] = data->velocities[i] + deltams * data->gravity;
     54        data->positions[i] = data->positions[i] + deltams * data->velocities[i];
     55        if (data->positions[i].y < -100)
     56        {
     57            data->particles[i] = data->particles[data->nparticles - 1];
     58            data->positions[i] = data->positions[data->nparticles - 1];
     59            data->velocities[i] = data->velocities[data->nparticles - 1];
     60            data->nparticles--;
     61        }
     62    }
     63
    5164    Entity::TickGame(deltams);
    5265}
     
    5568{
    5669    Entity::TickDraw(deltams);
     70
     71    for (int i = 0; i < data->nparticles; i++)
     72        Scene::GetDefault()->AddTile((data->tiler << 16) | data->particles[i],
     73                                     data->positions[i].x,
     74                                     data->positions[i].y,
     75                                     data->positions[i].z, 0);
     76}
     77
     78void Emitter::AddParticle(int id, Float3 pos, Float3 vel)
     79{
     80    if (data->nparticles >= 100)
     81        return;
     82
     83    data->particles[data->nparticles] = id;
     84    data->positions[data->nparticles] = pos;
     85    data->velocities[data->nparticles] = vel;
     86    data->nparticles++;
    5787}
    5888
  • trunk/src/emitter.h

    r288 r290  
    2727    virtual ~Emitter();
    2828
     29    void AddParticle(int id, Float3 pos, Float3 vel);
     30
    2931protected:
    3032    virtual void TickGame(float deltams);
Note: See TracChangeset for help on using the changeset viewer.