base
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
#include "CharacterMind.h"
|
||||
|
||||
#include "Camera.h"
|
||||
#include "common.h"
|
||||
#include "Keyboard.h"
|
||||
|
||||
void KeyboardMind::ProduceActions(const Character& character, std::vector<CharacterAction>& actions)
|
||||
{
|
||||
glm::vec3 direction(0.0f);
|
||||
|
||||
if (enabled) {
|
||||
// Flattened, so looking up or down doesn't slow walking
|
||||
const glm::vec3 forward = camera.t.GetFrontVector();
|
||||
const glm::vec3 right = camera.t.GetRightVector();
|
||||
const glm::vec3 flatForward = glm::normalize(glm::vec3(forward.x, 0.0f, forward.z));
|
||||
const glm::vec3 flatRight = glm::normalize(glm::vec3(right.x, 0.0f, right.z));
|
||||
|
||||
// The camera's right vector points to the left of the screen, so A adds it
|
||||
if (keyboard->IsKeyDown(GLFW_KEY_W)) direction += flatForward;
|
||||
if (keyboard->IsKeyDown(GLFW_KEY_S)) direction -= flatForward;
|
||||
if (keyboard->IsKeyDown(GLFW_KEY_A)) direction += flatRight;
|
||||
if (keyboard->IsKeyDown(GLFW_KEY_D)) direction -= flatRight;
|
||||
if (glm::length(direction) > 0.0f)
|
||||
direction = glm::normalize(direction);
|
||||
}
|
||||
|
||||
// Always sent, so letting go of the keys stops the character
|
||||
actions.push_back(CharacterAction::Move(direction));
|
||||
}
|
||||
Reference in New Issue
Block a user