continuing the avatar class
authorJohn Tsiombikas <nuclear@member.fsf.org>
Mon, 21 May 2018 21:24:09 +0000 (00:24 +0300)
committerJohn Tsiombikas <nuclear@member.fsf.org>
Mon, 21 May 2018 21:24:09 +0000 (00:24 +0300)
src/app.cc
src/avatar.cc
src/avatar.h

index 44c65fd..764d248 100644 (file)
@@ -278,6 +278,21 @@ static void update(float dt)
        exman->update(dt);
        exui_update(dt);
 
        exman->update(dt);
        exui_update(dt);
 
+       // use goatvr sticks for joystick input
+       int num_vr_sticks = goatvr_num_sticks();
+       if(num_vr_sticks > 0) {
+               float p[2];
+               goatvr_stick_pos(0, p);
+               joy_move.x = p[0];
+               joy_move.y = -p[1];
+       }
+       if(num_vr_sticks > 1) {
+               float p[2];
+               goatvr_stick_pos(1, p);
+               joy_look.x = p[0];
+       }
+
+
        float speed = walk_speed * dt;
        Vec3 dir;
 
        float speed = walk_speed * dt;
        Vec3 dir;
 
index 0986d8a..737d3a6 100644 (file)
@@ -2,6 +2,89 @@
 
 Avatar::Avatar()
 {
 
 Avatar::Avatar()
 {
+       mode = 0;
        body_rot = 0;
        head_alt = 0;
 }
        body_rot = 0;
        head_alt = 0;
 }
+
+void Avatar::set_tracking_mode(unsigned int mode)
+{
+       this->mode = mode;
+}
+
+unsigned int Avatar::get_tracking_mode() const
+{
+       return mode;
+}
+
+void Avatar::set_position(const Vec3 &p)
+{
+       pos = p;
+}
+
+const Vec3 &Avatar::get_position() const
+{
+       return pos;
+}
+
+void Avatar::set_body_rotation(float rot)
+{
+       body_rot = rot;
+}
+
+float Avatar::get_body_rotation() const
+{
+       return body_rot;
+}
+
+const Vec3 &Avatar::get_body_fwd() const
+{
+       return fwd;
+}
+
+const Vec3 &Avatar::get_body_right() const
+{
+       return right;
+}
+
+const Quat &Avatar::get_head_rotation() const
+{
+       return head_rot;
+}
+
+void Avatar::tracked_head_rotation(const Quat &q)
+{
+       head_rot = q;
+}
+
+// TODO maybe transform from head-relative first
+void Avatar::tracked_hand_position(int hand, const Vec3 &p)
+{
+       hand_pos[hand] = p;
+}
+
+// TODO maybe transform from head-relative first
+void Avatar::tracked_hand_rotation(int hand, const Quat &q)
+{
+       hand_rot[hand] = q;
+}
+
+void Avatar::mouselook(float horiz, float vert)
+{
+       body_rot += horiz;
+       head_alt += vert;
+       if(head_alt > M_PI / 2.0) head_alt = M_PI / 2.0;
+       if(head_alt < -M_PI / 2.0) head_alt = -M_PI / 2.0;
+}
+
+Vec3 Avatar::calc_walk_dir(float fwd, float right) const
+{
+       // TODO
+       return Vec3(0, 0, 0);
+}
+
+void Avatar::walk(float fwd, float right)
+{
+       Vec3 wdir = calc_walk_dir(fwd, right);
+       pos += wdir;
+}
index 6c3aa41..e604177 100644 (file)
@@ -5,19 +5,67 @@
 
 #include <gmath/gmath.h>
 
 
 #include <gmath/gmath.h>
 
-/* when head-tracking is available, head_tilt is ignored, and the
- * body_rot (controlled by mouse/gamepad) is independent of head_rot.
+enum {
+       AVATAR_NO_TRACKING              = 0,
+       AVATAR_HEAD_TRACKING    = 1,
+       AVATAR_HAND_TRACKING    = 2
+};
+
+/* when head tracking is available, head_alt is ignored
  *
  *
- * without head-tracking, head_rot is derived from body_rot and head_tilt
+ * if HAND tracking is available, body_rot is derived from the hand
+ * orientation during the last call to walk().
+ *
+ * without head-tracking, head_rot is derived from body_rot and head_alt
  */
 class Avatar {
  */
 class Avatar {
+//private:
 public:
 public:
+       unsigned int mode;      // tracking mode
+
        Vec3 pos;
        Vec3 pos;
-       float body_rot;
+       float body_rot;         // walk direction basically
        Quat head_rot;          // used when head-tracking
        Quat head_rot;          // used when head-tracking
-       float head_alt; // used for mouselook
+       float head_alt;         // used for mouselook
 
 
+       Vec3 hand_pos[2];
+       Quat hand_rot[2];
+
+       // body forward and right vectors
+       Vec3 fwd, right;
+
+public:
        Avatar();
        Avatar();
+
+       void set_tracking_mode(unsigned int mode);
+       unsigned int get_tracking_mode() const;
+
+       void set_position(const Vec3 &p);
+       const Vec3 &get_position() const;
+
+       void set_body_rotation(float rot);
+       float get_body_rotation() const;
+       const Vec3 &get_body_fwd() const;
+       const Vec3 &get_body_right() const;
+
+       const Quat &get_head_rotation() const;
+
+       // set current head orientation when head-tracking
+       void tracked_head_rotation(const Quat &q);
+
+       // set current hand position/orientation when hand-tracking
+       void tracked_hand_position(int hand, const Vec3 &p);
+       void tracked_hand_rotation(int hand, const Quat &q);
+
+       // mouselook, or gamepad right-stick input
+       void mouselook(float horiz, float vert);
+
+       // calculate absolute walk direction based on forward and right
+       // magnituted, and the current mode and body orientation data
+       Vec3 calc_walk_dir(float fwd, float right) const;
+
+       // uses calc_walk_dir, then updates pos
+       void walk(float fwd, float right);
 };
 
 #endif // AVATAR_H_
 };
 
 #endif // AVATAR_H_