# HG changeset patch # User John Tsiombikas # Date 1422927314 -7200 # Node ID d487181ee1d922e533698461464cde35abc45ec3 # Parent 85e26116ba5a9b268c6909a976db8c29b3f66338 fixed movement diff -r 85e26116ba5a -r d487181ee1d9 src/app.cc --- a/src/app.cc Mon Feb 02 21:11:23 2015 +0200 +++ b/src/app.cc Tue Feb 03 03:35:14 2015 +0200 @@ -9,7 +9,7 @@ static User user; static float eye_level = 1.6; -static const float walk_speed = 4.0; +static const float walk_speed = 5.0; static int win_width, win_height; static bool keystate[256]; @@ -45,15 +45,15 @@ redisplay(); } if(keystate['d'] || keystate['D']) { - right += walk_speed * 0.5 * dt; + right += walk_speed * 0.7 * dt; redisplay(); } if(keystate['a'] || keystate['A']) { - right -= walk_speed * 0.5 * dt; + right -= walk_speed * 0.7 * dt; redisplay(); } - user.posrot.move(fwd, right); + user.move(fwd, right); } void app_display() @@ -67,7 +67,7 @@ glLoadIdentity(); Matrix4x4 viewmat; - user.posrot.calc_inv_matrix(&viewmat); + user.calc_inv_matrix(&viewmat); glLoadTransposeMatrixf(viewmat.m[0]); glTranslatef(0, -eye_level, 0); @@ -128,7 +128,7 @@ void app_mouse_motion(int x, int y) { - static const float rot_speed = 10.0; + static const float rot_speed = 250.0; float dx = (float)(x - prev_x) / (float)win_width; float dy = (float)(y - prev_y) / (float)win_height; @@ -136,7 +136,7 @@ prev_y = y; if(bnstate[0]) { - user.posrot.rotate(dx * rot_speed, dy * rot_speed); + user.rotate(dx * rot_speed, dy * rot_speed); redisplay(); } } @@ -156,7 +156,7 @@ static void draw_grid(int num, float sep) { int hnum = num / 2; - float max_dist = hnum * sep; + float max_dist = (hnum - 1) * sep; glBegin(GL_LINES); glColor3f(0.4, 0.4, 0.4); diff -r 85e26116ba5a -r d487181ee1d9 src/fs.cc --- a/src/fs.cc Mon Feb 02 21:11:23 2015 +0200 +++ b/src/fs.cc Tue Feb 03 03:35:14 2015 +0200 @@ -32,6 +32,7 @@ sorted = true; uid = gid = mode = 0; type = UNKNOWN; + data = 0; } void FSNode::destroy() @@ -227,6 +228,16 @@ return expanded; } +void FSNode::set_ext_data(void *data) +{ + this->data = data; +} + +void *FSNode::get_ext_data() const +{ + return data; +} + // ---- FSDir ---- FSDir::FSDir() diff -r 85e26116ba5a -r d487181ee1d9 src/fs.h --- a/src/fs.h Mon Feb 02 21:11:23 2015 +0200 +++ b/src/fs.h Tue Feb 03 03:35:14 2015 +0200 @@ -17,6 +17,8 @@ Type type; unsigned int uid, gid, mode; + void *data; + private: FSNode(const FSNode&); FSNode &operator =(const FSNode&); @@ -57,6 +59,9 @@ virtual bool expand(); virtual bool is_expanded() const; + + virtual void set_ext_data(void *data); + virtual void *get_ext_data() const; }; class FSDir : public FSNode { diff -r 85e26116ba5a -r d487181ee1d9 src/user.cc --- a/src/user.cc Mon Feb 02 21:11:23 2015 +0200 +++ b/src/user.cc Tue Feb 03 03:35:14 2015 +0200 @@ -1,28 +1,46 @@ #include "user.h" -void PosRot::move(float dfwd, float dright, float dup) +User::User() { - Vector3 dir = Vector3(dright, dup, -dfwd); - dir.transform(rot); + hangle = vangle = 0; +} + +void User::move(float dfwd, float dright, float dup) +{ + float costheta = cos(DEG_TO_RAD(hangle)); + float sintheta = sin(DEG_TO_RAD(hangle)); + + Vector3 dir; + + dir.x = dright * costheta - dfwd * sintheta; + dir.y = dup; + dir.z = -dright * sintheta - dfwd * costheta; + pos += dir; } -void PosRot::rotate(float dhoriz, float dvert) +void User::rotate(float dhoriz, float dvert) { - rot.rotate(Vector3(1, 0, 0), dvert); - rot.rotate(Vector3(0, 1, 0), dhoriz); + hangle = fmod(hangle - dhoriz, 360.0); + vangle -= dvert; + + if(vangle < -90) vangle = -90; + if(vangle > 90) vangle = 90; } -void PosRot::calc_matrix(Matrix4x4 *res) const +void User::calc_matrix(Matrix4x4 *res) const { - Matrix4x4 rmat = rot.get_rotation_matrix(); + Matrix4x4 rmat; + rmat.set_rotation(Vector3(0, DEG_TO_RAD(hangle), 0)); + rmat.rotate(Vector3(DEG_TO_RAD(vangle), 0, 0)); + Matrix4x4 tmat; tmat.set_translation(pos); *res = tmat * rmat; } -void PosRot::calc_inv_matrix(Matrix4x4 *res) const +void User::calc_inv_matrix(Matrix4x4 *res) const { calc_matrix(res); *res = res->inverse(); diff -r 85e26116ba5a -r d487181ee1d9 src/user.h --- a/src/user.h Mon Feb 02 21:11:23 2015 +0200 +++ b/src/user.h Tue Feb 03 03:35:14 2015 +0200 @@ -3,9 +3,12 @@ #include -struct PosRot { +class User { +public: Vector3 pos; - Quaternion rot; + float hangle, vangle; + + User(); void move(float dfwd, float dright, float dup = 0.0f); void rotate(float dhoriz, float dvert); @@ -14,9 +17,4 @@ void calc_inv_matrix(Matrix4x4 *res) const; }; -class User { -public: - PosRot posrot; -}; - #endif // USER_H_