X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fui%2Fui.cpp;h=dd113ca2b620d8fd763934459e9e4b1f088c15ce;hb=f0a20986c573c4df1eb1212333489252c4b30efa;hp=0f82139b2a7bd5350db9965e51d89ea1ea3c0843;hpb=54f3f1260b95a924fcb40d9d6de3fa2e2c382f6f;p=blank.git diff --git a/src/ui/ui.cpp b/src/ui/ui.cpp index 0f82139..dd113ca 100644 --- a/src/ui/ui.cpp +++ b/src/ui/ui.cpp @@ -37,12 +37,10 @@ PlayerController::PlayerController(World &world, Player &player) : world(world) , player(player) , move_dir(0.0f) -, pitch(0.0f) -, yaw(0.0f) , dirty(true) , aim_world() , aim_entity() { - + player.GetEntity().SetController(*this); } void PlayerController::SetMovement(const glm::vec3 &m) noexcept { @@ -54,20 +52,20 @@ void PlayerController::SetMovement(const glm::vec3 &m) noexcept { Invalidate(); } +glm::vec3 PlayerController::ControlForce(const Entity &e, const EntityState &s) const { + return TargetVelocity(rotateY(move_dir * e.MaxVelocity(), s.yaw), s, 5.0f); +} + void PlayerController::TurnHead(float dp, float dy) noexcept { - pitch += dp; - if (pitch > PI / 2) { - pitch = PI / 2; - } else if (pitch < -PI / 2) { - pitch = -PI / 2; - } - yaw += dy; - if (yaw > PI) { - yaw -= PI * 2; - } else if (yaw < -PI) { - yaw += PI * 2; - } - Invalidate(); + player.GetEntity().TurnHead(dp, dy); +} + +float PlayerController::GetPitch() const noexcept { + return player.GetEntity().Pitch(); +} + +float PlayerController::GetYaw() const noexcept { + return player.GetEntity().Yaw(); } void PlayerController::SelectInventory(int i) noexcept { @@ -83,12 +81,7 @@ void PlayerController::Invalidate() noexcept { } void PlayerController::UpdatePlayer() noexcept { - constexpr float max_vel = 5.0f; // in m/s if (dirty) { - player.GetEntity().Orientation(glm::quat(glm::vec3(0.0f, yaw, 0.0f))); - player.GetEntity().GetModel().EyesState().orientation = glm::quat(glm::vec3(pitch, 0.0f, 0.0f)); - player.GetEntity().TargetVelocity(glm::rotateY(move_dir * max_vel, yaw)); - Ray aim = player.Aim(); if (!world.Intersection(aim, glm::mat4(1.0f), player.GetEntity().ChunkCoords(), aim_world)) { aim_world = WorldCollision(); @@ -112,12 +105,12 @@ void PlayerController::UpdatePlayer() noexcept { DirectInput::DirectInput(World &world, Player &player, WorldManipulator &manip) : PlayerController(world, player) , manip(manip) -, place_timer(256) -, remove_timer(256) { +, place_timer(0.25f) +, remove_timer(0.25f) { } -void DirectInput::Update(int dt) { +void DirectInput::Update(Entity &, float dt) { Invalidate(); // world has changed in the meantime UpdatePlayer(); @@ -465,10 +458,20 @@ Interface::Interface( , fwd(0) , rev(0) , slot(0) -, num_slots(10) { +, num_slots(10) +, locked(false) { } +void Interface::Lock() { + fwd = glm::ivec3(0); + rev = glm::ivec3(0); + locked = true; +} + +void Interface::Unlock() { + locked = false; +} void Interface::HandlePress(const SDL_KeyboardEvent &event) { if (!config.input.keyboard) return; @@ -600,7 +603,7 @@ void Interface::HandleRelease(const SDL_KeyboardEvent &event) { } void Interface::Handle(const SDL_MouseMotionEvent &event) { - if (!config.input.mouse) return; + if (locked || !config.input.mouse) return; player_ctrl.TurnHead( event.yrel * config.input.pitch_sensitivity, event.xrel * config.input.yaw_sensitivity);