1 | // |
---|

2 | // Orbital |
---|

3 | // |
---|

4 | // Copyright: (c) 2012 Various People |
---|

5 | // |
---|

6 | |
---|

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

8 | |
---|

9 | #if !defined __PARTICLESYSTEM_H__ |
---|

10 | #define __PARTICLESYSTEM_H__ |
---|

11 | |
---|

12 | class ParticleSystem : public WorldEntity |
---|

13 | { |
---|

14 | public: |
---|

15 | ParticleSystem() |
---|

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

17 | m_ready(false) |
---|

18 | { |
---|

19 | m_mesh.SendCommand("sc.8,.8,.8,1,acg8,2,5,5,1.5,1.5,.1,0,rx15"); |
---|

20 | m_mesh.SendCommand("t0,-100,-30,fl"); |
---|

21 | |
---|

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

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

24 | } |
---|

25 | |
---|

26 | ~ParticleSystem() |
---|

27 | { |
---|

28 | } |
---|

29 | |
---|

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

31 | |
---|

32 | protected: |
---|

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

34 | { |
---|

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

36 | |
---|

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

38 | { |
---|

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

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

41 | { |
---|

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

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

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

45 | } |
---|

46 | |
---|

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

48 | } |
---|

49 | |
---|

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

51 | } |
---|

52 | |
---|

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

54 | { |
---|

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

56 | |
---|

57 | if (!m_ready) |
---|

58 | { |
---|

59 | m_mesh.SendCommand("irb"); |
---|

60 | m_ready = true; |
---|

61 | } |
---|

62 | |
---|

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

64 | { |
---|

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

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

67 | |
---|

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

69 | } |
---|

70 | } |
---|

71 | |
---|

72 | private: |
---|

73 | Mesh m_mesh; |
---|

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

75 | float m_angle; |
---|

76 | bool m_ready; |
---|

77 | }; |
---|

78 | |
---|

79 | #endif /* __PARTICLESYSTEM_H__ */ |
---|

80 | |
---|