forked from Yao-class-cpp-studio/GameX
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
125 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,27 @@ | ||
#include "GameBall/logic/player_input.h" | ||
|
||
namespace GameBall::Logic {} | ||
#include "GameBall/core/game_ball.h" | ||
|
||
namespace GameBall::Logic { | ||
PlayerInputController::PlayerInputController(GameBall *app) : app_(app) { | ||
} | ||
|
||
PlayerInput PlayerInputController::GetInput() { | ||
auto window = app_->Window(); | ||
input_.move_forward = (glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS); | ||
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_.brake = (glfwGetKey(window, GLFW_KEY_SPACE) == GLFW_PRESS); | ||
auto camera_controller = app_->CameraController(); | ||
auto pitch_yaw = camera_controller->GetPitchYaw(); | ||
auto pitch = pitch_yaw.x; | ||
auto yaw = pitch_yaw.y; | ||
input_.orientation = {glm::sin(glm::radians(yaw)), 0.0f, | ||
-glm::cos(glm::radians(yaw))}; | ||
auto result = input_; | ||
input_ = {}; | ||
return result; | ||
} | ||
|
||
} // namespace GameBall::Logic |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,28 @@ | ||
#pragma once | ||
#include "GameBall/core/utils.h" | ||
|
||
namespace GameBall { | ||
class GameBall; | ||
} | ||
|
||
namespace GameBall::Logic { | ||
struct PlayerInput { | ||
bool move_forward{false}; | ||
bool move_backward{false}; | ||
bool move_left{false}; | ||
bool move_right{false}; | ||
bool brake{false}; | ||
glm::vec3 orientation{0.0f, 0.0f, 1.0f}; | ||
}; | ||
|
||
class PlayerInputController { | ||
public: | ||
PlayerInputController(GameBall *app); | ||
PlayerInput GetInput(); | ||
|
||
private: | ||
GameBall *app_; | ||
PlayerInput input_{}; | ||
}; | ||
|
||
} // namespace GameBall::Logic |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters