vrfileman
changeset 5:d487181ee1d9
fixed movement
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Tue, 03 Feb 2015 03:35:14 +0200 |
parents | 85e26116ba5a |
children | b041bc1c38ad |
files | src/app.cc src/fs.cc src/fs.h src/user.cc src/user.h |
diffstat | 5 files changed, 56 insertions(+), 24 deletions(-) [+] |
line diff
1.1 --- a/src/app.cc Mon Feb 02 21:11:23 2015 +0200 1.2 +++ b/src/app.cc Tue Feb 03 03:35:14 2015 +0200 1.3 @@ -9,7 +9,7 @@ 1.4 static User user; 1.5 static float eye_level = 1.6; 1.6 1.7 -static const float walk_speed = 4.0; 1.8 +static const float walk_speed = 5.0; 1.9 1.10 static int win_width, win_height; 1.11 static bool keystate[256]; 1.12 @@ -45,15 +45,15 @@ 1.13 redisplay(); 1.14 } 1.15 if(keystate['d'] || keystate['D']) { 1.16 - right += walk_speed * 0.5 * dt; 1.17 + right += walk_speed * 0.7 * dt; 1.18 redisplay(); 1.19 } 1.20 if(keystate['a'] || keystate['A']) { 1.21 - right -= walk_speed * 0.5 * dt; 1.22 + right -= walk_speed * 0.7 * dt; 1.23 redisplay(); 1.24 } 1.25 1.26 - user.posrot.move(fwd, right); 1.27 + user.move(fwd, right); 1.28 } 1.29 1.30 void app_display() 1.31 @@ -67,7 +67,7 @@ 1.32 glLoadIdentity(); 1.33 1.34 Matrix4x4 viewmat; 1.35 - user.posrot.calc_inv_matrix(&viewmat); 1.36 + user.calc_inv_matrix(&viewmat); 1.37 glLoadTransposeMatrixf(viewmat.m[0]); 1.38 glTranslatef(0, -eye_level, 0); 1.39 1.40 @@ -128,7 +128,7 @@ 1.41 1.42 void app_mouse_motion(int x, int y) 1.43 { 1.44 - static const float rot_speed = 10.0; 1.45 + static const float rot_speed = 250.0; 1.46 1.47 float dx = (float)(x - prev_x) / (float)win_width; 1.48 float dy = (float)(y - prev_y) / (float)win_height; 1.49 @@ -136,7 +136,7 @@ 1.50 prev_y = y; 1.51 1.52 if(bnstate[0]) { 1.53 - user.posrot.rotate(dx * rot_speed, dy * rot_speed); 1.54 + user.rotate(dx * rot_speed, dy * rot_speed); 1.55 redisplay(); 1.56 } 1.57 } 1.58 @@ -156,7 +156,7 @@ 1.59 static void draw_grid(int num, float sep) 1.60 { 1.61 int hnum = num / 2; 1.62 - float max_dist = hnum * sep; 1.63 + float max_dist = (hnum - 1) * sep; 1.64 1.65 glBegin(GL_LINES); 1.66 glColor3f(0.4, 0.4, 0.4);
2.1 --- a/src/fs.cc Mon Feb 02 21:11:23 2015 +0200 2.2 +++ b/src/fs.cc Tue Feb 03 03:35:14 2015 +0200 2.3 @@ -32,6 +32,7 @@ 2.4 sorted = true; 2.5 uid = gid = mode = 0; 2.6 type = UNKNOWN; 2.7 + data = 0; 2.8 } 2.9 2.10 void FSNode::destroy() 2.11 @@ -227,6 +228,16 @@ 2.12 return expanded; 2.13 } 2.14 2.15 +void FSNode::set_ext_data(void *data) 2.16 +{ 2.17 + this->data = data; 2.18 +} 2.19 + 2.20 +void *FSNode::get_ext_data() const 2.21 +{ 2.22 + return data; 2.23 +} 2.24 + 2.25 2.26 // ---- FSDir ---- 2.27 FSDir::FSDir()
3.1 --- a/src/fs.h Mon Feb 02 21:11:23 2015 +0200 3.2 +++ b/src/fs.h Tue Feb 03 03:35:14 2015 +0200 3.3 @@ -17,6 +17,8 @@ 3.4 Type type; 3.5 unsigned int uid, gid, mode; 3.6 3.7 + void *data; 3.8 + 3.9 private: 3.10 FSNode(const FSNode&); 3.11 FSNode &operator =(const FSNode&); 3.12 @@ -57,6 +59,9 @@ 3.13 3.14 virtual bool expand(); 3.15 virtual bool is_expanded() const; 3.16 + 3.17 + virtual void set_ext_data(void *data); 3.18 + virtual void *get_ext_data() const; 3.19 }; 3.20 3.21 class FSDir : public FSNode {
4.1 --- a/src/user.cc Mon Feb 02 21:11:23 2015 +0200 4.2 +++ b/src/user.cc Tue Feb 03 03:35:14 2015 +0200 4.3 @@ -1,28 +1,46 @@ 4.4 #include "user.h" 4.5 4.6 -void PosRot::move(float dfwd, float dright, float dup) 4.7 +User::User() 4.8 { 4.9 - Vector3 dir = Vector3(dright, dup, -dfwd); 4.10 - dir.transform(rot); 4.11 + hangle = vangle = 0; 4.12 +} 4.13 + 4.14 +void User::move(float dfwd, float dright, float dup) 4.15 +{ 4.16 + float costheta = cos(DEG_TO_RAD(hangle)); 4.17 + float sintheta = sin(DEG_TO_RAD(hangle)); 4.18 + 4.19 + Vector3 dir; 4.20 + 4.21 + dir.x = dright * costheta - dfwd * sintheta; 4.22 + dir.y = dup; 4.23 + dir.z = -dright * sintheta - dfwd * costheta; 4.24 + 4.25 pos += dir; 4.26 } 4.27 4.28 -void PosRot::rotate(float dhoriz, float dvert) 4.29 +void User::rotate(float dhoriz, float dvert) 4.30 { 4.31 - rot.rotate(Vector3(1, 0, 0), dvert); 4.32 - rot.rotate(Vector3(0, 1, 0), dhoriz); 4.33 + hangle = fmod(hangle - dhoriz, 360.0); 4.34 + vangle -= dvert; 4.35 + 4.36 + if(vangle < -90) vangle = -90; 4.37 + if(vangle > 90) vangle = 90; 4.38 } 4.39 4.40 -void PosRot::calc_matrix(Matrix4x4 *res) const 4.41 +void User::calc_matrix(Matrix4x4 *res) const 4.42 { 4.43 - Matrix4x4 rmat = rot.get_rotation_matrix(); 4.44 + Matrix4x4 rmat; 4.45 + rmat.set_rotation(Vector3(0, DEG_TO_RAD(hangle), 0)); 4.46 + rmat.rotate(Vector3(DEG_TO_RAD(vangle), 0, 0)); 4.47 + 4.48 Matrix4x4 tmat; 4.49 tmat.set_translation(pos); 4.50 4.51 *res = tmat * rmat; 4.52 } 4.53 4.54 -void PosRot::calc_inv_matrix(Matrix4x4 *res) const 4.55 +void User::calc_inv_matrix(Matrix4x4 *res) const 4.56 { 4.57 calc_matrix(res); 4.58 *res = res->inverse();
5.1 --- a/src/user.h Mon Feb 02 21:11:23 2015 +0200 5.2 +++ b/src/user.h Tue Feb 03 03:35:14 2015 +0200 5.3 @@ -3,9 +3,12 @@ 5.4 5.5 #include <vmath/vmath.h> 5.6 5.7 -struct PosRot { 5.8 +class User { 5.9 +public: 5.10 Vector3 pos; 5.11 - Quaternion rot; 5.12 + float hangle, vangle; 5.13 + 5.14 + User(); 5.15 5.16 void move(float dfwd, float dright, float dup = 0.0f); 5.17 void rotate(float dhoriz, float dvert); 5.18 @@ -14,9 +17,4 @@ 5.19 void calc_inv_matrix(Matrix4x4 *res) const; 5.20 }; 5.21 5.22 -class User { 5.23 -public: 5.24 - PosRot posrot; 5.25 -}; 5.26 - 5.27 #endif // USER_H_