source: trunk/games/demo-jnat/player.h @ 1716

Last change on this file since 1716 was 1716, checked in by Jnat, 9 years ago
File size: 1.2 KB
Line 
1//
2// demo-jnat
3//
4
5
6#if !defined __PLAYER_H__
7#define __PLAYER_H__
8
9class Player : public WorldEntity
10{
11public:
12    Player()
13      : m_stick(0),
14        m_ready(false)
15    {
16                m_bodymesh.Compile("sc#f21 scb#1c1");
17        m_bodymesh.AppendFlatChamfBox(vec3(10, 30, 10), 1.f);
18                m_position = vec3(0.f,10.0f,0.f);
19    }
20
21    ~Player()
22    {
23        if (m_stick)
24            Input::UntrackStick(m_stick);
25    }
26
27    char const *GetName() { return "<player>"; }
28
29protected:
30    virtual void TickGame(float seconds)
31    {
32        WorldEntity::TickGame(seconds);
33
34        float test = lol::sin(0.5f) * 200.f + 60.f;
35        m_rotation *= quat::rotate(seconds * test, vec3(0, 1, 0));
36
37        m_velocity = 120.f * m_rotation.transform(vec3(0, 0, 1));
38        vec3 deltapos = seconds * m_velocity;
39        m_position += deltapos;
40    }
41
42    virtual void TickDraw(float seconds)
43    {
44        WorldEntity::TickDraw(seconds);
45
46        if (!m_ready)
47        {
48            m_bodymesh.MeshConvert();
49            m_ready = true;
50        }
51
52        mat4 model = mat4::translate(m_position) * mat4(m_rotation);
53
54        m_bodymesh.Render(model);
55    }
56
57private:
58    EasyMesh m_bodymesh;
59    Stick *m_stick;
60       
61    bool m_ready;
62};
63
64#endif /* __PLAYER_H__ */
65
Note: See TracBrowser for help on using the repository browser.