1 | // |
---|

2 | // Orbital |
---|

3 | // |
---|

4 | // Copyright: (c) 2009-2012 Cédric Lecacheur <jordx@free.fr> |
---|

5 | // (c) 2009-2012 Benjamin Huet <huet.benjamin@gmail.com> |
---|

6 | // (c) 2012 Sam Hocevar <sam@hocevar.net> |
---|

7 | // |
---|

8 | |
---|

9 | /* FIXME: this file is pure crap; it's only a test. */ |
---|

10 | |
---|

11 | #if !defined __PARTICLESYSTEM_H__ |
---|

12 | #define __PARTICLESYSTEM_H__ |
---|

13 | |
---|

14 | class ParticleSystem : public WorldEntity |
---|

15 | { |
---|

16 | public: |
---|

17 | ParticleSystem() |
---|

18 | : m_angle(0.f), |
---|

19 | m_ready(false) |
---|

20 | { |
---|

21 | m_mesh.Compile("[sc#ccc acg8 2 5 5 1.5 1.5 .1 0 rx15 t0 -100 -30]"); |
---|

22 | |
---|

23 | for (int i = 0; i < 200; i++) |
---|

24 | m_particles.Push(vec3(0), vec3(0), RandF(0.f, 2.f)); |
---|

25 | } |
---|

26 | |
---|

27 | ~ParticleSystem() |
---|

28 | { |
---|

29 | } |
---|

30 | |
---|

31 | char const *GetName() { return "<particlesystem>"; } |
---|

32 | |
---|

33 | protected: |
---|

34 | virtual void TickGame(float seconds) |
---|

35 | { |
---|

36 | WorldEntity::TickGame(seconds); |
---|

37 | |
---|

38 | for (int i = 0; i < m_particles.Count(); i++) |
---|

39 | { |
---|

40 | m_particles[i].m3 += seconds; |
---|

41 | if (m_particles[i].m3 > 2.f) |
---|

42 | { |
---|

43 | m_particles[i].m1 = vec3(RandF(-1.f, 1.f), RandF(-1.f, 1.f), RandF(-1.f, 1.f)); |
---|

44 | m_particles[i].m2 = normalize(vec3(RandF(-1.f, 1.f), RandF(-1.f, 1.f), RandF(-1.f, 1.f))); |
---|

45 | m_particles[i].m3 = RandF(0.f, 2.f); |
---|

46 | } |
---|

47 | |
---|

48 | m_particles[i].m1 += seconds * 100.f * m_particles[i].m2; |
---|

49 | } |
---|

50 | |
---|

51 | m_angle += seconds * 100.f; |
---|

52 | } |
---|

53 | |
---|

54 | virtual void TickDraw(float seconds) |
---|

55 | { |
---|

56 | WorldEntity::TickDraw(seconds); |
---|

57 | |
---|

58 | if (!m_ready) |
---|

59 | { |
---|

60 | m_mesh.MeshConvert(); |
---|

61 | m_ready = true; |
---|

62 | } |
---|

63 | |
---|

64 | for (int i = 0; i < m_particles.Count(); i++) |
---|

65 | { |
---|

66 | mat4 model = mat4::translate(vec3(0, 0, -100)) |
---|

67 | * mat4::translate(m_particles[i].m1);; |
---|

68 | |
---|

69 | m_mesh.Render(model); |
---|

70 | } |
---|

71 | } |
---|

72 | |
---|

73 | private: |
---|

74 | EasyMesh m_mesh; |
---|

75 | Array<vec3, vec3, float> m_particles; |
---|

76 | float m_angle; |
---|

77 | bool m_ready; |
---|

78 | }; |
---|

79 | |
---|

80 | #endif /* __PARTICLESYSTEM_H__ */ |
---|

81 | |
---|