diff --git a/Source/RWTHVRToolkit/Private/Pawn/ContinuousMovementComponent.cpp b/Source/RWTHVRToolkit/Private/Pawn/Navigation/ContinuousMovementComponent.cpp similarity index 97% rename from Source/RWTHVRToolkit/Private/Pawn/ContinuousMovementComponent.cpp rename to Source/RWTHVRToolkit/Private/Pawn/Navigation/ContinuousMovementComponent.cpp index 787b9c1ad43e5f9c2d9b8c8be0766d5482a2acc8..9843a1591f0d5e0caeae3982118dab71d13bbb6f 100644 --- a/Source/RWTHVRToolkit/Private/Pawn/ContinuousMovementComponent.cpp +++ b/Source/RWTHVRToolkit/Private/Pawn/Navigation/ContinuousMovementComponent.cpp @@ -1,6 +1,6 @@ // Fill out your copyright notice in the Description page of Project Settings. -#include "Pawn/ContinuousMovementComponent.h" +#include "Pawn/Navigation/ContinuousMovementComponent.h" #include "EnhancedInputComponent.h" #include "EnhancedInputSubsystems.h" diff --git a/Source/RWTHVRToolkit/Private/Pawn/MovementComponentBase.cpp b/Source/RWTHVRToolkit/Private/Pawn/Navigation/MovementComponentBase.cpp similarity index 98% rename from Source/RWTHVRToolkit/Private/Pawn/MovementComponentBase.cpp rename to Source/RWTHVRToolkit/Private/Pawn/Navigation/MovementComponentBase.cpp index 715cd955eba7667cf5a62c453f165f4b4da79ed7..2f8f319db6060a095c2a2d6b4971c84ad594f6cf 100644 --- a/Source/RWTHVRToolkit/Private/Pawn/MovementComponentBase.cpp +++ b/Source/RWTHVRToolkit/Private/Pawn/Navigation/MovementComponentBase.cpp @@ -1,7 +1,7 @@ // Fill out your copyright notice in the Description page of Project Settings. -#include "Pawn/MovementComponentBase.h" +#include "Pawn/Navigation/MovementComponentBase.h" #include "EnhancedInputComponent.h" #include "EnhancedInputSubsystems.h" diff --git a/Source/RWTHVRToolkit/Private/Pawn/TeleportationComponent.cpp b/Source/RWTHVRToolkit/Private/Pawn/Navigation/TeleportationComponent.cpp similarity index 99% rename from Source/RWTHVRToolkit/Private/Pawn/TeleportationComponent.cpp rename to Source/RWTHVRToolkit/Private/Pawn/Navigation/TeleportationComponent.cpp index c760b50cc1241568438c4e107a2c5b12929ebb49..667cd7b1ee486702c8f4ea4de0680cce079352ba 100644 --- a/Source/RWTHVRToolkit/Private/Pawn/TeleportationComponent.cpp +++ b/Source/RWTHVRToolkit/Private/Pawn/Navigation/TeleportationComponent.cpp @@ -1,7 +1,7 @@ // Fill out your copyright notice in the Description page of Project Settings. -#include "Pawn/TeleportationComponent.h" +#include "Pawn/Navigation/TeleportationComponent.h" #include "EnhancedInputComponent.h" #include "EnhancedInputSubsystems.h" diff --git a/Source/RWTHVRToolkit/Private/Pawn/VRPawnMovement.cpp b/Source/RWTHVRToolkit/Private/Pawn/VRPawnMovement.cpp index 4b4b81900ca5db47788fa3e6de8c4eafc7260492..5822f34aa7dad1e4466bdeac4a0342e8f92030ea 100644 --- a/Source/RWTHVRToolkit/Private/Pawn/VRPawnMovement.cpp +++ b/Source/RWTHVRToolkit/Private/Pawn/VRPawnMovement.cpp @@ -1,4 +1,4 @@ -#include "Pawn/VRPawnMovement.h" +#include "Pawn/Navigation/VRPawnMovement.h" #include "DrawDebugHelpers.h" #include "Kismet/KismetSystemLibrary.h" diff --git a/Source/RWTHVRToolkit/Private/Pawn/VirtualRealityPawn.cpp b/Source/RWTHVRToolkit/Private/Pawn/VirtualRealityPawn.cpp index 4ac07d8efcef2b83aae88b2d4fd6aeec97b2023b..77dc2be8361e9d6fceecbaa35bc53d92d34fa79c 100644 --- a/Source/RWTHVRToolkit/Private/Pawn/VirtualRealityPawn.cpp +++ b/Source/RWTHVRToolkit/Private/Pawn/VirtualRealityPawn.cpp @@ -10,11 +10,11 @@ #include "Core/RWTHVRPlayerState.h" #include "Kismet/GameplayStatics.h" #include "Logging/StructuredLog.h" -#include "Pawn/ContinuousMovementComponent.h" +#include "Pawn/InputExtensionInterface.h" +#include "Pawn/Navigation/VRPawnMovement.h" #include "Pawn/ReplicatedCameraComponent.h" #include "Pawn/ReplicatedMotionControllerComponent.h" #include "Pawn/VRPawnInputConfig.h" -#include "Pawn/VRPawnMovement.h" #include "Roles/LiveLinkTransformTypes.h" #include "Utility/VirtualRealityUtilities.h" diff --git a/Source/RWTHVRToolkit/Public/Pawn/ContinuousMovementComponent.h b/Source/RWTHVRToolkit/Public/Pawn/Navigation/ContinuousMovementComponent.h similarity index 97% rename from Source/RWTHVRToolkit/Public/Pawn/ContinuousMovementComponent.h rename to Source/RWTHVRToolkit/Public/Pawn/Navigation/ContinuousMovementComponent.h index 0c1daf2fae9e03636e94c017acc2cb06eb68a545..6f7d801468443b983b3fabab7a851517dd7ee462 100644 --- a/Source/RWTHVRToolkit/Public/Pawn/ContinuousMovementComponent.h +++ b/Source/RWTHVRToolkit/Public/Pawn/Navigation/ContinuousMovementComponent.h @@ -4,7 +4,7 @@ #include "CoreMinimal.h" #include "Pawn/VirtualRealityPawn.h" -#include "Pawn/MovementComponentBase.h" +#include "Pawn/Navigation/MovementComponentBase.h" #include "Components/ActorComponent.h" #include "ContinuousMovementComponent.generated.h" diff --git a/Source/RWTHVRToolkit/Private/Pawn/MovementComponentBase.h b/Source/RWTHVRToolkit/Public/Pawn/Navigation/MovementComponentBase.h similarity index 100% rename from Source/RWTHVRToolkit/Private/Pawn/MovementComponentBase.h rename to Source/RWTHVRToolkit/Public/Pawn/Navigation/MovementComponentBase.h diff --git a/Source/RWTHVRToolkit/Public/Pawn/TeleportationComponent.h b/Source/RWTHVRToolkit/Public/Pawn/Navigation/TeleportationComponent.h similarity index 98% rename from Source/RWTHVRToolkit/Public/Pawn/TeleportationComponent.h rename to Source/RWTHVRToolkit/Public/Pawn/Navigation/TeleportationComponent.h index 9946ed94f30691d481bba8c6649bde703d56574c..2f07fef51eb2a83e33c0e7ce32d138ee3224734d 100644 --- a/Source/RWTHVRToolkit/Public/Pawn/TeleportationComponent.h +++ b/Source/RWTHVRToolkit/Public/Pawn/Navigation/TeleportationComponent.h @@ -7,7 +7,7 @@ #include "Pawn/VirtualRealityPawn.h" #include "NiagaraComponent.h" #include "Kismet/GameplayStaticsTypes.h" -#include "Pawn/MovementComponentBase.h" +#include "Pawn/Navigation/MovementComponentBase.h" #include "TeleportationComponent.generated.h" diff --git a/Source/RWTHVRToolkit/Public/Pawn/VRPawnMovement.h b/Source/RWTHVRToolkit/Public/Pawn/Navigation/VRPawnMovement.h similarity index 97% rename from Source/RWTHVRToolkit/Public/Pawn/VRPawnMovement.h rename to Source/RWTHVRToolkit/Public/Pawn/Navigation/VRPawnMovement.h index 31ae483a88343dfb029b04e06bf3c6ef589f49aa..63dc5b0e0065df7644253db43fe88983daf3c359 100644 --- a/Source/RWTHVRToolkit/Public/Pawn/VRPawnMovement.h +++ b/Source/RWTHVRToolkit/Public/Pawn/Navigation/VRPawnMovement.h @@ -1,87 +1,87 @@ -#pragma once - -#include "CoreMinimal.h" -#include "GameFramework/FloatingPawnMovement.h" -#include "Components/CapsuleComponent.h" - -#include "VRPawnMovement.generated.h" - -/* - * This Movement component is needed since in VR not only the pawn itself (UpdatedComponent) is moved but also the - * user herself can walk and thereby move the CameraComponent, which can also lead to collisions or e.g. going up steps - * - * The four modes are: - * None: No controller movement is applied and no corrections regarding steps or collisions with walls are done - * Ghost: The same as above but now the Inputs can be used for unconstrained flying (also through objects) - * Fly: The user can fly but not through walls etc. When the user walks against a wall the scene is moved with her to avoid walking through - * The user can also walk up stairs with a maximum step height of MaxStepHeight - * Walk: Additionally to Fly now gravity keeps the user on the floor - */ - -UENUM(BlueprintType) -enum class EVRNavigationModes : uint8 -{ - NAV_NONE UMETA(DisplayName = "None (no controller movement)"), - NAV_GHOST UMETA(DisplayName = "Ghost (flying, also through walls)"), - NAV_FLY UMETA(DisplayName = "Fly (prohibiting collisions)"), - NAV_WALK UMETA(DisplayName = "Walk (gravity and prohibiting collisions)") -}; - -UCLASS() -class RWTHVRTOOLKIT_API UVRPawnMovement : public UFloatingPawnMovement -{ - GENERATED_UCLASS_BODY() - -public: - virtual void BeginPlay() override; - void CheckAndRevertCollisionSinceLastTick(); - - void MoveOutOfNewDynamicCollisions(); - virtual void TickComponent(float DeltaTime, enum ELevelTick TickType, - FActorComponentTickFunction* ThisTickFunction) override; - - void SetHeadComponent(USceneComponent* NewHeadComponent); - - UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VR Movement") - EVRNavigationModes NavigationMode = EVRNavigationModes::NAV_WALK; - - UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VR Movement", meta = (ClampMin="0.0")) - float MaxStepHeight = 40.0f; - - // if the height that the pawn would fall (in walking mode) is higher - // it is not falling, set to <0.0f if you want to fall infinitely - UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VR Movement") - float MaxFallingDepth = 1000.0f; - - UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VR Movement", meta = (ClampMax="0.0")) - float GravityAcceleration = -981.0f; - - UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VR Movement", meta = (ClampMin="0.0")) - float UpSteppingAcceleration = 981.0f; - - UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VR Movement", meta = (ClampMin="0.0")) - float CapsuleRadius = 40.0f; - -private: - //check for - FHitResult CreateCapsuleTrace(const FVector& Start, const FVector& End, bool DrawDebug = false) const; - FVector GetOverlapResolveDirection(); - void SetCapsuleColliderToUserSize() const; - void CheckForPhysWalkingCollision(); - FVector GetCollisionSafeVirtualSteeringVec(FVector InputVector, float DeltaTime); - void MoveByGravityOrStepUp(float DeltaSeconds); - void ShiftVertically(float Distance, float VerticalAcceleration, float DeltaSeconds); - - UPROPERTY(VisibleAnywhere) - UCapsuleComponent* CapsuleColliderComponent = nullptr; - UPROPERTY() - USceneComponent* HeadComponent = nullptr; - - float VerticalSpeed = 0.0f; - FVector LastCollisionFreeCapsulePosition; - FVector LastSteeringCollisionVector; - - //just stored for performance gains; - UPROPERTY() - TArray<AActor*> ActorsToIgnore; -}; +#pragma once + +#include "CoreMinimal.h" +#include "GameFramework/FloatingPawnMovement.h" +#include "Components/CapsuleComponent.h" + +#include "VRPawnMovement.generated.h" + +/* + * This Movement component is needed since in VR not only the pawn itself (UpdatedComponent) is moved but also the + * user herself can walk and thereby move the CameraComponent, which can also lead to collisions or e.g. going up steps + * + * The four modes are: + * None: No controller movement is applied and no corrections regarding steps or collisions with walls are done + * Ghost: The same as above but now the Inputs can be used for unconstrained flying (also through objects) + * Fly: The user can fly but not through walls etc. When the user walks against a wall the scene is moved with her to avoid walking through + * The user can also walk up stairs with a maximum step height of MaxStepHeight + * Walk: Additionally to Fly now gravity keeps the user on the floor + */ + +UENUM(BlueprintType) +enum class EVRNavigationModes : uint8 +{ + NAV_NONE UMETA(DisplayName = "None (no controller movement)"), + NAV_GHOST UMETA(DisplayName = "Ghost (flying, also through walls)"), + NAV_FLY UMETA(DisplayName = "Fly (prohibiting collisions)"), + NAV_WALK UMETA(DisplayName = "Walk (gravity and prohibiting collisions)") +}; + +UCLASS() +class RWTHVRTOOLKIT_API UVRPawnMovement : public UFloatingPawnMovement +{ + GENERATED_UCLASS_BODY() + +public: + virtual void BeginPlay() override; + void CheckAndRevertCollisionSinceLastTick(); + + void MoveOutOfNewDynamicCollisions(); + virtual void TickComponent(float DeltaTime, enum ELevelTick TickType, + FActorComponentTickFunction* ThisTickFunction) override; + + void SetHeadComponent(USceneComponent* NewHeadComponent); + + UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VR Movement") + EVRNavigationModes NavigationMode = EVRNavigationModes::NAV_WALK; + + UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VR Movement", meta = (ClampMin="0.0")) + float MaxStepHeight = 40.0f; + + // if the height that the pawn would fall (in walking mode) is higher + // it is not falling, set to <0.0f if you want to fall infinitely + UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VR Movement") + float MaxFallingDepth = 1000.0f; + + UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VR Movement", meta = (ClampMax="0.0")) + float GravityAcceleration = -981.0f; + + UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VR Movement", meta = (ClampMin="0.0")) + float UpSteppingAcceleration = 981.0f; + + UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VR Movement", meta = (ClampMin="0.0")) + float CapsuleRadius = 40.0f; + +private: + //check for + FHitResult CreateCapsuleTrace(const FVector& Start, const FVector& End, bool DrawDebug = false) const; + FVector GetOverlapResolveDirection(); + void SetCapsuleColliderToUserSize() const; + void CheckForPhysWalkingCollision(); + FVector GetCollisionSafeVirtualSteeringVec(FVector InputVector, float DeltaTime); + void MoveByGravityOrStepUp(float DeltaSeconds); + void ShiftVertically(float Distance, float VerticalAcceleration, float DeltaSeconds); + + UPROPERTY(VisibleAnywhere) + UCapsuleComponent* CapsuleColliderComponent = nullptr; + UPROPERTY() + USceneComponent* HeadComponent = nullptr; + + float VerticalSpeed = 0.0f; + FVector LastCollisionFreeCapsulePosition; + FVector LastSteeringCollisionVector; + + //just stored for performance gains; + UPROPERTY() + TArray<AActor*> ActorsToIgnore; +}; diff --git a/Source/RWTHVRToolkit/Public/Pawn/VirtualRealityPawn.h b/Source/RWTHVRToolkit/Public/Pawn/VirtualRealityPawn.h index 9238d465709831c05e9f014710a5738e5e532b32..4d057835592305af944b398f790b84394d7d7f24 100644 --- a/Source/RWTHVRToolkit/Public/Pawn/VirtualRealityPawn.h +++ b/Source/RWTHVRToolkit/Public/Pawn/VirtualRealityPawn.h @@ -5,7 +5,7 @@ #include "BasicVRInteractionComponent.h" #include "CoreMinimal.h" #include "LiveLinkRole.h" -#include "Pawn/VRPawnMovement.h" +#include "Pawn/Navigation/VRPawnMovement.h" #include "VirtualRealityPawn.generated.h" class UInputMappingContext;