X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?p=laserbrain_demo;a=blobdiff_plain;f=src%2Favatar.cc;h=456f269b56241eccdd7d93f6b1c6c23a746b53e6;hp=0986d8a9a879492a8afed86239f01e220c82d50a;hb=5c69b226e45df981db338dd859ef1d95e9be8f96;hpb=2c648dbdf80ad77015e3283beb028cd389c2d2fa diff --git a/src/avatar.cc b/src/avatar.cc index 0986d8a..456f269 100644 --- a/src/avatar.cc +++ b/src/avatar.cc @@ -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; +}