KekEngine/src/kekengine/cpp/player/noclipplayercontroller.cpp

55 lines
1.3 KiB
C++

#include "noclipplayercontroller.h"
#include "input.h"
#include "internal.h"
namespace kek {
NoclipPlayerController::NoclipPlayerController() {
}
NoclipPlayerController::~NoclipPlayerController() {
}
glm::vec3 NoclipPlayerController::move(glm::vec3 movement) {
kekData.player->translate(movement);
return movement;
}
void NoclipPlayerController::update() {
if(Input::isKeyboardCaptured()) return;
glm::vec3 direction = glm::vec3(0);
if(Input::getKeyState(keyForward) == GLFW_PRESS) {
direction += kekData.activeCamera->direction;
}
if(Input::getKeyState(keyBackward) == GLFW_PRESS) {
direction += -kekData.activeCamera->direction;
}
if(Input::getKeyState(keyLeft) == GLFW_PRESS) {
direction += -glm::normalize(glm::cross(kekData.activeCamera->direction, glm::vec3(0.0f, 1.0f, 0.0f)));
}
if(Input::getKeyState(keyRight) == GLFW_PRESS) {
direction += glm::normalize(glm::cross(kekData.activeCamera->direction, glm::vec3(0.0f, 1.0f, 0.0f)));
}
if(Input::getKeyState(keyUp) == GLFW_PRESS) {
direction += glm::vec3(0, 1, 0);
}
if(Input::getKeyState(keyDown) == GLFW_PRESS) {
direction += glm::vec3(0, -1, 0);
}
if(glm::length2(direction) > 0) {
direction = glm::normalize(direction) * noclipSpeed * kekData.lastFrameTime;
move(direction);
}
}
}