Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/GameBall/core/camera_third_person.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,8 @@ void CameraControllerThirdPerson::CursorMove(float x, float y) {
dst_pitch_ += y * 0.1f;
dst_pitch_ = glm::clamp(dst_pitch_, -89.0f, 89.0f);
}

void CameraControllerThirdPerson::CursorScroll(float x, float y) {
dst_distance_ += y * 0.5f;
}
} // namespace GameBall
2 changes: 2 additions & 0 deletions src/GameBall/core/camera_third_person.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ class CameraControllerThirdPerson {

void CursorMove(float x, float y);

void CursorScroll(float x, float y);

private:
GameX::Graphics::PCamera camera_;
float dst_distance_{10.0f};
Expand Down
9 changes: 9 additions & 0 deletions src/GameBall/core/game_ball.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,4 +150,13 @@ void GameBall::CursorPosCallback(double xpos, double ypos) {
ignore_next_mouse_move_ = false;
}

void GameBall::ScrollCallback(double xoffset, double yoffset) {

if (!ignore_next_mouse_move_) {
camera_controller_->CursorScroll(xoffset, yoffset);
}

ignore_next_mouse_move_ = false;
}

} // namespace GameBall
2 changes: 2 additions & 0 deletions src/GameBall/core/game_ball.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ class GameBall : public GameX::Base::Application {

void CursorPosCallback(double xpos, double ypos) override;

void ScrollCallback(double xoffset, double yoffset) override;

CameraControllerThirdPerson *CameraController() {
return camera_controller_.get();
}
Expand Down
8 changes: 4 additions & 4 deletions src/GameBall/logic/player_input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ 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_.move_forward = (glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS) | (glfwGetKey(window, GLFW_KEY_UP) == GLFW_PRESS);
input_.move_backward = (glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS) | (glfwGetKey(window, GLFW_KEY_DOWN) == GLFW_PRESS);
input_.move_left = (glfwGetKey(window, GLFW_KEY_A) == GLFW_PRESS) | (glfwGetKey(window, GLFW_KEY_LEFT) == GLFW_PRESS);
input_.move_right = (glfwGetKey(window, GLFW_KEY_D) == GLFW_PRESS) | (glfwGetKey(window, GLFW_KEY_RIGHT) == GLFW_PRESS);
input_.brake = (glfwGetKey(window, GLFW_KEY_SPACE) == GLFW_PRESS);
auto camera_controller = app_->CameraController();
auto pitch_yaw = camera_controller->GetPitchYaw();
Expand Down
76 changes: 38 additions & 38 deletions src/GameBall/logic/units/regular_ball.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -144,4 +144,4 @@ glm::vec3 RegularBall::AngularMomentum() const {
return augular_momentum_;
}

} // namespace GameBall::Logic::Units
} //namespace GameBall::Logic::Units