Vulkan Schnee 0.0.1 (22840dc8)
High-performance rendering engine
Loading...
Searching...
No Matches
Engine::Components::VrGlider Class Reference

VR locomotion component that switches between walking, falling, gliding, and stalled flight. More...

#include <VrGliderComponent.h>

Inheritance diagram for Engine::Components::VrGlider:
Collaboration diagram for Engine::Components::VrGlider:

Classes

struct  DebugSnapshot
 Diagnostics captured from the most recent tick() call. More...
struct  HandData
 Hand position and orientation data relative to head. More...

Public Member Functions

 VrGlider (Entities::Scene *owningScene, Rendering::Headset *headset, Input::InputManager *inputManager, PhysicsBody *physicsBody)
 Creates a VR glider locomotion component.
 ~VrGlider () override=default
 Destroys the component without owning the headset, input handler, or physics body.
std::string getComponentName () const override
 Returns the component registry name.
void beginPlay () override
 Initializes runtime state when the owning actor begins play.
void tick (double deltaTime) override
 Advances locomotion and writes the updated player position.
void endPlay () override
 Stops component play and calls the base Logic lifecycle hook.
bool drawImGui () override
 Draws and edits glider state in the engine ImGui inspector.
GliderState getState () const
 Returns the current movement state.
glm::vec3 getVelocity () const
 Returns the current locomotion velocity.
float getSpeed () const
 Returns the magnitude of the current locomotion velocity.
const GliderConfig & getConfig () const
 Returns the current glider tuning values.
GliderConfig & getConfig ()
 Returns mutable glider tuning values.
void setConfig (const GliderConfig &config)
 Replaces the active glider tuning values.
void setEnabled (bool enabled)
 Enables or disables locomotion processing.
bool isEnabled () const
 Returns whether locomotion processing is enabled.
void setFrozen (bool frozen)
 Freezes or unfreezes player movement.
void resetGliderStateTo (GliderState state)
 Resets velocity and persistent flight state, then sets the current movement state.
PhysicsBody * getPhysicsBody () const
 Returns the physics body controlled by this component.
const DebugSnapshot & getDebugSnapshot () const
 Returns diagnostics from the most recent tick.
bool isFrozen () const
 Returns whether movement is frozen.
void setDebugLogging (bool enabled)
 Enables or disables glider debug logging and debug drawing.
bool isDebugLogging () const
 Returns whether glider debug logging and debug drawing are enabled.
Public Member Functions inherited from Engine::Components::Logic
 Logic (Entities::Scene *owningScene)
 Constructs a logic component owned by a scene.
 Logic (const Entities::SpawnContext &context)
 Constructs a logic component from spawn context data.
virtual ~Logic ()=default
 Destroys the logic component.
virtual bool drawImGuiName ()
 Used to alter the name of the entity in the outliner.
bool hasBegunPlay () const
 Checks whether beginPlay() has been called without a matching endPlay().
bool canTick () const
 Checks if the component is currently set to tick.
void setCanTick (bool enable)
 Enables or disables ticking for this component.
Entities::Entity * getOwningEntity () const
 Gets the entity this component belongs to.

Static Public Member Functions

static const char * stateToString (GliderState state)
 Converts a glider state to a display string.

Static Public Attributes

static constexpr bool IsUnique = true
 This component type is unique per actor.
static constexpr const char * ComponentName = "VrGlider"
 Component registry name.
static constexpr float CAPSULE_RADIUS = 0.3f
 Radius of the player capsule used by glider sweep tests.
static constexpr float CAPSULE_HALF_HEIGHT = 0.7f
 Half of the cylinder section height used by glider sweep tests.
static constexpr float CAPSULE_TOTAL_HALF = 1.0f
 Half of the complete capsule height, including one radius.
Static Public Attributes inherited from Engine::Components::Logic
static constexpr bool IsUnique = false
 Defines whether multiple instances of this component can exist on the same entity. Defaults to false (multiple allowed). Override in derived classes with static constexpr bool IsUnique = true; if needed.
static constexpr const char * ComponentName = "Logic"
 Fallback component type name. Derived classes may override getComponentName() for custom labels.

