source: trunk/orbital/tank.h @ 1423

Last change on this file since 1423 was 1423, checked in by sam, 9 years ago

orbital: fix copyright statements.

File size: 1.9 KB
Line 
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 __TANK_H__
12#define __TANK_H__
13
14class Tank : public WorldEntity
15{
16public:
17    Tank()
18      : m_turret_angle(0.f),
19        m_ready(false)
20    {
21        m_body.SendCommand("sc0.1,0.1,0,1,ab6,6,15,ty-2,sc.7,.8,.7,1,afcb4,5,16,0.4,tx4,ty5,mx,fl,sc0.2,0.7,0,1,afcb8,7,10,0.4,tz-4,ty5,fl");
22        m_turret.SendCommand("sc0.2,0.7,0,1,afcb3,6,10,0.4,tx-8,afcb3,6,10,0.4,tx4,ty13,fl,sc.7,.8,.7,1,afcb3,6,10,0.4,rx-30,ty13,fl");
23
24        m_rotation = quat::rotate(RandF(0.f, 360.f), vec3(0, 1, 0));
25    }
26
27    ~Tank()
28    {
29    }
30
31    char const *GetName() { return "<tank>"; }
32
33    /* Set a target for the tank */
34    void SetTarget(vec3 const &position)
35    {
36        m_target = position;
37    }
38
39protected:
40    virtual void TickGame(float seconds)
41    {
42        WorldEntity::TickGame(seconds);
43
44        float test = RandF(40.f, 70.f);
45        m_rotation *= quat::rotate(seconds * test, vec3(0, 1, 0));
46        m_velocity = m_rotation.transform(vec3(0, 0, 1));
47        m_position += seconds * 80.f * m_velocity;
48
49        m_turret_angle += seconds * 50.f;
50    }
51
52    virtual void TickDraw(float seconds)
53    {
54        WorldEntity::TickDraw(seconds);
55
56        if (!m_ready)
57        {
58            m_body.SendCommand("irb");
59            m_turret.SendCommand("irb");
60            m_ready = true;
61        }
62
63        mat4 model = mat4::translate(m_position) * mat4(m_rotation);
64        m_body.Render(model);
65
66        model = model * mat4::rotate(m_turret_angle, vec3(0, 1, 0));
67        m_turret.Render(model);
68    }
69
70private:
71    Mesh m_body, m_turret;
72    vec3 m_target;
73    float m_turret_angle;
74    bool m_ready;
75};
76
77#endif /* __TANK_H__ */
78
Note: See TracBrowser for help on using the repository browser.