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