Private Member Functions

HandData getHandData (Input::Hand hand) const
bool areArmsSpread (const HandData &leftHand, const HandData &rightHand, float hysteresis=0.0f) const
bool areHandsTucked (const HandData &leftHand, const HandData &rightHand) const
void updateGlidingVelocity (const HandData &leftHand, const HandData &rightHand, float dt)
ArcadeGliderTuning makeFlightTuning () const
glm::vec3 buildGlideDirection (const HandData &leftHand, const HandData &rightHand, glm::vec3 &outBodyForward, float &outForwardAmount, float &outRightAmount) const
glm::vec3 getHeadWorldPosition () const
 Returns the headset world position.
glm::quat getHeadOrientation () const
 Returns the headset world orientation.
glm::vec3 getHeadForward () const
 Returns the headset forward vector in world space.
bool canStartGlidingFromWalking (const glm::vec3 &currentPos, glm::vec3 &outTakeoffPos) const
bool handleFlightCollision (const glm::vec3 &currentPos, glm::vec3 &desiredPos)
bool sweepGround (const glm::vec3 &origin, glm::vec3 &outHitPoint, glm::vec3 &outHitNormal, float &outHitFraction) const
void updateWalkingInput (float dt)
glm::vec3 collideAndSlide (const glm::vec3 &startPos, const glm::vec3 &displacement)
void updateLastSafeLanding (const glm::vec3 &position, bool stableWalkableGround, float dt)
void teleportPlayer (const glm::vec3 &position)
void resetToLastSafeLanding ()
void resetToSpawn ()

Private Attributes

Rendering::Headset * headset_ = nullptr
Input::InputManager * inputManager_ = nullptr
PhysicsBody * physicsBody_ = nullptr
GliderConfig config_
GliderState currentState_ = GliderState::FALLING
bool takeoffArmed_ = true
glm::vec3 velocity_ { 0.0f }
bool enabled_ = true
bool frozen_ = true
bool debugLogging_ = true
float debugLogTimer_ = 0.0f
bool bothGripsWerePressed_ = false
ArcadeGliderState flightState_ {}
World::WindSample lastWindSample_ {}
DebugSnapshot debugSnapshot_ {}
glm::vec3 lastSafeLandingPosition_ { 0.0f, 10.0f, 0.0f }
bool hasLastSafeLandingPosition_ = false
float landingCheckpointTimer_ = 0.0f
float playerYaw_ = 0.0f
bool rightStickSnapTurnArmed_ = true
float smoothedGroundY_ = 0.0f
bool groundYInitialized_ = false

Static Private Attributes

static constexpr float DEBUG_LOG_INTERVAL = 0.5f
static constexpr float GRIP_THRESHOLD = 0.8f
static constexpr float SKIN_WIDTH = 0.02f
static constexpr int MAX_SLIDE_ITERATIONS = 3

Additional Inherited Members

Protected Member Functions inherited from Engine::Components::Logic
Entities::Scene * getScene () const
 Gets the scene this component belongs to.
Core::SceneManager * getSceneManager () const
 Helper to get the SceneManager from the owning scene.

Detailed Description

VR locomotion component that switches between walking, falling, gliding, and stalled flight.

VrGlider reads headset pose, hand poses, grip input, triggers, and thumbsticks from the XR runtime. It writes the locomotion root to the headset and attached Engine::Components::PhysicsBody. The component starts frozen so the player can put on the headset before movement begins. Press and release both grips to toggle the frozen state.

Add this component to an actor with a kinematic Engine::Components::PhysicsBody. The collision sweeps assume a player capsule matching Engine::Components::VrGlider::CAPSULE_RADIUS and Engine::Components::VrGlider::CAPSULE_HALF_HEIGHT.

Definition at line 114 of file VrGliderComponent.h.

Constructor & Destructor Documentation

◆ VrGlider()

Engine::Components::VrGlider::VrGlider ( Entities::Scene * owningScene,
Rendering::Headset * headset,
Input::InputManager * inputManager,
PhysicsBody * physicsBody )

