dungeon_crawler
diff prototype/src/camera.cc @ 7:8fb37db44fd8
first person motion
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Fri, 17 Aug 2012 14:29:37 +0300 |
parents | 96de911d05d4 |
children | 77c302306206 |
line diff
1.1 --- a/prototype/src/camera.cc Tue Aug 14 08:49:38 2012 +0300 1.2 +++ b/prototype/src/camera.cc Fri Aug 17 14:29:37 2012 +0300 1.3 @@ -106,13 +106,13 @@ 1.4 1.5 void OrbitCamera::input_rotate(float x, float y, float z) 1.6 { 1.7 - theta += x; 1.8 - phi += y; 1.9 + theta += y; 1.10 + phi += x; 1.11 1.12 - if(phi < -M_PI / 2.0) 1.13 - phi = -M_PI / 2.0; 1.14 - if(phi > M_PI / 2.0) 1.15 - phi = M_PI / 2.0; 1.16 + if(phi < -M_PI / 2) 1.17 + phi = -M_PI / 2; 1.18 + if(phi > M_PI) 1.19 + phi = M_PI; 1.20 1.21 inval_cache(); 1.22 } 1.23 @@ -127,6 +127,32 @@ 1.24 } 1.25 1.26 1.27 +void FpsCamera::calc_matrix(Matrix4x4 *mat) const 1.28 +{ 1.29 + mat->reset_identity(); 1.30 + /*mat->translate(Vector3(pos.x, pos.y, pos.z)); 1.31 + mat->rotate(Vector3(phi, 0, 0)); 1.32 + mat->rotate(Vector3(0, theta, 0));*/ 1.33 +} 1.34 + 1.35 +void FpsCamera::calc_inv_matrix(Matrix4x4 *mat) const 1.36 +{ 1.37 + mat->reset_identity(); 1.38 + mat->rotate(Vector3(phi, 0, 0)); 1.39 + mat->rotate(Vector3(0, theta, 0)); 1.40 + mat->translate(Vector3(-pos.x, -pos.y, -pos.z)); 1.41 +} 1.42 + 1.43 +void FpsCamera::input_move(float x, float y, float z) 1.44 +{ 1.45 + pos.x += x * cos(theta) - z * sin(theta); 1.46 + pos.z += x * sin(theta) + z * cos(theta); 1.47 + pos.y += y; 1.48 + inval_cache(); 1.49 +} 1.50 + 1.51 + 1.52 + 1.53 FlyCamera::FlyCamera() 1.54 { 1.55 pos.z = 10.0f;