X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fcontroller.cpp;h=b996f9e37a04c80301a5776c288b5af09202b38e;hb=88620c3c816c47b32a90758f40efe5d02c50bbfa;hp=5d547b7eab8d3a39b725137425367fe9480d960d;hpb=32a385382b73072438c99b533686a4bb9ba4742c;p=blank.git diff --git a/src/controller.cpp b/src/controller.cpp index 5d547b7..b996f9e 100644 --- a/src/controller.cpp +++ b/src/controller.cpp @@ -1,38 +1,49 @@ #include "controller.hpp" -#include #include #include -#include namespace blank { -FPSController::FPSController() -: velocity(0, 0, 0) -, position(0, 0, 0) +FPSController::FPSController(Entity &entity) +: entity(entity) , pitch(0) , yaw(0) { } -FPSController::~FPSController() { +void FPSController::Pitch(float p) { + pitch = p; + if (pitch > PI / 2) { + pitch = PI / 2; + } else if (pitch < -PI / 2) { + pitch = -PI / 2; + } } - -glm::mat4 FPSController::Transform() const { - return glm::translate(position) * glm::eulerAngleYX(yaw, pitch); +void FPSController::RotatePitch(float delta) { + Pitch(pitch + delta); } +void FPSController::Yaw(float y) { + yaw = y; + if (yaw > PI) { + yaw -= PI * 2; + } else if (yaw < -PI) { + yaw += PI * 2; + } +} -void FPSController::OrientationVelocity(const glm::vec3 &vel) { - velocity = glm::rotateY(vel, yaw); +void FPSController::RotateYaw(float delta) { + Yaw(yaw + delta); } void FPSController::Update(int dt) { - position += velocity * float(dt); + entity.Rotation(glm::eulerAngleYX(yaw, pitch)); + entity.Velocity(glm::rotateY(velocity, yaw)); } }