Creates a VR glider locomotion component.

The component reads from headset and inputHandler every tick. The component teleports physicsBody to the computed locomotion-root position and writes its linear velocity. Passing nullptr for any runtime dependency leaves the component enabled but causes movement ticks to be skipped.

Parameters
owningSceneScene that owns this component.
headsetHeadset interface used for head pose and locomotion-root updates.
inputManagerXR input handler used for hand poses, grips, triggers, and thumbsticks.
physicsBodyKinematic physics body used for collision sweeps and velocity reporting.

◆ ~VrGlider()

Engine::Components::VrGlider::~VrGlider ( )
overridedefault

Destroys the component without owning the headset, input handler, or physics body.

Member Function Documentation

◆ areArmsSpread()

bool Engine::Components::VrGlider::areArmsSpread ( const HandData & leftHand,
const HandData & rightHand,
float hysteresis = 0.0f ) const
nodiscardprivate

◆ areHandsTucked()

bool Engine::Components::VrGlider::areHandsTucked ( const HandData & leftHand,
const HandData & rightHand ) const
nodiscardprivate

◆ beginPlay()

void Engine::Components::VrGlider::beginPlay ( )
overridevirtual

Initializes runtime state when the owning actor begins play.

The component applies the current snap-turn yaw to the headset and seeds the last safe landing position from GliderConfig::spawnPosition.

Reimplemented from Engine::Components::Logic.

◆ buildGlideDirection()

glm::vec3 Engine::Components::VrGlider::buildGlideDirection ( const HandData & leftHand,
const HandData & rightHand,
glm::vec3 & outBodyForward,
float & outForwardAmount,
float & outRightAmount ) const
nodiscardprivate

◆ canStartGlidingFromWalking()

bool Engine::Components::VrGlider::canStartGlidingFromWalking ( const glm::vec3 & currentPos,
glm::vec3 & outTakeoffPos ) const
private

◆ collideAndSlide()

glm::vec3 Engine::Components::VrGlider::collideAndSlide ( const glm::vec3 & startPos,
const glm::vec3 & displacement )
private

◆ drawImGui()

bool Engine::Components::VrGlider::drawImGui ( )
overridevirtual

Draws and edits glider state in the engine ImGui inspector.

The inspector exposes runtime flags, current diagnostics, collision state, wind state, and GliderConfig tuning values.

Returns
true after drawing the inspector.

Reimplemented from Engine::Components::Logic.

◆ endPlay()

void Engine::Components::VrGlider::endPlay ( )
overridevirtual

Stops component play and calls the base Logic lifecycle hook.

Reimplemented from Engine::Components::Logic.

◆ getComponentName()

std::string Engine::Components::VrGlider::getComponentName ( ) const
inlinenodiscardoverridevirtual

Returns the component registry name.

Returns
"VrGlider".

Reimplemented from Engine::Components::Logic.

Definition at line 261 of file VrGliderComponent.h.

References ComponentName.

◆ getConfig() [1/2]

GliderConfig & Engine::Components::VrGlider::getConfig ( )
inline

Returns mutable glider tuning values.

Changes affect subsequent ticks and the ImGui tuning panel.

Returns
Mutable reference to the active configuration.

Definition at line 337 of file VrGliderComponent.h.

References config_.

◆ getConfig() [2/2]

const GliderConfig & Engine::Components::VrGlider::getConfig ( ) const
inlinenodiscard

Returns the current glider tuning values.

Returns
Const reference to the active configuration.

Definition at line 325 of file VrGliderComponent.h.

References config_.

◆ getDebugSnapshot()

const DebugSnapshot & Engine::Components::VrGlider::getDebugSnapshot ( ) const
inlinenodiscard

Returns diagnostics from the most recent tick.

Returns
Reference to the internal debug snapshot.

Definition at line 404 of file VrGliderComponent.h.

References debugSnapshot_.

◆ getHandData()

HandData Engine::Components::VrGlider::getHandData ( Input::Hand hand) const
nodiscardprivate

◆ getHeadForward()

glm::vec3 Engine::Components::VrGlider::getHeadForward ( ) const
nodiscardprivate

Returns the headset forward vector in world space.

◆ getHeadOrientation()

glm::quat Engine::Components::VrGlider::getHeadOrientation ( ) const
nodiscardprivate

Returns the headset world orientation.

◆ getHeadWorldPosition()

glm::vec3 Engine::Components::VrGlider::getHeadWorldPosition ( ) const
nodiscardprivate

Returns the headset world position.

◆ getPhysicsBody()

PhysicsBody * Engine::Components::VrGlider::getPhysicsBody ( ) const
inlinenodiscard

Returns the physics body controlled by this component.

Returns
Pointer passed to the constructor, or nullptr when no body was provided.

Definition at line 398 of file VrGliderComponent.h.

References physicsBody_.

◆ getSpeed()

float Engine::Components::VrGlider::getSpeed ( ) const
inlinenodiscard

Returns the magnitude of the current locomotion velocity.

Returns
Speed in meters per second.

Definition at line 316 of file VrGliderComponent.h.

References velocity_.

◆ getState()

GliderState Engine::Components::VrGlider::getState ( ) const
inlinenodiscard

Returns the current movement state.

Returns
Current glider state after the most recent tick or reset.

Definition at line 298 of file VrGliderComponent.h.

References currentState_.

◆ getVelocity()

glm::vec3 Engine::Components::VrGlider::getVelocity ( ) const
inlinenodiscard

Returns the current locomotion velocity.

Returns
World-space velocity in meters per second.

Definition at line 307 of file VrGliderComponent.h.

References velocity_.

◆ handleFlightCollision()

bool Engine::Components::VrGlider::handleFlightCollision ( const glm::vec3 & currentPos,
glm::vec3 & desiredPos )
private

◆ isDebugLogging()

bool Engine::Components::VrGlider::isDebugLogging ( ) const
inlinenodiscard

Returns whether glider debug logging and debug drawing are enabled.

Returns
true when debug output is enabled.

Definition at line 428 of file VrGliderComponent.h.

References debugLogging_.

◆ isEnabled()

bool Engine::Components::VrGlider::isEnabled ( ) const
inlinenodiscard

Returns whether locomotion processing is enabled.

Returns
true when tick() processes movement.

Definition at line 368 of file VrGliderComponent.h.

References enabled_.

◆ isFrozen()

bool Engine::Components::VrGlider::isFrozen ( ) const
inlinenodiscard

Returns whether movement is frozen.

Returns
true when movement integration is skipped but input diagnostics still update.

Definition at line 410 of file VrGliderComponent.h.

References frozen_.

◆ makeFlightTuning()

ArcadeGliderTuning Engine::Components::VrGlider::makeFlightTuning ( ) const
nodiscardprivate

◆ resetGliderStateTo()

void Engine::Components::VrGlider::resetGliderStateTo ( GliderState state)

Resets velocity and persistent flight state, then sets the current movement state.

This does not teleport the player. Use it to recover from a bad state or to force a known locomotion mode from UI or gameplay code.

Parameters
stateNew movement state.

◆ resetToLastSafeLanding()

void Engine::Components::VrGlider::resetToLastSafeLanding ( )
private

◆ resetToSpawn()

void Engine::Components::VrGlider::resetToSpawn ( )
private

◆ setConfig()

void Engine::Components::VrGlider::setConfig ( const GliderConfig & config)
inline

Replaces the active glider tuning values.

Parameters
configNew configuration copied into the component.

Definition at line 346 of file VrGliderComponent.h.

References config_.

◆ setDebugLogging()

void Engine::Components::VrGlider::setDebugLogging ( bool enabled)
inline

Enables or disables glider debug logging and debug drawing.

Parameters
enabledtrue to emit periodic log messages and draw glider debug helpers.

Definition at line 419 of file VrGliderComponent.h.

References debugLogging_.

◆ setEnabled()

void Engine::Components::VrGlider::setEnabled ( bool enabled)
inline

Enables or disables locomotion processing.

Disabled components still exist and keep their current state. Ticks are skipped while disabled.

Parameters
enabledtrue to process movement ticks, false to skip movement ticks.

