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