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 "<particlesystme>"; } |
---|

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 | mat4 anim = mat4::rotate(m_angle, vec3(0, 1, 0)); |
---|

63 | mat4 view = mat4::lookat(vec3(0, 2, 0), vec3(0, 0, -4), vec3(0, 1, 0)); |
---|

64 | mat4 proj = mat4::perspective(45.0f, 640.0f, 480.0f, 0.1f, 10.0f); |
---|

65 | |
---|

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

67 | { |
---|

68 | mat4 model = mat4::translate(vec3(0, 0, -4.5)) |
---|

69 | * mat4::scale(vec3(0.025)) |
---|

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

71 | mat4 modelview = view * model * anim; |
---|

72 | |
---|

73 | m_mesh.Render(modelview, proj); |
---|

74 | } |
---|

75 | } |
---|

76 | |
---|

77 | private: |
---|

78 | Mesh m_mesh; |
---|

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

80 | float m_angle; |
---|

81 | bool m_ready; |
---|

82 | }; |
---|

83 | |
---|

84 | #endif /* __PARTICLESYSTEM_H__ */ |
---|

85 | |
---|