diff --git a/src/GameBall/logic/player_input.cpp b/src/GameBall/logic/player_input.cpp index c002a91..09633df 100644 --- a/src/GameBall/logic/player_input.cpp +++ b/src/GameBall/logic/player_input.cpp @@ -13,6 +13,12 @@ PlayerInput PlayerInputController::GetInput() { input_.move_left = (glfwGetKey(window, GLFW_KEY_A) == GLFW_PRESS); input_.move_right = (glfwGetKey(window, GLFW_KEY_D) == GLFW_PRESS); input_.brake = (glfwGetKey(window, GLFW_KEY_SPACE) == GLFW_PRESS); + input_.rotate_left = (glfwGetKey(window, GLFW_KEY_N) == GLFW_PRESS); + input_.rotate_right = (glfwGetKey(window, GLFW_KEY_M) == GLFW_PRESS); + input_.jump = (glfwGetKey(window, GLFW_KEY_J) == GLFW_PRESS); + input_.reverse_gravity = (glfwGetKey(window, GLFW_KEY_R) == GLFW_PRESS); + input_.larger_radius = (glfwGetKey(window, GLFW_KEY_L) == GLFW_PRESS); + input_.smaller_radius = (glfwGetKey(window, GLFW_KEY_K) == GLFW_PRESS); auto camera_controller = app_->CameraController(); auto pitch_yaw = camera_controller->GetPitchYaw(); auto pitch = pitch_yaw.x; diff --git a/src/GameBall/logic/player_input.h b/src/GameBall/logic/player_input.h index 98b60c0..38dd7c6 100644 --- a/src/GameBall/logic/player_input.h +++ b/src/GameBall/logic/player_input.h @@ -12,6 +12,12 @@ struct PlayerInput { bool move_left{false}; bool move_right{false}; bool brake{false}; + bool rotate_left{false}; + bool rotate_right{false}; + bool jump{false}; + bool reverse_gravity{false}; + bool larger_radius{false}; + bool smaller_radius{false}; glm::vec3 orientation{0.0f, 0.0f, 1.0f}; }; diff --git a/src/GameBall/logic/units/regular_ball.cpp b/src/GameBall/logic/units/regular_ball.cpp index af1cc95..17dc460 100644 --- a/src/GameBall/logic/units/regular_ball.cpp +++ b/src/GameBall/logic/units/regular_ball.cpp @@ -44,44 +44,66 @@ void RegularBall::UpdateTick() { float delta_time = world_->TickDeltaT(); auto physics_world = world_->PhysicsWorld(); auto &sphere = physics_world->GetSphere(sphere_id_); - - // auto owner = world_->GetPlayer(player_id_); - // if (owner) { - // if (UnitId() == owner->PrimaryUnitId()) { - // auto input = owner->TakePlayerInput(); - // - // glm::vec3 forward = glm::normalize(glm::vec3{input.orientation}); - // glm::vec3 right = - // glm::normalize(glm::cross(forward, glm::vec3{0.0f, 1.0f, 0.0f})); - // - // glm::vec3 moving_direction{}; - // - // float angular_acceleration = glm::radians(2880.0f); - // - // if (input.move_forward) { - // moving_direction -= right; - // } - // if (input.move_backward) { - // moving_direction += right; - // } - // if (input.move_left) { - // moving_direction -= forward; - // } - // if (input.move_right) { - // moving_direction += forward; - // } - // - // if (glm::length(moving_direction) > 0.0f) { - // moving_direction = glm::normalize(moving_direction); - // sphere.angular_velocity += - // moving_direction * angular_acceleration * delta_time; - // } - // - // if (input.brake) { - // sphere.angular_velocity = glm::vec3{0.0f}; - // } - // } - // } + auto owner = world_->GetPlayer(player_id_); + if (owner) { + if (UnitId() == owner->PrimaryUnitId()) { + auto input = owner->TakePlayerInput(); + + glm::vec3 forward = glm::normalize(glm::vec3{input.orientation}); + glm::vec3 right = + glm::normalize(glm::cross(forward, glm::vec3{0.0f, 1.0f, 0.0f})); + glm::vec3 rotation = + glm::normalize(glm::cross(forward, glm::vec3(0.0f, 0.0f, 1.0f))); + glm::vec3 upward = glm::vec3(0.0f, 3.0f, 0.0f); + + glm::vec3 moving_direction{}; + + float angular_acceleration = glm::radians(2880.0f); + + if (input.move_forward) { + moving_direction -= right; + } + if (input.move_backward) { + moving_direction += right; + } + if (input.move_left) { + moving_direction -= forward; + } + if (input.move_right) { + moving_direction += forward; + } + if (input.rotate_left) { + moving_direction -= rotation; + } + if (input.rotate_right) { + moving_direction += rotation; + } + if (input.jump) { + sphere.velocity += upward; + } + if (glm::length(moving_direction) > 0.0f) { + moving_direction = glm::normalize(moving_direction); + sphere.angular_velocity += + moving_direction * angular_acceleration * delta_time; + } + if (input.brake) { + sphere.angular_velocity = glm::vec3{0.0f}; + } + if (input.reverse_gravity) { + sphere.gravity = -sphere.gravity; + } + if (input.larger_radius) { + radius_ += delta_time; + sphere.radius += delta_time; + sphere.position += glm::vec3{0.0f, 1.0f, 0.0f} * delta_time; + } + if (input.smaller_radius&&radius_>=0.1f) { + radius_ -= delta_time; + sphere.radius -= delta_time; + sphere.position -= glm::vec3{0.0f, 1.0f, 0.0f} * delta_time; + } + } + } sphere.velocity *= std::pow(0.5f, delta_time); sphere.angular_velocity *= std::pow(0.2f, delta_time);