From 94ec6c481e7251c499e763555636b8fa7f56d96e Mon Sep 17 00:00:00 2001 From: Gary2005 <2803175673@qq.com> Date: Sat, 20 Jan 2024 15:07:33 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E8=BE=93=E5=85=A5?= =?UTF-8?q?=E6=8E=A7=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .DS_Store | Bin 0 -> 8196 bytes src/GameBall/logic/units/regular_ball.cpp | 74 +++++++++++----------- 2 files changed, 37 insertions(+), 37 deletions(-) create mode 100644 .DS_Store diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..7cff3eeebb4caf50409c75dfcb72da7ab9f89409 GIT binary patch literal 8196 zcmeHMU2GIp6h3EKU~bCK1q+=npc^V8b&;0eB4D=LrTj_>+jdJq>+H@zCroG7o!MQa zV(Q<6Mu4VoCAF!2Xoupt^>&=@t*NPP3jc<$WU$`%@5j2f7m%sq3@ z&&)mNe&^mjvjBjplF<&J0f0)EpuB;)8#Eyo*L6(^IYNkJ4`AdfULj|@x$ATzMihZ4 z0#O8_2t*NxBJlr+0G-*QsZ*T$QX2J91fmGsk`WO5L!2%_lOY|GG}t<*3rYZ@^~4Su z-BTS9*u+Dc4C$Dpfhj#xRu34OVpw9JG$(mns1r?wbWBod4k*n5!#87CpuDs}bKrq57ks153anPIn*@pZrC zrS#%{G3s?)J6FBebN!ZC8RCsyuH);LV-^Dg%P>jhK-O{$w~}&8j^PEi87WYi%7%E; z=;(^JM0{QQu|#~deQo=yM7*P8^|512o!_!@o2`*bgF zI)>#O8l*rvzID(ti;Ta?dL4bl9Otv=%v#W-X#=I4^+?I`ALT8o8gLgb(%1om=JY!?bK!I>mQ}%#ICA8=yrQp&5H~F%hyi->+#8i8t@kJ-?@5Iy9?~!q=y|G;Pou z){ACOg)qfG4f$J%A1nq*gxMCu^4(%6+)1wN6A$b(jKC2QL~W0@SLK&fT2;#_TZCka zw*<7>l57QURZ)~W zWv0@sERi!;s;M(D;Yo0#tR`~JUSNCW@LQg8)yI;`+t%gU(XaPId|S|jq`68 zIkIkJasp2hfK|+0i{t>lH7gsyH%OI9xErUeX^t&qi>FGrKEl0uL>1uWGo*H$El~;g ze3~3CWy@4TJfALyt+9kkImVS>$X3SM8D$c$lf%~7TBdT8gAR5dqnzUPdhFXbczPV!SKFXad*b zI_wB=n#L`-6}RCI%wR9}W0tU*3$S_+T`XV`JuKnlIEGK+Q}{F<#}oJhzKAaodQakM ze0LHechn*h&(|Vy#7(EeugmJL6|bNB^6gJLCupG*SO=nfm+x&E#_AOB8`90+S+u_32DHMa-$TJW*@M>3Wzh(S+WZ zq=5-_K{-w|D94FT{9#DPhysicsWorld(); 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 ddc1e3e64521009aeb344de9ca35b50500f0648f Mon Sep 17 00:00:00 2001 From: Gary2005 <2803175673@qq.com> Date: Sat, 20 Jan 2024 15:30:53 +0800 Subject: [PATCH 2/2] add rotate command --- src/GameBall/logic/player_input.cpp | 2 ++ src/GameBall/logic/player_input.h | 2 ++ src/GameBall/logic/units/regular_ball.cpp | 6 ++++++ 3 files changed, 10 insertions(+) diff --git a/src/GameBall/logic/player_input.cpp b/src/GameBall/logic/player_input.cpp index c002a91..e0d8d84 100644 --- a/src/GameBall/logic/player_input.cpp +++ b/src/GameBall/logic/player_input.cpp @@ -12,6 +12,8 @@ PlayerInput PlayerInputController::GetInput() { input_.move_backward = (glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS); input_.move_left = (glfwGetKey(window, GLFW_KEY_A) == GLFW_PRESS); input_.move_right = (glfwGetKey(window, GLFW_KEY_D) == GLFW_PRESS); + input_.rotate_left=(glfwGetKey(window, GLFW_KEY_Q) == GLFW_PRESS); + input_.rotate_right=(glfwGetKey(window, GLFW_KEY_E) == GLFW_PRESS); input_.brake = (glfwGetKey(window, GLFW_KEY_SPACE) == GLFW_PRESS); auto camera_controller = app_->CameraController(); auto pitch_yaw = camera_controller->GetPitchYaw(); diff --git a/src/GameBall/logic/player_input.h b/src/GameBall/logic/player_input.h index 98b60c0..2ec0382 100644 --- a/src/GameBall/logic/player_input.h +++ b/src/GameBall/logic/player_input.h @@ -12,6 +12,8 @@ struct PlayerInput { bool move_left{false}; bool move_right{false}; bool brake{false}; + bool rotate_left{false}; + bool rotate_right{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 1e1bb31..dbfe2bc 100644 --- a/src/GameBall/logic/units/regular_ball.cpp +++ b/src/GameBall/logic/units/regular_ball.cpp @@ -70,6 +70,12 @@ void RegularBall::UpdateTick() { if (input.move_right) { moving_direction += forward; } + if(input.rotate_left) { + moving_direction +=glm::normalize(glm::vec3{0.0f, 1.0f, 0.0f}); + } + if(input.rotate_right) { + moving_direction -=glm::normalize(glm::vec3{0.0f, 1.0f, 0.0f}); + } if (glm::length(moving_direction) > 0.0f) { moving_direction = glm::normalize(moving_direction);