4#include <glm/gtc/matrix_transform.hpp>
20 PLOGD <<
"VrMovementComponent initialized";
29 glm::vec3 currentPos =
headset_->getPlayerPosition();
30 glm::vec3 movement{0.0f};
36 if (glm::length(thumbstick) <
deadzone_) {
37 thumbstick = glm::vec2{0.0f};
42 glm::vec3 rightXZ = glm::normalize(glm::cross(forwardXZ, glm::vec3{0.0f, 1.0f, 0.0f}));
45 movement += forwardXZ * thumbstick.y *
moveSpeed_ *
static_cast<float>(deltaTime);
46 movement += rightXZ * thumbstick.x *
moveSpeed_ *
static_cast<float>(deltaTime);
54 float upInput = glm::max(triggerLeft, triggerRight);
55 float downInput = glm::max(gripLeft, gripRight);
57 movement.y += (upInput - downInput) *
verticalSpeed_ *
static_cast<float>(deltaTime);
60 currentPos += movement;
61 headset_->setPlayerPosition(currentPos);
73 glm::mat4 viewMatrix =
headset_->getEyeViewMatrix(0);
82 glm::vec3 forward = -glm::vec3(viewMatrix[0][2], viewMatrix[1][2], viewMatrix[2][2]);
86 float length = glm::length(forward);
87 if (length > 0.001f) {
91 forward = glm::vec3{0.0f, 0.0f, -1.0f};
virtual void endPlay()
Called when the component is removed or the game ends.
void setCanTick(bool enable)
Enables or disables ticking for this component.
virtual void beginPlay()
Called when the component is added to the scene or the game starts.
LogicComponent(Scene *owningScene)
A scene is the overarching structure which can spawn actors.
Input::XrInputHandler * inputHandler_
void beginPlay() override
Called when the component is added to the scene or the game starts.
void tick(double deltaTime) override
Called every frame if ticking is enabled.
void endPlay() override
Called when the component is removed or the game ends.
glm::vec3 getHeadsetForwardXZ() const
VrMovementComponent(Scene *owningScene, Headset *headset, Input::XrInputHandler *inputHandler)
Constructs the VR movement component.
Log category system implementation.