vrfileman
diff src/user.cc @ 5:d487181ee1d9
fixed movement
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Tue, 03 Feb 2015 03:35:14 +0200 |
parents | 85e26116ba5a |
children |
line diff
1.1 --- a/src/user.cc Mon Feb 02 21:11:23 2015 +0200 1.2 +++ b/src/user.cc Tue Feb 03 03:35:14 2015 +0200 1.3 @@ -1,28 +1,46 @@ 1.4 #include "user.h" 1.5 1.6 -void PosRot::move(float dfwd, float dright, float dup) 1.7 +User::User() 1.8 { 1.9 - Vector3 dir = Vector3(dright, dup, -dfwd); 1.10 - dir.transform(rot); 1.11 + hangle = vangle = 0; 1.12 +} 1.13 + 1.14 +void User::move(float dfwd, float dright, float dup) 1.15 +{ 1.16 + float costheta = cos(DEG_TO_RAD(hangle)); 1.17 + float sintheta = sin(DEG_TO_RAD(hangle)); 1.18 + 1.19 + Vector3 dir; 1.20 + 1.21 + dir.x = dright * costheta - dfwd * sintheta; 1.22 + dir.y = dup; 1.23 + dir.z = -dright * sintheta - dfwd * costheta; 1.24 + 1.25 pos += dir; 1.26 } 1.27 1.28 -void PosRot::rotate(float dhoriz, float dvert) 1.29 +void User::rotate(float dhoriz, float dvert) 1.30 { 1.31 - rot.rotate(Vector3(1, 0, 0), dvert); 1.32 - rot.rotate(Vector3(0, 1, 0), dhoriz); 1.33 + hangle = fmod(hangle - dhoriz, 360.0); 1.34 + vangle -= dvert; 1.35 + 1.36 + if(vangle < -90) vangle = -90; 1.37 + if(vangle > 90) vangle = 90; 1.38 } 1.39 1.40 -void PosRot::calc_matrix(Matrix4x4 *res) const 1.41 +void User::calc_matrix(Matrix4x4 *res) const 1.42 { 1.43 - Matrix4x4 rmat = rot.get_rotation_matrix(); 1.44 + Matrix4x4 rmat; 1.45 + rmat.set_rotation(Vector3(0, DEG_TO_RAD(hangle), 0)); 1.46 + rmat.rotate(Vector3(DEG_TO_RAD(vangle), 0, 0)); 1.47 + 1.48 Matrix4x4 tmat; 1.49 tmat.set_translation(pos); 1.50 1.51 *res = tmat * rmat; 1.52 } 1.53 1.54 -void PosRot::calc_inv_matrix(Matrix4x4 *res) const 1.55 +void User::calc_inv_matrix(Matrix4x4 *res) const 1.56 { 1.57 calc_matrix(res); 1.58 *res = res->inverse();