From fae150da0104b66a5b1169c93b17ea28ea85b1d2 Mon Sep 17 00:00:00 2001 From: Rita1218 <145887023+Rita1218@users.noreply.github.com> Date: Sat, 13 Jan 2024 10:15:00 +0800 Subject: [PATCH 01/14] Update regular_ball.cpp --- src/GameBall/logic/units/regular_ball.cpp | 74 +++++++++++------------ 1 file changed, 37 insertions(+), 37 deletions(-) diff --git a/src/GameBall/logic/units/regular_ball.cpp b/src/GameBall/logic/units/regular_ball.cpp index af1cc95..b8373aa 100644 --- a/src/GameBall/logic/units/regular_ball.cpp +++ b/src/GameBall/logic/units/regular_ball.cpp @@ -45,43 +45,43 @@ void RegularBall::UpdateTick() { 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 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}; + } + } + } sphere.velocity *= std::pow(0.5f, delta_time); sphere.angular_velocity *= std::pow(0.2f, delta_time); From db147608c584c2b33f3e3d3da0e0eae932ff41b4 Mon Sep 17 00:00:00 2001 From: Rita1218 <145887023+Rita1218@users.noreply.github.com> Date: Mon, 15 Jan 2024 16:01:38 +0800 Subject: [PATCH 02/14] Update rigid_body.cpp --- src/GameX/physics/rigid_body.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/GameX/physics/rigid_body.cpp b/src/GameX/physics/rigid_body.cpp index 2cba66c..99a695e 100644 --- a/src/GameX/physics/rigid_body.cpp +++ b/src/GameX/physics/rigid_body.cpp @@ -1,9 +1,14 @@ #include "GameX/physics/rigid_body.h" +#include namespace GameX::Physics { void RigidBody::Update(float delta_time) { position += velocity * delta_time; + if (position.y < -20.0) { + std::cout << "GAME OVER" << std::endl; + exit(1); + } orientation = Base::Rotate(angular_velocity * delta_time) * orientation; } From cd89312bf8ea05a51ee29fff9841fd889692448f Mon Sep 17 00:00:00 2001 From: Rita1218 <145887023+Rita1218@users.noreply.github.com> Date: Mon, 15 Jan 2024 16:05:08 +0800 Subject: [PATCH 03/14] Update rigid_body.cpp --- src/GameX/physics/rigid_body.cpp | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/GameX/physics/rigid_body.cpp b/src/GameX/physics/rigid_body.cpp index 99a695e..2cba66c 100644 --- a/src/GameX/physics/rigid_body.cpp +++ b/src/GameX/physics/rigid_body.cpp @@ -1,14 +1,9 @@ #include "GameX/physics/rigid_body.h" -#include namespace GameX::Physics { void RigidBody::Update(float delta_time) { position += velocity * delta_time; - if (position.y < -20.0) { - std::cout << "GAME OVER" << std::endl; - exit(1); - } orientation = Base::Rotate(angular_velocity * delta_time) * orientation; } From 2992b94b17f09077e944e1a546085b215fa577ff Mon Sep 17 00:00:00 2001 From: Rita1218 <145887023+Rita1218@users.noreply.github.com> Date: Mon, 15 Jan 2024 16:07:46 +0800 Subject: [PATCH 04/14] Update rigid_body.cpp --- src/GameX/physics/rigid_body.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/GameX/physics/rigid_body.cpp b/src/GameX/physics/rigid_body.cpp index 2cba66c..99a695e 100644 --- a/src/GameX/physics/rigid_body.cpp +++ b/src/GameX/physics/rigid_body.cpp @@ -1,9 +1,14 @@ #include "GameX/physics/rigid_body.h" +#include namespace GameX::Physics { void RigidBody::Update(float delta_time) { position += velocity * delta_time; + if (position.y < -20.0) { + std::cout << "GAME OVER" << std::endl; + exit(1); + } orientation = Base::Rotate(angular_velocity * delta_time) * orientation; } From f69bc5948a538c366eb006dc3478aae7e9ff00eb Mon Sep 17 00:00:00 2001 From: Rita1218 <145887023+Rita1218@users.noreply.github.com> Date: Tue, 16 Jan 2024 09:24:03 +0800 Subject: [PATCH 05/14] Update rigid_body.cpp --- src/GameX/physics/rigid_body.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/GameX/physics/rigid_body.cpp b/src/GameX/physics/rigid_body.cpp index 99a695e..f2539ac 100644 --- a/src/GameX/physics/rigid_body.cpp +++ b/src/GameX/physics/rigid_body.cpp @@ -1,13 +1,15 @@ #include "GameX/physics/rigid_body.h" -#include + namespace GameX::Physics { void RigidBody::Update(float delta_time) { position += velocity * delta_time; if (position.y < -20.0) { - std::cout << "GAME OVER" << std::endl; - exit(1); + position = ini_position + glm::vec3{0.0f, 5.0f, 0.0f}; + velocity = glm::vec3{0.0f, 0.0f, 0.0f}; + angular_velocity = glm::vec3{0.0f, 0.0f, 0.0f}; + orientation = glm::mat3{1.0f}; } orientation = Base::Rotate(angular_velocity * delta_time) * orientation; } From 22603ce746ea88a76ed1b17200c8c95460e9da76 Mon Sep 17 00:00:00 2001 From: Rita1218 <145887023+Rita1218@users.noreply.github.com> Date: Tue, 16 Jan 2024 09:25:48 +0800 Subject: [PATCH 06/14] Update player_input.cpp --- src/GameBall/logic/player_input.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/GameBall/logic/player_input.cpp b/src/GameBall/logic/player_input.cpp index c002a91..57a6391 100644 --- a/src/GameBall/logic/player_input.cpp +++ b/src/GameBall/logic/player_input.cpp @@ -13,6 +13,10 @@ 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_.jump = (glfwGetKey(window, GLFW_KEY_LEFT_SHIFT) == GLFW_PRESS); + input_.jump = (glfwGetKey(window, GLFW_KEY_RIGHT_SHIFT) == GLFW_PRESS); + input_.quit = (glfwGetKey(window, GLFW_KEY_Q) == GLFW_PRESS); + input_.reset = (glfwGetKey(window, GLFW_KEY_R) == GLFW_PRESS); auto camera_controller = app_->CameraController(); auto pitch_yaw = camera_controller->GetPitchYaw(); auto pitch = pitch_yaw.x; From 99ad04a8c81dd6bf083f29d89b63858346eee0bc Mon Sep 17 00:00:00 2001 From: Rita1218 <145887023+Rita1218@users.noreply.github.com> Date: Tue, 16 Jan 2024 09:26:31 +0800 Subject: [PATCH 07/14] Update player_input.h --- src/GameBall/logic/player_input.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/GameBall/logic/player_input.h b/src/GameBall/logic/player_input.h index 98b60c0..fe2b962 100644 --- a/src/GameBall/logic/player_input.h +++ b/src/GameBall/logic/player_input.h @@ -12,6 +12,9 @@ struct PlayerInput { bool move_left{false}; bool move_right{false}; bool brake{false}; + bool jump{false}; + bool quit{false}; + bool reset{false}; glm::vec3 orientation{0.0f, 0.0f, 1.0f}; }; From 73caa49df5ee5427ea6fc03e87b18785bb4f5eda Mon Sep 17 00:00:00 2001 From: Rita1218 <145887023+Rita1218@users.noreply.github.com> Date: Tue, 16 Jan 2024 09:28:53 +0800 Subject: [PATCH 08/14] Update regular_ball.cpp --- src/GameBall/logic/units/regular_ball.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/GameBall/logic/units/regular_ball.cpp b/src/GameBall/logic/units/regular_ball.cpp index b8373aa..f5cfe30 100644 --- a/src/GameBall/logic/units/regular_ball.cpp +++ b/src/GameBall/logic/units/regular_ball.cpp @@ -70,7 +70,18 @@ void RegularBall::UpdateTick() { if (input.move_right) { moving_direction += forward; } - + //if (input.jump) { + //moving_direction+= + //} + if (input.quit) { + exit(0); + } + if (input.reset) { + sphere.position = sphere.ini_position + glm::vec3{0.0f, 5.0f, 0.0f}; + sphere.velocity = glm::vec3{0.0f, 0.0f, 0.0f}; + sphere.angular_velocity = glm::vec3{0.0f, 0.0f, 0.0f}; + sphere.orientation = glm::mat3{1.0f}; + } if (glm::length(moving_direction) > 0.0f) { moving_direction = glm::normalize(moving_direction); sphere.angular_velocity += From 0b8188dcf420f681f05366d2325dda9c379cb5cf Mon Sep 17 00:00:00 2001 From: Rita1218 <145887023+Rita1218@users.noreply.github.com> Date: Tue, 16 Jan 2024 09:56:18 +0800 Subject: [PATCH 09/14] Update regular_ball.cpp --- src/GameBall/logic/units/regular_ball.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/GameBall/logic/units/regular_ball.cpp b/src/GameBall/logic/units/regular_ball.cpp index f5cfe30..7ce2645 100644 --- a/src/GameBall/logic/units/regular_ball.cpp +++ b/src/GameBall/logic/units/regular_ball.cpp @@ -70,9 +70,11 @@ void RegularBall::UpdateTick() { if (input.move_right) { moving_direction += forward; } - //if (input.jump) { - //moving_direction+= - //} + if (input.jump) { + if (sphere.position.y <= 1 && sphere.position.y >= 0) { + sphere.velocity += glm::vec3{0.0f, 7.0f, 0.0f}; + } + } if (input.quit) { exit(0); } From 35ca731f8fa3f94f872d728d7ad691a29081cdb8 Mon Sep 17 00:00:00 2001 From: Rita1218 <145887023+Rita1218@users.noreply.github.com> Date: Tue, 16 Jan 2024 09:56:54 +0800 Subject: [PATCH 10/14] Update player_input.cpp --- src/GameBall/logic/player_input.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/GameBall/logic/player_input.cpp b/src/GameBall/logic/player_input.cpp index 57a6391..cf4fae9 100644 --- a/src/GameBall/logic/player_input.cpp +++ b/src/GameBall/logic/player_input.cpp @@ -13,8 +13,7 @@ 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_.jump = (glfwGetKey(window, GLFW_KEY_LEFT_SHIFT) == GLFW_PRESS); - input_.jump = (glfwGetKey(window, GLFW_KEY_RIGHT_SHIFT) == GLFW_PRESS); + input_.jump = (glfwGetKey(window, GLFW_KEY_J) == GLFW_PRESS); input_.quit = (glfwGetKey(window, GLFW_KEY_Q) == GLFW_PRESS); input_.reset = (glfwGetKey(window, GLFW_KEY_R) == GLFW_PRESS); auto camera_controller = app_->CameraController(); From 671f76f3074df6a7be540a4e6b8c51eaf25d8709 Mon Sep 17 00:00:00 2001 From: Rita1218 <145887023+Rita1218@users.noreply.github.com> Date: Tue, 16 Jan 2024 09:58:05 +0800 Subject: [PATCH 11/14] Update rigid_body.cpp --- src/GameX/physics/rigid_body.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/GameX/physics/rigid_body.cpp b/src/GameX/physics/rigid_body.cpp index f2539ac..90aa9f9 100644 --- a/src/GameX/physics/rigid_body.cpp +++ b/src/GameX/physics/rigid_body.cpp @@ -5,7 +5,7 @@ namespace GameX::Physics { void RigidBody::Update(float delta_time) { position += velocity * delta_time; - if (position.y < -20.0) { + if (position.y < -10.0) { position = ini_position + glm::vec3{0.0f, 5.0f, 0.0f}; velocity = glm::vec3{0.0f, 0.0f, 0.0f}; angular_velocity = glm::vec3{0.0f, 0.0f, 0.0f}; From 39de9919e6710a49109d31f0b42f051fca1202fc Mon Sep 17 00:00:00 2001 From: Rita1218 <145887023+Rita1218@users.noreply.github.com> Date: Tue, 16 Jan 2024 10:31:26 +0800 Subject: [PATCH 12/14] Update game_ball.cpp --- src/GameBall/core/game_ball.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/GameBall/core/game_ball.cpp b/src/GameBall/core/game_ball.cpp index a47b79e..671a5f6 100644 --- a/src/GameBall/core/game_ball.cpp +++ b/src/GameBall/core/game_ball.cpp @@ -39,8 +39,14 @@ void GameBall::OnInit() { auto enemy_player = world->CreatePlayer(); auto primary_unit = world->CreateUnit( primary_player->PlayerId(), glm::vec3{0.0f, 1.0f, 0.0f}, 1.0f, 1.0f); - auto enemy_unit = world->CreateUnit( + auto enemy_unit_1 = world->CreateUnit( enemy_player->PlayerId(), glm::vec3{-5.0f, 1.0f, 0.0f}, 1.0f, 1.0f); + auto enemy_unit_2 = world->CreateUnit( + enemy_player->PlayerId(), glm::vec3{5.0f, 1.0f, 0.0f}, 1.0f, 1.0f); + auto enemy_unit_3 = world->CreateUnit( + enemy_player->PlayerId(), glm::vec3{0.0f, 1.0f, 5.0f}, 1.0f, 1.0f); + auto enemy_unit_4 = world->CreateUnit( + enemy_player->PlayerId(), glm::vec3{0.0f, 1.0f, -5.0f}, 1.0f, 1.0f); auto primary_obstacle = world->CreateObstacle( glm::vec3{0.0f, -10.0f, 0.0f}, std::numeric_limits::infinity(), false, 20.0f); From 602b4d8a0b10cfe8cdcab0bb801fefacd4092a97 Mon Sep 17 00:00:00 2001 From: Rita1218 <145887023+Rita1218@users.noreply.github.com> Date: Tue, 16 Jan 2024 10:36:21 +0800 Subject: [PATCH 13/14] Update regular_ball.cpp --- src/GameBall/logic/units/regular_ball.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/GameBall/logic/units/regular_ball.cpp b/src/GameBall/logic/units/regular_ball.cpp index 7ce2645..c7313f0 100644 --- a/src/GameBall/logic/units/regular_ball.cpp +++ b/src/GameBall/logic/units/regular_ball.cpp @@ -17,6 +17,7 @@ RegularBall::RegularBall(World *world, sphere_id_ = physics_world->CreateSphere(); auto &sphere = physics_world->GetSphere(sphere_id_); sphere.position = position_; + sphere.ini_position = position_; sphere.SetRadiusMass(radius_, mass_); sphere.orientation = orientation_; sphere.velocity = velocity_; From 0f19f08f8cbc6724f85f667b5565420f72e91426 Mon Sep 17 00:00:00 2001 From: Rita1218 <145887023+Rita1218@users.noreply.github.com> Date: Tue, 16 Jan 2024 11:17:56 +0800 Subject: [PATCH 14/14] Update rigid_body.h --- src/GameX/physics/rigid_body.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/GameX/physics/rigid_body.h b/src/GameX/physics/rigid_body.h index 4b43b4d..59f3848 100644 --- a/src/GameX/physics/rigid_body.h +++ b/src/GameX/physics/rigid_body.h @@ -9,6 +9,7 @@ struct RigidBody { glm::mat3 inertia{1.0f}; // inertia tensor without orientation glm::mat3 inertia_inv{1.0f}; // inverse inertia tensor without orientation glm::vec3 position{0.0f}; + glm::vec3 ini_position{0.0f}; glm::vec3 velocity{0.0f}; glm::vec3 angular_velocity{0.0f}; glm::mat3 orientation{1.0f};