stash/unstash clunky as fuck
[laserbrain_demo] / src / avatar.cc
index 737d3a6..456f269 100644 (file)
@@ -1,4 +1,5 @@
 #include "avatar.h"
+#include "logger.h"
 
 Avatar::Avatar()
 {
@@ -30,6 +31,12 @@ const Vec3 &Avatar::get_position() const
 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
@@ -79,8 +86,10 @@ void Avatar::mouselook(float horiz, float vert)
 
 Vec3 Avatar::calc_walk_dir(float fwd, float right) const
 {
-       // TODO
-       return Vec3(0, 0, 0);
+       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)