vrfileman

view 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 source
1 #include "user.h"
3 User::User()
4 {
5 hangle = vangle = 0;
6 }
8 void User::move(float dfwd, float dright, float dup)
9 {
10 float costheta = cos(DEG_TO_RAD(hangle));
11 float sintheta = sin(DEG_TO_RAD(hangle));
13 Vector3 dir;
15 dir.x = dright * costheta - dfwd * sintheta;
16 dir.y = dup;
17 dir.z = -dright * sintheta - dfwd * costheta;
19 pos += dir;
20 }
22 void User::rotate(float dhoriz, float dvert)
23 {
24 hangle = fmod(hangle - dhoriz, 360.0);
25 vangle -= dvert;
27 if(vangle < -90) vangle = -90;
28 if(vangle > 90) vangle = 90;
29 }
31 void User::calc_matrix(Matrix4x4 *res) const
32 {
33 Matrix4x4 rmat;
34 rmat.set_rotation(Vector3(0, DEG_TO_RAD(hangle), 0));
35 rmat.rotate(Vector3(DEG_TO_RAD(vangle), 0, 0));
37 Matrix4x4 tmat;
38 tmat.set_translation(pos);
40 *res = tmat * rmat;
41 }
43 void User::calc_inv_matrix(Matrix4x4 *res) const
44 {
45 calc_matrix(res);
46 *res = res->inverse();
47 // TODO: optimize
48 }