Subversion Repositories DIN Is Noise

Rev

Rev 215 | Rev 471 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

/*
* trail.cc
* DIN Is Noise is copyright (c) 2006-2017 Jagannathan Sampath
* For more information, please visit http://dinisnoise.org/
*/


#include "dingl.h"
#include "trail.h"

trail_t::trail_t (int _e, int _max) {
  max_points = _max;
  num_points = 0;
}

void trail_t::add (float x, float y) {
  if (x != last.x || y != last.y) {
    int dt = num_points - max_points;
    if (dt >= 0) {
      int npops = dt + 1;
      for (int i = 0; i < npops; ++i) tq.pop_front ();
      num_points -= npops;
    }      
    tq.push_back (point<float>(x, y));
    ++num_points;
    last.x = x;
    last.y = y;
  }
}

void trail_t::change_size (int delta) {
  max_points += delta;
  if (max_points < 1) max_points = 1;
}

void trail_t::draw () {
  if (n_tpts < num_points) {
    if (tpts) delete[] tpts;
    tpts = new float [2 * num_points];
    n_tpts = num_points;
  }
  int m = 0, n = 0;
  for (std::list< point<float> >::iterator iter = tq.begin (), jter = tq.end (); iter != jter; ++iter) {
    point<float>& p = *iter;
    tpts[m++] = p.x; tpts[m++]=p.y;
    ++n;
  }
  glVertexPointer (2, GL_FLOAT, 0, tpts);
  glDrawArrays (GL_LINE_STRIP, 0, n);
}