Open Source Tomb Raider Engine
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

Particle.cpp 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. /*!
  2. * \file src/Particle.cpp
  3. * \brief Particle system base implementation
  4. *
  5. * \author Mongoose
  6. */
  7. #include <stdlib.h>
  8. #include <stdio.h>
  9. #include "Particle.h"
  10. Particle::Particle()
  11. {
  12. setActive(true);
  13. TextureId(0);
  14. Speed(2000.0f, 2000.0f, 2000.0f);
  15. Color(1.0f, 1.0f, 1.0f);
  16. Force(0.0f, 0.8f, 0.0f);
  17. Reset();
  18. }
  19. Particle::~Particle()
  20. {
  21. }
  22. void Particle::TextureId(int id)
  23. {
  24. _texture = id;
  25. }
  26. void Particle::setActive(bool active)
  27. {
  28. _active = active;
  29. }
  30. void Particle::Speed(float x, float y, float z)
  31. {
  32. _speed[0] = x;
  33. _speed[1] = y;
  34. _speed[2] = z;
  35. }
  36. void Particle::Color(float r, float g, float b)
  37. {
  38. _color[0] = r;
  39. _color[1] = g;
  40. _color[2] = b;
  41. }
  42. void Particle::Force(float x, float y, float z)
  43. {
  44. _force[0] = x;
  45. _force[1] = y;
  46. _force[2] = z;
  47. }
  48. void Particle::Reset()
  49. {
  50. // Mongoose 2002.01.01, Ah, how old is that code?
  51. #ifdef OBSOLETE
  52. _active = true;
  53. _life = 1.0;
  54. _blend = (float)(rand() % 100) / 1000.0 + 0.003;
  55. _pos[0] = _pos[1] = _pos[2] = 0.0;
  56. _dir[0] = (float)((rand() % 50) - 26.0) * 10.0;
  57. _dir[1] = (float)((rand() % 50) - 25.0) * 10.0;
  58. _dir[2] = _dir[1];
  59. _force[0] = 0.0;
  60. _force[1] = -0.8;
  61. _force[2] = 0.0;
  62. #else
  63. //! \fixme _blend prob should have nonstatic range
  64. _blend = (float)(0.003 + (0.1 * rand() / (RAND_MAX + 1.0))); // high order
  65. //_blend = (float)(rand() % 100) / 1000.0 + 0.003;
  66. //! \fixme Reset these using some nonstatic functions and values later
  67. _life = 1.0;
  68. _pos[0] = _pos[1] = _pos[2] = 0.0;
  69. _dir[0] = (float)(-26.0 + (50.0 * rand() / (RAND_MAX + 1.0))); // high order
  70. _dir[0] *= 10.0;
  71. //_dir[0] = (float)((rand() % 50) - 26.0) * 10.0;
  72. _dir[1] = (float)(-25.0 + (50.0 * rand() / (RAND_MAX + 1.0))); // high order
  73. _dir[1] *= 10.0;
  74. //_dir[1] = (float)((rand() % 50) - 25.0) * 10.0;
  75. _dir[2] = _dir[1];
  76. #endif
  77. }
  78. void Particle::Pos(float *x, float *y, float *z)
  79. {
  80. *x = _pos[0];
  81. *y = _pos[1];
  82. *z = _pos[2];
  83. }
  84. void Particle::Color(float *r, float *g, float *b)
  85. {
  86. *r = _color[0];
  87. *g = _color[1];
  88. *b = _color[2];
  89. }
  90. float Particle::Life()
  91. {
  92. return _life;
  93. }
  94. void Particle::Update()
  95. {
  96. // Adjust particle position
  97. _pos[0] += _dir[0] / _speed[0];
  98. _pos[1] += _dir[1] / _speed[1];
  99. _pos[2] += _dir[2] / _speed[2];
  100. // Adjust particle direction
  101. _dir[0] += _force[0];
  102. _dir[1] += _force[1];
  103. _dir[2] += _force[2];
  104. // Adjust particle blending/life
  105. _life -= _blend;
  106. // Reset 'dead' OR fully blended particles
  107. if (_life < 0.0)
  108. {
  109. Reset();
  110. }
  111. }
  112. int Particle::Texture()
  113. {
  114. return _texture;
  115. }
  116. bool Particle::isActive()
  117. {
  118. return _active;
  119. }