Quelcode des Partikelsystems Boden
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

particle.cpp 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. // particle.cpp
  2. // particleSystem
  3. //
  4. #include "particle.h"
  5. #include "ofApp.h"
  6. Particle::Particle()
  7. {
  8. }
  9. //--------------------------------------------------------------------------------------
  10. Particle::~Particle()
  11. {
  12. }
  13. //--------------------------------------------------------------------------------------
  14. void Particle::setup(ofVec2f _position) {
  15. this->position = _position;
  16. vel.set(ofRandom(-3.0, 3.0), ofRandom(-3.0, 3.0));
  17. age = 0.0;
  18. maxLife = 12.0;
  19. color.set(250, 250, 250);
  20. size = ofRandom(4.0, 0.01);
  21. mass = ofRandom(100, 250);
  22. tex.load("img/overlay.png");
  23. }
  24. //--------------------------------------------------------------------------------------
  25. void Particle::update(float deltaT, vector<Attractor*>* attractors) {
  26. ofVec2f force;
  27. counterOfActiveAttractors = 0;
  28. for (int i = 0; i < attractors->size(); i++) {
  29. if (attractors->at(i)->getX() == 0 && attractors->at(i)->getY() == 0) {
  30. force = 0 * force.getNormalized();
  31. vel += force;
  32. vel = mass * vel.getNormalized();
  33. break;
  34. }
  35. counterOfActiveAttractors++;
  36. force.set(attractors->at(i)->getX() - position.x, attractors->at(i)->getY() - position.y);
  37. if (force.length() < 150) {
  38. force = 60 * force.getNormalized();
  39. size = size + ofRandom(.01, 0.01);
  40. vel += force;
  41. vel = mass * vel.getNormalized();
  42. }
  43. else {
  44. force = 0 * force.getNormalized();
  45. vel += force;
  46. vel = mass * vel.getNormalized();
  47. }
  48. }
  49. age += deltaT * .5;
  50. position += (vel * deltaT);
  51. // *** COLLISION *** COLLISION *** COLLISION *** COLLISION *** COLLISION *** COLLISION
  52. //if (position.x <= 0 || position.x >= ofGetWidth()) {
  53. //vel.x = -vel.x;
  54. //position += (vel * deltaT);
  55. //}
  56. //else if (position.y <= 0 || position.y >= ofGetHeight()) {
  57. //vel.y = -vel.y;
  58. //position += (vel * deltaT);
  59. //}
  60. //else {
  61. //position += (vel * deltaT);
  62. //}
  63. //void thParticle::update(float deltaT, ofVec2f attractor){
  64. //
  65. //
  66. // age += deltaT;
  67. //
  68. // ofVec2f force = attractor - position;
  69. // color.set(250,250, 250, (1 - age / maxLife) * 255);
  70. //
  71. // if( force.length() < 40 && force.length() > 11 ){
  72. // velocity = velocity.getNormalized() * mass;
  73. // velocity += 0.01 * force ;
  74. //
  75. // }else if(force.length() < 12){
  76. // velocity = velocity.getNormalized() * mass;
  77. // velocity += 5 * force ;
  78. //
  79. // }else{
  80. //
  81. // velocity = velocity.getNormalized() * mass;
  82. // velocity += 0.12 * force ;
  83. // }
  84. // position += velocity * deltaT;
  85. //}
  86. }
  87. //--------------------------------------------------------------------------------------
  88. void Particle::draw() {
  89. color.set(getAgeNorm() * 241,241/ getAgeNorm() ,219);
  90. ofSetColor(color, (1 - getAgeNorm()) * 255);
  91. //tex.setColor(color);
  92. //tex.draw(position, size, size);
  93. ofDrawCircle(position, size);
  94. }
  95. //--------------------------------------------------------------------------------------
  96. float Particle::getAgeNorm() {
  97. return age / maxLife;
  98. }
  99. //--------------------------------------------------------------------------------------
  100. float Particle::getMaxLife() {
  101. return 1;
  102. }
  103. //--------------------------------------------------------------------------------------