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

Particle emitter test.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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
Note: See TracChangeset for help on using the changeset viewer.