source: trunk/orbital/starfield.h @ 1365

Last change on this file since 1365 was 1365, checked in by sam, 11 years ago

orbital: better starfield randomising.

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