Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2017
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.09 KB | None | 0 0
  1. void Sable::scanParticle(QPointF p)
  2. {
  3.     QVector<Particle>::iterator itP;
  4.         for (itP = particles.begin(); itP != particles.end(); ++itP)
  5.         {
  6.             if (qAbs(p.x() - itP->x()) < RAYON &&
  7.                 qAbs(p.y() - itP->y()) < RAYON)
  8.             {
  9.                 QVector2D dir = QVector2D(p.x() - itP->x(),
  10.                                           p.y() - itP->y());
  11.                 double dist = dir.length();
  12.                 if (dist < RAYON)
  13.                 {
  14.                     dir.normalize();
  15.                     QVector2D deltaPos = 3*dir*(RAYON-dist);
  16.                     itP->setX(itP->x() - deltaPos.x());
  17.                     itP->setY(itP->y() - deltaPos.y());
  18.                 }
  19.             }
  20.         }
  21.  
  22.         this->update();
  23. }
  24.  
  25.  
  26.  
  27. void Particle::drawSand(const QVector<Particle> &ps)
  28. {
  29.     glEnableClientState(GL_VERTEX_ARRAY);
  30.     glVertexPointer(2, GL_DOUBLE, sizeof(Particle), &(ps[0].m_x));
  31.     glEnableClientState(GL_COLOR_ARRAY);
  32.     glColorPointer(3, GL_DOUBLE, sizeof(Particle), &(ps[0].r));
  33.     glDrawArrays(GL_POINTS, 0, ps.count());
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement