Open Source Tomb Raider Engine
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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. /* -*- Mode: C++; tab-width: 3; indent-tabs-mode: t; c-basic-offset: 3 -*- */
  2. /*================================================================
  3. *
  4. * Project : Freyja
  5. * Author : Terry 'Mongoose' Hendrix II
  6. * Website : http://www.westga.edu/~stu7440/
  7. * Email : stu7440@westga.edu
  8. * Object : Particle
  9. * License : No use w/o permission (C)2001Mongoose
  10. * Comments: Partcle system's atomic base
  11. *
  12. *
  13. * This file was generated using Mongoose's C++
  14. * template generator script. <stu7440@westga.edu>
  15. *
  16. *-- History -------------------------------------------------
  17. *
  18. * 2001.08.13:
  19. * Mongoose - Created
  20. =================================================================*/
  21. #include <stdlib.h>
  22. #include <stdio.h>
  23. #include "Particle.h"
  24. #ifdef DEBUG_MEMEORY
  25. # include "memeory_test.h"
  26. #endif
  27. Particle::Particle()
  28. {
  29. setActive(true);
  30. TextureId(0);
  31. Speed(2000.0, 2000.0, 2000.0);
  32. Color(1.0, 1.0, 1.0);
  33. Force(0.0, 0.8, 0.0);
  34. Reset();
  35. }
  36. Particle::~Particle()
  37. {
  38. }
  39. void Particle::TextureId(int id)
  40. {
  41. _texture = id;
  42. }
  43. void Particle::setActive(bool active)
  44. {
  45. _active = active;
  46. }
  47. void Particle::Speed(float x, float y, float z)
  48. {
  49. _speed[0] = x;
  50. _speed[1] = y;
  51. _speed[2] = z;
  52. }
  53. void Particle::Color(float r, float g, float b)
  54. {
  55. _color[0] = r;
  56. _color[1] = g;
  57. _color[2] = b;
  58. }
  59. void Particle::Force(float x, float y, float z)
  60. {
  61. _force[0] = x;
  62. _force[1] = y;
  63. _force[2] = z;
  64. }
  65. void Particle::Reset()
  66. {
  67. // Mongoose 2002.01.01, Ah, how old is that code?
  68. #ifdef OBSOLOETE
  69. _active = true;
  70. _life = 1.0;
  71. _blend = (float)(rand() % 100) / 1000.0 + 0.003;
  72. _pos[0] = _pos[1] = _pos[2] = 0.0;
  73. _dir[0] = (float)((rand() % 50) - 26.0) * 10.0;
  74. _dir[1] = (float)((rand() % 50) - 25.0) * 10.0;
  75. _dir[2] = _dir[1];
  76. _force[0] = 0.0;
  77. _force[1] = -0.8;
  78. _force[2] = 0.0;
  79. #else
  80. // FIXME: _blend prob should have nonstatic range
  81. _blend = (float)(0.003 + (0.1 * rand() / (RAND_MAX + 1.0))); // high order
  82. //_blend = (float)(rand() % 100) / 1000.0 + 0.003;
  83. // FIXME: Reset these using some nonstatic functions and values later
  84. _life = 1.0;
  85. _pos[0] = _pos[1] = _pos[2] = 0.0;
  86. _dir[0] = (float)(-26.0 + (50.0 * rand() / (RAND_MAX + 1.0))); // high order
  87. _dir[0] *= 10.0;
  88. //_dir[0] = (float)((rand() % 50) - 26.0) * 10.0;
  89. _dir[1] = (float)(-25.0 + (50.0 * rand() / (RAND_MAX + 1.0))); // high order
  90. _dir[1] *= 10.0;
  91. //_dir[1] = (float)((rand() % 50) - 25.0) * 10.0;
  92. _dir[2] = _dir[1];
  93. #endif
  94. }
  95. void Particle::Pos(float *x, float *y, float *z)
  96. {
  97. *x = _pos[0];
  98. *y = _pos[1];
  99. *z = _pos[2];
  100. }
  101. void Particle::Color(float *r, float *g, float *b)
  102. {
  103. *r = _color[0];
  104. *g = _color[1];
  105. *b = _color[2];
  106. }
  107. float Particle::Life()
  108. {
  109. return _life;
  110. }
  111. void Particle::Update()
  112. {
  113. // Adjust particle position
  114. _pos[0] += _dir[0] / _speed[0];
  115. _pos[1] += _dir[1] / _speed[1];
  116. _pos[2] += _dir[2] / _speed[2];
  117. // Adjust particle direction
  118. _dir[0] += _force[0];
  119. _dir[1] += _force[1];
  120. _dir[2] += _force[2];
  121. // Adjust particle blending/life
  122. _life -= _blend;
  123. // Reset 'dead' OR fully blended particles
  124. if (_life < 0.0)
  125. {
  126. Reset();
  127. }
  128. }
  129. int Particle::Texture()
  130. {
  131. return _texture;
  132. }
  133. bool Particle::isActive()
  134. {
  135. return _active;
  136. }