]> git.localhorst.tv Git - blank.git/blobdiff - src/controller.cpp
fix error in border block calculation
[blank.git] / src / controller.cpp
index d0a026b7069111284a38ef259819c83ed9af2377..b996f9e37a04c80301a5776c288b5af09202b38e 100644 (file)
@@ -1,34 +1,49 @@
 #include "controller.hpp"
 
-#include <glm/gtc/matrix_transform.hpp>
 #include <glm/gtx/euler_angles.hpp>
 #include <glm/gtx/rotate_vector.hpp>
-#include <glm/gtx/transform.hpp>
 
 
 namespace blank {
 
-FPSController::FPSController()
-: velocity(0, 0, 0)
-, position(0, 0, 0)
+FPSController::FPSController(Entity &entity)
+: entity(entity)
 , pitch(0)
 , yaw(0) {
 
 }
 
 
-glm::mat4 FPSController::Transform() const {
-       return glm::translate(position) * glm::eulerAngleYX(yaw, pitch);
+void FPSController::Pitch(float p) {
+       pitch = p;
+       if (pitch > PI / 2) {
+               pitch = PI / 2;
+       } else if (pitch < -PI / 2) {
+               pitch = -PI / 2;
+       }
 }
 
+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));
 }
 
 }