| 87 | } |
| 88 | |
| 89 | void MovementController::GetAcceleration( |
| 90 | const KeyboardState& keyboard_state, |
| 91 | float& out_dir, float& out_acceleration ) const |
| 92 | { |
| 93 | m_Vec3 move_vector(0.0f,0.0f,0.0f); |
| 94 | |
| 95 | auto key_pressed= |
| 96 | [&]( const char* const key_setting_name ) |
| 97 | { |
| 98 | using KeyCode= SystemEvent::KeyEvent::KeyCode; |
| 99 | const KeyCode key= static_cast<KeyCode>( settings_.GetInt( key_setting_name ) ); |
| 100 | if( key > KeyCode::Unknown && key < KeyCode::KeyCount ) |
| 101 | return keyboard_state[ static_cast<unsigned int>( key ) ]; |
| 102 | return false; |
| 103 | }; |
| 104 | |
| 105 | if( key_pressed( SettingsKeys::key_forward ) ) move_vector.y+= +1.0f; |
| 106 | if( key_pressed( SettingsKeys::key_backward ) ) move_vector.y+= -1.0f; |
| 107 | if( key_pressed( SettingsKeys::key_step_left ) ) move_vector.x+= -1.0f; |
| 108 | if( key_pressed( SettingsKeys::key_step_right ) ) move_vector.x+= +1.0f; |
| 109 | |
| 110 | m_Mat4 move_vector_rot_mat; |
| 111 | move_vector_rot_mat.RotateZ( angle_.z ); |
| 112 | |
| 113 | move_vector= move_vector * move_vector_rot_mat; |
| 114 | |
| 115 | if( move_vector.xy().SquareLength() <= 0.001f ) |
| 116 | { |
| 117 | out_dir= 0.0f; |
| 118 | out_acceleration= 0.0f; |
| 119 | } |
| 120 | else |
| 121 | { |
| 122 | out_dir= std::atan2( move_vector.y, move_vector.x ); |
| 123 | out_acceleration= 1.0f; |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | float MovementController::GetEyeZShift() const |
| 128 | { |