player.c (1408B)
1 #include "player.h" 2 3 static void Player_updateRotation(Player *player, f32 dx, f32 dy) 4 { 5 player->transform->yaw += dx * player->sensitivity; 6 7 player->transform->pitch -= dy * player->sensitivity; 8 if (player->transform->pitch > 85.0f) 9 { 10 player->transform->pitch = 85.0f; 11 } 12 if (player->transform->pitch < -85.0f) 13 { 14 player->transform->pitch = -85.0f; 15 } 16 } 17 18 static void Player_updatePosition(Player *player, f32 dx, f32 dy, f32 dz) 19 { 20 Vec3 movement_x; 21 Vec3_scale(player->transform->right, dx, movement_x); 22 23 Vec3 movement_y; 24 Vec3_scale(player->transform->up, dy, movement_y); 25 26 Vec3 movement_z; 27 Vec3_scale(player->transform->forward, dz, movement_z); 28 29 Vec3 movement; 30 Vec3_add(movement_x, movement_y, movement); 31 Vec3_add(movement_z, movement, movement); 32 Vec3_normalize(movement, movement); 33 Vec3_scale(movement, player->speed, movement); 34 35 Vec3_add( 36 player->transform->position, 37 movement, 38 player->transform->position 39 ); 40 } 41 42 void Player_move(Player *player, UserInput *input) 43 { 44 Player_updateRotation( 45 player, 46 input->rotation_dx, 47 input->rotation_dy 48 ); 49 50 Player_updatePosition( 51 player, 52 input->move_dx, 53 input->move_dy, 54 input->move_dz 55 ); 56 57 Transform_updateVectors(player->transform); 58 } 59