Definition at line 359 of file VrGliderComponent.h.

References enabled_.

◆ setFrozen()

void Engine::Components::VrGlider::setFrozen ( bool frozen)

Freezes or unfreezes player movement.

Freezing resets velocity and switches the component to GliderState::FALLING. Unfreezing also resets velocity and starts from GliderState::FALLING. The player can toggle this state by pressing and releasing both grips.

Parameters
frozentrue to skip movement while still sampling debug input, false to move normally.

◆ stateToString()

const char * Engine::Components::VrGlider::stateToString ( GliderState state)
staticnodiscard

Converts a glider state to a display string.

Parameters
stateState to convert.
Returns
Static string for known states, or "Unknown" for an invalid enum value.

◆ sweepGround()

bool Engine::Components::VrGlider::sweepGround ( const glm::vec3 & origin,
glm::vec3 & outHitPoint,
glm::vec3 & outHitNormal,
float & outHitFraction ) const
private

◆ teleportPlayer()

void Engine::Components::VrGlider::teleportPlayer ( const glm::vec3 & position)
private

◆ tick()

void Engine::Components::VrGlider::tick ( double deltaTime)
overridevirtual

Advances locomotion and writes the updated player position.

The tick reads XR input, updates the movement state, applies walking or flight movement, handles capsule sweeps, updates the attached physics body, and records Engine::Components::VrGlider::DebugSnapshot diagnostics. Movement is skipped when disabled, frozen, or missing a runtime dependency.

Parameters
deltaTimeFrame duration in seconds.

Reimplemented from Engine::Components::Logic.

◆ updateGlidingVelocity()

void Engine::Components::VrGlider::updateGlidingVelocity ( const HandData & leftHand,
const HandData & rightHand,
float dt )
private

◆ updateLastSafeLanding()

void Engine::Components::VrGlider::updateLastSafeLanding ( const glm::vec3 & position,
bool stableWalkableGround,
float dt )
private

◆ updateWalkingInput()

void Engine::Components::VrGlider::updateWalkingInput ( float dt)
private

Member Data Documentation

◆ bothGripsWerePressed_

bool Engine::Components::VrGlider::bothGripsWerePressed_ = false
private

Definition at line 526 of file VrGliderComponent.h.

◆ CAPSULE_HALF_HEIGHT

float Engine::Components::VrGlider::CAPSULE_HALF_HEIGHT = 0.7f
staticconstexpr

Half of the cylinder section height used by glider sweep tests.

Definition at line 122 of file VrGliderComponent.h.

◆ CAPSULE_RADIUS

float Engine::Components::VrGlider::CAPSULE_RADIUS = 0.3f
staticconstexpr

Radius of the player capsule used by glider sweep tests.

Definition at line 121 of file VrGliderComponent.h.

◆ CAPSULE_TOTAL_HALF

float Engine::Components::VrGlider::CAPSULE_TOTAL_HALF = 1.0f
staticconstexpr

Half of the complete capsule height, including one radius.

Definition at line 123 of file VrGliderComponent.h.

◆ ComponentName

const char* Engine::Components::VrGlider::ComponentName = "VrGlider"
staticconstexpr

Component registry name.

Definition at line 119 of file VrGliderComponent.h.

Referenced by getComponentName().

◆ config_

GliderConfig Engine::Components::VrGlider::config_
private

Definition at line 514 of file VrGliderComponent.h.

Referenced by getConfig(), getConfig(), and setConfig().

◆ currentState_

GliderState Engine::Components::VrGlider::currentState_ = GliderState::FALLING
private

Definition at line 515 of file VrGliderComponent.h.

Referenced by getState().

◆ DEBUG_LOG_INTERVAL

float Engine::Components::VrGlider::DEBUG_LOG_INTERVAL = 0.5f
staticconstexprprivate

Definition at line 523 of file VrGliderComponent.h.

◆ debugLogging_

bool Engine::Components::VrGlider::debugLogging_ = true
private

Definition at line 521 of file VrGliderComponent.h.

Referenced by isDebugLogging(), and setDebugLogging().

