stash/unstash clunky as fuck
[laserbrain_demo] / src / avatar.cc
index 0986d8a..456f269 100644 (file)
@@ -1,7 +1,99 @@
 #include "avatar.h"
+#include "logger.h"
 
 Avatar::Avatar()
 {
+       mode = 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 theta = deg_to_rad(body_rot);
+       fwd.x = sin(theta);
+       fwd.y = 0;
+       fwd.z = -cos(theta);
+       right = Vec3(-fwd.z, 0, fwd.x);
+}
+
+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
+{
+       float theta = M_PI * body_rot / 180.0f;
+       float dx = cos(theta) * right - sin(theta) * fwd;
+       float dz = sin(theta) * right + cos(theta) * fwd;
+       return Vec3(dx, 0, dz);
+}
+
+void Avatar::walk(float fwd, float right)
+{
+       Vec3 wdir = calc_walk_dir(fwd, right);
+       pos += wdir;
+}