/src/renderer/particles.h

https://bitbucket.org/vivkin/gam3b00bs/ · C Header · 72 lines · 57 code · 15 blank · 0 comment · 0 complexity · c617f586c6959995a1ba754cac9cdaff MD5 · raw file

  1. #pragma once
  2. #include "common.h"
  3. #include "renderer/device.h"
  4. #define PARTICLES_MAX 512
  5. #define PARTICLE_EMITTERS_MAX 64
  6. struct particle_vertex_t
  7. {
  8. FLOAT x, y, z;
  9. DWORD color;
  10. FLOAT u, v;
  11. };
  12. struct particle_t
  13. {
  14. particle_vertex_t vertices[4];
  15. D3DXVECTOR3 position, direction;
  16. float size, life;
  17. };
  18. struct particle_emitter_t
  19. {
  20. struct
  21. {
  22. texture_h texture;
  23. vbuffer_h vb;
  24. } visual;
  25. particle_t particles[PARTICLES_MAX];
  26. uint32_t particles_count;
  27. D3DXVECTOR3 position, direction;
  28. float speed[2], life[2], size[2], color[2][3]; // min/max
  29. float spawn_rate, spawn_last, spawn_time; // spawns per second
  30. };
  31. struct particle_system_t
  32. {
  33. struct
  34. {
  35. ibuffer_h ib;
  36. vertex_layout_h vlayout;
  37. D3DXMATRIX transform;
  38. } visual;
  39. particle_emitter_t emitters[PARTICLE_EMITTERS_MAX];
  40. uint32_t emitters_count;
  41. };
  42. struct particle_desc_t
  43. {
  44. texture_h texture;
  45. D3DXVECTOR3 position;
  46. D3DXVECTOR3 direction;
  47. float speed[2];
  48. float life[2];
  49. float size[2];
  50. float color[2][3];
  51. float rate;
  52. float time;
  53. };
  54. void particle_system_create(particle_system_t *psys);
  55. void particle_system_add(particle_system_t *psys, const particle_desc_t *desc);
  56. void particle_system_update(particle_system_t *psys, const camera_t &camera, float dt);
  57. void particle_system_render(particle_system_t *psys, const camera_t &camera, LPDIRECT3DDEVICE9 device);