◆ debugLogTimer_

float Engine::Components::VrGlider::debugLogTimer_ = 0.0f
private

Definition at line 522 of file VrGliderComponent.h.

◆ debugSnapshot_

DebugSnapshot Engine::Components::VrGlider::debugSnapshot_ {}
private

Definition at line 531 of file VrGliderComponent.h.

Referenced by getDebugSnapshot().

◆ enabled_

bool Engine::Components::VrGlider::enabled_ = true
private

Definition at line 519 of file VrGliderComponent.h.

Referenced by isEnabled(), and setEnabled().

◆ flightState_

ArcadeGliderState Engine::Components::VrGlider::flightState_ {}
private

Definition at line 529 of file VrGliderComponent.h.

◆ frozen_

bool Engine::Components::VrGlider::frozen_ = true
private

Definition at line 520 of file VrGliderComponent.h.

Referenced by isFrozen().

◆ GRIP_THRESHOLD

float Engine::Components::VrGlider::GRIP_THRESHOLD = 0.8f
staticconstexprprivate

Definition at line 527 of file VrGliderComponent.h.

◆ groundYInitialized_

bool Engine::Components::VrGlider::groundYInitialized_ = false
private

Definition at line 542 of file VrGliderComponent.h.

◆ hasLastSafeLandingPosition_

bool Engine::Components::VrGlider::hasLastSafeLandingPosition_ = false
private

Definition at line 533 of file VrGliderComponent.h.

◆ headset_

Rendering::Headset* Engine::Components::VrGlider::headset_ = nullptr
private

Definition at line 510 of file VrGliderComponent.h.

◆ inputManager_

Input::InputManager* Engine::Components::VrGlider::inputManager_ = nullptr
private

Definition at line 511 of file VrGliderComponent.h.

◆ IsUnique

bool Engine::Components::VrGlider::IsUnique = true
staticconstexpr

This component type is unique per actor.

Definition at line 117 of file VrGliderComponent.h.

◆ landingCheckpointTimer_

float Engine::Components::VrGlider::landingCheckpointTimer_ = 0.0f
private

Definition at line 534 of file VrGliderComponent.h.

◆ lastSafeLandingPosition_

glm::vec3 Engine::Components::VrGlider::lastSafeLandingPosition_ { 0.0f, 10.0f, 0.0f }
private

Definition at line 532 of file VrGliderComponent.h.

◆ lastWindSample_

World::WindSample Engine::Components::VrGlider::lastWindSample_ {}
private

Definition at line 530 of file VrGliderComponent.h.

◆ MAX_SLIDE_ITERATIONS

int Engine::Components::VrGlider::MAX_SLIDE_ITERATIONS = 3
staticconstexprprivate

Definition at line 546 of file VrGliderComponent.h.

◆ physicsBody_

PhysicsBody* Engine::Components::VrGlider::physicsBody_ = nullptr
private

Definition at line 512 of file VrGliderComponent.h.

Referenced by getPhysicsBody().

◆ playerYaw_

float Engine::Components::VrGlider::playerYaw_ = 0.0f
private

Definition at line 537 of file VrGliderComponent.h.

◆ rightStickSnapTurnArmed_

bool Engine::Components::VrGlider::rightStickSnapTurnArmed_ = true
private

Definition at line 538 of file VrGliderComponent.h.

◆ SKIN_WIDTH

float Engine::Components::VrGlider::SKIN_WIDTH = 0.02f
staticconstexprprivate

Definition at line 545 of file VrGliderComponent.h.

◆ smoothedGroundY_

float Engine::Components::VrGlider::smoothedGroundY_ = 0.0f
private

Definition at line 541 of file VrGliderComponent.h.

◆ takeoffArmed_

bool Engine::Components::VrGlider::takeoffArmed_ = true
private

Definition at line 516 of file VrGliderComponent.h.

◆ velocity_

glm::vec3 Engine::Components::VrGlider::velocity_ { 0.0f }
private

Definition at line 518 of file VrGliderComponent.h.

Referenced by getSpeed(), and getVelocity().


The documentation for this class was generated from the following file: