continuing the avatar class
[laserbrain_demo] / src / avatar.h
1 #ifndef AVATAR_H_
2 #define AVATAR_H_
3
4 // TODO incomplete
5
6 #include <gmath/gmath.h>
7
8 enum {
9         AVATAR_NO_TRACKING              = 0,
10         AVATAR_HEAD_TRACKING    = 1,
11         AVATAR_HAND_TRACKING    = 2
12 };
13
14 /* when head tracking is available, head_alt is ignored
15  *
16  * if HAND tracking is available, body_rot is derived from the hand
17  * orientation during the last call to walk().
18  *
19  * without head-tracking, head_rot is derived from body_rot and head_alt
20  */
21 class Avatar {
22 //private:
23 public:
24         unsigned int mode;      // tracking mode
25
26         Vec3 pos;
27         float body_rot;         // walk direction basically
28         Quat head_rot;          // used when head-tracking
29         float head_alt;         // used for mouselook
30
31         Vec3 hand_pos[2];
32         Quat hand_rot[2];
33
34         // body forward and right vectors
35         Vec3 fwd, right;
36
37 public:
38         Avatar();
39
40         void set_tracking_mode(unsigned int mode);
41         unsigned int get_tracking_mode() const;
42
43         void set_position(const Vec3 &p);
44         const Vec3 &get_position() const;
45
46         void set_body_rotation(float rot);
47         float get_body_rotation() const;
48         const Vec3 &get_body_fwd() const;
49         const Vec3 &get_body_right() const;
50
51         const Quat &get_head_rotation() const;
52
53         // set current head orientation when head-tracking
54         void tracked_head_rotation(const Quat &q);
55
56         // set current hand position/orientation when hand-tracking
57         void tracked_hand_position(int hand, const Vec3 &p);
58         void tracked_hand_rotation(int hand, const Quat &q);
59
60         // mouselook, or gamepad right-stick input
61         void mouselook(float horiz, float vert);
62
63         // calculate absolute walk direction based on forward and right
64         // magnituted, and the current mode and body orientation data
65         Vec3 calc_walk_dir(float fwd, float right) const;
66
67         // uses calc_walk_dir, then updates pos
68         void walk(float fwd, float right);
69 };
70
71 #endif  // AVATAR_H_