source: trunk/orbital/tank.h @ 1336

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

orbital: play with the tanks.

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