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 __STARFIELD_H__ |
---|
12 | #define __STARFIELD_H__ |
---|
13 | |
---|
14 | class StarField : public WorldEntity |
---|
15 | { |
---|
16 | public: |
---|
17 | StarField(int count, float z, float speed) |
---|
18 | : m_ready(false) |
---|
19 | { |
---|
20 | if (z == 1.f) |
---|
21 | m_mesh.SendCommand("sc1,1,1,1,scb1,1,1,0,ad4,1.8,1"); |
---|
22 | else |
---|
23 | m_mesh.SendCommand("sc1,1,1,1,scb1,1,1,0,ad3,0.8,1"); |
---|
24 | |
---|
25 | for (int i = 0; i < count; i++) |
---|
26 | m_stars.Push(vec3(RandF(-220.f, 220.f), z, RandF(-150.f, 300.f)), |
---|
27 | vec3(0.f, 0.f, speed), |
---|
28 | RandF(0.f, 10.f)); |
---|
29 | } |
---|
30 | |
---|
31 | ~StarField() |
---|
32 | { |
---|
33 | } |
---|
34 | |
---|
35 | char const *GetName() { return "<starfield>"; } |
---|
36 | |
---|
37 | protected: |
---|
38 | virtual void TickGame(float seconds) |
---|
39 | { |
---|
40 | WorldEntity::TickGame(seconds); |
---|
41 | |
---|
42 | for (int i = 0; i < m_stars.Count(); i++) |
---|
43 | { |
---|
44 | m_stars[i].m3 += 10.f * seconds; |
---|
45 | m_stars[i].m1 += seconds * m_stars[i].m2; |
---|
46 | if (m_stars[i].m1.z > 300.f) |
---|
47 | { |
---|
48 | m_stars[i].m1.x = RandF(-220.f, 220.f); |
---|
49 | m_stars[i].m1.z = RandF(-152.f, -150.f); |
---|
50 | } |
---|
51 | } |
---|
52 | } |
---|
53 | |
---|
54 | virtual void TickDraw(float seconds) |
---|
55 | { |
---|
56 | WorldEntity::TickDraw(seconds); |
---|
57 | |
---|
58 | if (!m_ready) |
---|
59 | { |
---|
60 | m_mesh.SendCommand("irb"); |
---|
61 | m_ready = true; |
---|
62 | } |
---|
63 | |
---|
64 | for (int i = 0; i < m_stars.Count(); i++) |
---|
65 | { |
---|
66 | mat4 model = mat4::translate(m_stars[i].m1) |
---|
67 | * mat4::rotate(m_stars[i].m3, 0.f, 1.f, 0.f); |
---|
68 | |
---|
69 | m_mesh.Render(model); |
---|
70 | } |
---|
71 | } |
---|
72 | |
---|
73 | private: |
---|
74 | Mesh m_mesh; |
---|
75 | Array<vec3, vec3, float> m_stars; |
---|
76 | bool m_ready; |
---|
77 | }; |
---|
78 | |
---|
79 | #endif /* __STARFIELD_H__ */ |
---|
80 | |
---|