Skip to content
Snippets Groups Projects
Commit 62366312 authored by David Gilbert's avatar David Gilbert :bug:
Browse files

Huge reformatting / cosmetic fixes commit.

parent ce188108
Branches
No related tags found
1 merge request!36Huge reformatting / cosmetic fixes commit.
Showing
with 218 additions and 370 deletions
...@@ -33,4 +33,3 @@ void FCAVEOverlay::OnSessionStart(UWorld* World, const UWorld::InitializationVal ...@@ -33,4 +33,3 @@ void FCAVEOverlay::OnSessionStart(UWorld* World, const UWorld::InitializationVal
World->SpawnActor(ACAVEOverlayController::StaticClass()); World->SpawnActor(ACAVEOverlayController::StaticClass());
} }
} }
#include "CAVEOverlay/CAVEOverlayController.h" #include "CAVEOverlay/CAVEOverlayController.h"
#include "CoreMinimal.h" #include "CoreMinimal.h"
#include "CAVEOverlay/DoorOverlayData.h"
#include "IDisplayCluster.h" #include "IDisplayCluster.h"
#include "IXRTrackingSystem.h" #include "CAVEOverlay/DoorOverlayData.h"
#include "Cluster/IDisplayClusterClusterManager.h" #include "Cluster/IDisplayClusterClusterManager.h"
#include "Game/IDisplayClusterGameManager.h"
#include "UObject/ConstructorHelpers.h"
#include "Components/StaticMeshComponent.h" #include "Components/StaticMeshComponent.h"
#include "Materials/MaterialInstanceDynamic.h"
#include "Engine/CollisionProfile.h" #include "Engine/CollisionProfile.h"
#include "Materials/MaterialInstanceDynamic.h"
#include "UObject/ConstructorHelpers.h"
#include "Utility/VirtualRealityUtilities.h" #include "Utility/VirtualRealityUtilities.h"
DEFINE_LOG_CATEGORY(LogCAVEOverlay); DEFINE_LOG_CATEGORY(LogCAVEOverlay);
...@@ -22,7 +20,8 @@ bool ContainsFString(const TArray<FString>& Array, const FString& Entry) ...@@ -22,7 +20,8 @@ bool ContainsFString(const TArray<FString>& Array, const FString& Entry)
return false; return false;
} }
UStaticMeshComponent* ACAVEOverlayController::CreateMeshComponent(const FName& Name, UStaticMesh* Mesh, USceneComponent* Parent) UStaticMeshComponent* ACAVEOverlayController::CreateMeshComponent(const FName& Name, UStaticMesh* Mesh,
USceneComponent* Parent)
{ {
UStaticMeshComponent* Result = CreateDefaultSubobject<UStaticMeshComponent>(Name); UStaticMeshComponent* Result = CreateDefaultSubobject<UStaticMeshComponent>(Name);
Result->SetStaticMesh(Mesh); Result->SetStaticMesh(Mesh);
...@@ -40,7 +39,8 @@ ACAVEOverlayController::ACAVEOverlayController() ...@@ -40,7 +39,8 @@ ACAVEOverlayController::ACAVEOverlayController()
bAllowTickBeforeBeginPlay = false; bAllowTickBeforeBeginPlay = false;
AutoReceiveInput = EAutoReceiveInput::Player0; AutoReceiveInput = EAutoReceiveInput::Player0;
ConstructorHelpers::FClassFinder<UDoorOverlayData> WidgetClassFinder(TEXT("Blueprint'/RWTHVRToolkit/CAVEOverlay/DoorOverlay'")); ConstructorHelpers::FClassFinder<UDoorOverlayData> WidgetClassFinder(
TEXT("Blueprint'/RWTHVRToolkit/CAVEOverlay/DoorOverlay'"));
if (WidgetClassFinder.Succeeded()) if (WidgetClassFinder.Succeeded())
{ {
OverlayClass = WidgetClassFinder.Class; OverlayClass = WidgetClassFinder.Class;
...@@ -133,7 +133,8 @@ void ACAVEOverlayController::CycleDoorType() ...@@ -133,7 +133,8 @@ void ACAVEOverlayController::CycleDoorType()
void ACAVEOverlayController::HandleClusterEvent(const FDisplayClusterClusterEventJson& Event) void ACAVEOverlayController::HandleClusterEvent(const FDisplayClusterClusterEventJson& Event)
{ {
if (Event.Category.Equals("CAVEOverlay") && Event.Type.Equals("DoorChange") && Event.Parameters.Contains("NewDoorState")) if (Event.Category.Equals("CAVEOverlay") && Event.Type.Equals("DoorChange") && Event.Parameters.Contains(
"NewDoorState"))
{ {
SetDoorMode(static_cast<EDoorMode>(FCString::Atoi(*Event.Parameters["NewDoorState"]))); SetDoorMode(static_cast<EDoorMode>(FCString::Atoi(*Event.Parameters["NewDoorState"])));
} }
...@@ -148,7 +149,8 @@ void ACAVEOverlayController::SetDoorMode(EDoorMode NewMode) ...@@ -148,7 +149,8 @@ void ACAVEOverlayController::SetDoorMode(EDoorMode NewMode)
case EDoorMode::DOOR_PARTIALLY_OPEN: case EDoorMode::DOOR_PARTIALLY_OPEN:
DoorCurrentOpeningWidthAbsolute = DoorOpeningWidthAbsolute; DoorCurrentOpeningWidthAbsolute = DoorOpeningWidthAbsolute;
if (ScreenType == SCREEN_DOOR) Overlay->BlackBox->SetRenderScale(FVector2D(0, 1)); if (ScreenType == SCREEN_DOOR) Overlay->BlackBox->SetRenderScale(FVector2D(0, 1));
if (ScreenType == SCREEN_DOOR_PARTIAL) Overlay->BlackBox->SetRenderScale(FVector2D(DoorOpeningWidthRelative, 1)); if (ScreenType == SCREEN_DOOR_PARTIAL) Overlay->BlackBox->
SetRenderScale(FVector2D(DoorOpeningWidthRelative, 1));
if (ScreenType == SCREEN_MASTER) Overlay->BlackBox->SetRenderScale(FVector2D(0, 1)); if (ScreenType == SCREEN_MASTER) Overlay->BlackBox->SetRenderScale(FVector2D(0, 1));
Overlay->BlackBox->SetVisibility(ESlateVisibility::Visible); Overlay->BlackBox->SetVisibility(ESlateVisibility::Visible);
break; break;
...@@ -170,7 +172,8 @@ void ACAVEOverlayController::SetDoorMode(EDoorMode NewMode) ...@@ -170,7 +172,8 @@ void ACAVEOverlayController::SetDoorMode(EDoorMode NewMode)
} }
if (ScreenType == SCREEN_NORMAL) Overlay->BlackBox->SetRenderScale(FVector2D(0, 1)); //no overlay if (ScreenType == SCREEN_NORMAL) Overlay->BlackBox->SetRenderScale(FVector2D(0, 1)); //no overlay
UE_LOG(LogCAVEOverlay, Log, TEXT("Switched door state to '%s'. New opening width is %f."), *DoorModeNames[DoorCurrentMode], DoorCurrentOpeningWidthAbsolute); UE_LOG(LogCAVEOverlay, Log, TEXT("Switched door state to '%s'. New opening width is %f."),
*DoorModeNames[DoorCurrentMode], DoorCurrentOpeningWidthAbsolute);
if (ScreenType == SCREEN_MASTER) if (ScreenType == SCREEN_MASTER)
{ {
...@@ -192,7 +195,8 @@ void ACAVEOverlayController::BeginPlay() ...@@ -192,7 +195,8 @@ void ACAVEOverlayController::BeginPlay()
IDisplayClusterClusterManager* ClusterManager = IDisplayCluster::Get().GetClusterMgr(); IDisplayClusterClusterManager* ClusterManager = IDisplayCluster::Get().GetClusterMgr();
if (ClusterManager && !ClusterEventListenerDelegate.IsBound()) if (ClusterManager && !ClusterEventListenerDelegate.IsBound())
{ {
ClusterEventListenerDelegate = FOnClusterEventJsonListener::CreateUObject(this, &ACAVEOverlayController::HandleClusterEvent); ClusterEventListenerDelegate = FOnClusterEventJsonListener::CreateUObject(
this, &ACAVEOverlayController::HandleClusterEvent);
ClusterManager->AddClusterEventJsonListener(ClusterEventListenerDelegate); ClusterManager->AddClusterEventJsonListener(ClusterEventListenerDelegate);
} }
...@@ -217,7 +221,8 @@ void ACAVEOverlayController::BeginPlay() ...@@ -217,7 +221,8 @@ void ACAVEOverlayController::BeginPlay()
Overlay = CreateWidget<UDoorOverlayData>(GetWorld()->GetFirstPlayerController(), OverlayClass); Overlay = CreateWidget<UDoorOverlayData>(GetWorld()->GetFirstPlayerController(), OverlayClass);
Overlay->AddToViewport(0); Overlay->AddToViewport(0);
SetDoorMode(DoorCurrentMode); SetDoorMode(DoorCurrentMode);
Overlay->CornerText->SetText(FText::FromString("")); //Set Text to "" until someone presses the key for the first time Overlay->CornerText->SetText(FText::FromString(""));
//Set Text to "" until someone presses the key for the first time
if (!bAttachedToCAVEOrigin && CaveOrigin) if (!bAttachedToCAVEOrigin && CaveOrigin)
{ {
...@@ -237,7 +242,7 @@ void ACAVEOverlayController::EndPlay(const EEndPlayReason::Type EndPlayReason) ...@@ -237,7 +242,7 @@ void ACAVEOverlayController::EndPlay(const EEndPlayReason::Type EndPlayReason)
Super::EndPlay(EndPlayReason); Super::EndPlay(EndPlayReason);
} }
float ACAVEOverlayController::CalculateOpacityFromPosition(FVector Position) const float ACAVEOverlayController::CalculateOpacityFromPosition(const FVector& Position) const
{ {
return FMath::Max( return FMath::Max(
FMath::Clamp((FMath::Abs(Position.X) - (WallDistance - WallCloseDistance)) / WallFadeDistance, 0.0f, 1.0f), FMath::Clamp((FMath::Abs(Position.X) - (WallDistance - WallCloseDistance)) / WallFadeDistance, 0.0f, 1.0f),
...@@ -245,10 +250,12 @@ float ACAVEOverlayController::CalculateOpacityFromPosition(FVector Position) con ...@@ -245,10 +250,12 @@ float ACAVEOverlayController::CalculateOpacityFromPosition(FVector Position) con
); );
} }
bool ACAVEOverlayController::PositionInDoorOpening(FVector Position) const bool ACAVEOverlayController::PositionInDoorOpening(const FVector& Position) const
{ {
return FMath::IsWithinInclusive(-Position.X, WallDistance + 10 - 20 - WallCloseDistance, WallDistance + 10) //Overlap both sides 10cm return FMath::IsWithinInclusive(-Position.X, WallDistance + 10 - 20 - WallCloseDistance, WallDistance + 10)
&& FMath::IsWithinInclusive(-Position.Y, WallDistance + 10 - DoorCurrentOpeningWidthAbsolute, WallDistance + 10); //Overlap one side 10cm //Overlap both sides 10cm
&& FMath::IsWithinInclusive(-Position.Y, WallDistance + 10 - DoorCurrentOpeningWidthAbsolute,
WallDistance + 10); //Overlap one side 10cm
} }
// Called every frame // Called every frame
...@@ -272,7 +279,8 @@ void ACAVEOverlayController::Tick(float DeltaTime) ...@@ -272,7 +279,8 @@ void ACAVEOverlayController::Tick(float DeltaTime)
//FPS Counter //FPS Counter
if (Overlay) if (Overlay)
{ {
if (DoorCurrentMode == EDoorMode::DOOR_DEBUG && ContainsFString(ScreensFPS, IDisplayCluster::Get().GetClusterMgr()->GetNodeId())) if (DoorCurrentMode == EDoorMode::DOOR_DEBUG && ContainsFString(
ScreensFPS, IDisplayCluster::Get().GetClusterMgr()->GetNodeId()))
{ {
Overlay->FPS->SetText(FText::FromString(FString::Printf(TEXT("FPS: %.1f"), 1.0f / DeltaTime))); Overlay->FPS->SetText(FText::FromString(FString::Printf(TEXT("FPS: %.1f"), 1.0f / DeltaTime)));
} }
...@@ -291,7 +299,8 @@ void ACAVEOverlayController::Tick(float DeltaTime) ...@@ -291,7 +299,8 @@ void ACAVEOverlayController::Tick(float DeltaTime)
//Head/Tape Logic //Head/Tape Logic
const FVector ShutterPosition = Head->GetComponentLocation() - CaveOrigin->GetComponentLocation(); const FVector ShutterPosition = Head->GetComponentLocation() - CaveOrigin->GetComponentLocation();
const bool bHeadIsCloseToWall = FMath::IsWithinInclusive(ShutterPosition.GetAbsMax(), WallDistance - WallCloseDistance, WallDistance); const bool bHeadIsCloseToWall = FMath::IsWithinInclusive(ShutterPosition.GetAbsMax(),
WallDistance - WallCloseDistance, WallDistance);
if (bHeadIsCloseToWall && !PositionInDoorOpening(ShutterPosition)) if (bHeadIsCloseToWall && !PositionInDoorOpening(ShutterPosition))
{ {
...@@ -330,10 +339,14 @@ void ACAVEOverlayController::Tick(float DeltaTime) ...@@ -330,10 +339,14 @@ void ACAVEOverlayController::Tick(float DeltaTime)
SignPositiveX->SetRelativeLocation(FVector(+WallDistance, FlystickPosition.Y, FlystickPosition.Z)); SignPositiveX->SetRelativeLocation(FVector(+WallDistance, FlystickPosition.Y, FlystickPosition.Z));
SignPositiveY->SetRelativeLocation(FVector(FlystickPosition.X, +WallDistance, FlystickPosition.Z)); SignPositiveY->SetRelativeLocation(FVector(FlystickPosition.X, +WallDistance, FlystickPosition.Z));
SignNegativeX->SetVisibility(FMath::IsWithin(-FlystickPosition.X, WallDistance - WallCloseDistance, WallDistance) && !bFlystickInDoor); SignNegativeX->SetVisibility(
SignNegativeY->SetVisibility(FMath::IsWithin(-FlystickPosition.Y, WallDistance - WallCloseDistance, WallDistance) && !bFlystickInDoor); FMath::IsWithin(-FlystickPosition.X, WallDistance - WallCloseDistance, WallDistance) && !bFlystickInDoor);
SignPositiveX->SetVisibility(FMath::IsWithin(+FlystickPosition.X, WallDistance - WallCloseDistance, WallDistance) && !bFlystickInDoor); SignNegativeY->SetVisibility(
SignPositiveY->SetVisibility(FMath::IsWithin(+FlystickPosition.Y, WallDistance - WallCloseDistance, WallDistance) && !bFlystickInDoor); FMath::IsWithin(-FlystickPosition.Y, WallDistance - WallCloseDistance, WallDistance) && !bFlystickInDoor);
SignPositiveX->SetVisibility(
FMath::IsWithin(+FlystickPosition.X, WallDistance - WallCloseDistance, WallDistance) && !bFlystickInDoor);
SignPositiveY->SetVisibility(
FMath::IsWithin(+FlystickPosition.Y, WallDistance - WallCloseDistance, WallDistance) && !bFlystickInDoor);
SignMaterialDynamic->SetScalarParameterValue("SignOpacity", CalculateOpacityFromPosition(FlystickPosition)); SignMaterialDynamic->SetScalarParameterValue("SignOpacity", CalculateOpacityFromPosition(FlystickPosition));
} }
......
...@@ -5,7 +5,9 @@ ...@@ -5,7 +5,9 @@
void FClusterConsole::Register() void FClusterConsole::Register()
{ {
/* Registering console command */ /* Registering console command */
ClusterConsoleCommand = IConsoleManager::Get().RegisterConsoleCommand(TEXT("ClusterExecute"), TEXT("<Your Command> - Execute commands on every node of the nDisplay cluster by prepending ClusterExecute"), ClusterConsoleCommand = IConsoleManager::Get().RegisterConsoleCommand(
TEXT("ClusterExecute"),
TEXT("<Your Command> - Execute commands on every node of the nDisplay cluster by prepending ClusterExecute"),
FConsoleCommandWithArgsDelegate::CreateLambda([](const TArray<FString>& Args) FConsoleCommandWithArgsDelegate::CreateLambda([](const TArray<FString>& Args)
{ {
if (IDisplayCluster::Get().GetClusterMgr() == nullptr || Args.Num() == 0) return; if (IDisplayCluster::Get().GetClusterMgr() == nullptr || Args.Num() == 0) return;
...@@ -21,10 +23,11 @@ void FClusterConsole::Register() ...@@ -21,10 +23,11 @@ void FClusterConsole::Register()
})); }));
/* Register cluster event handling */ /* Register cluster event handling */
IDisplayCluster* DisplayCluster = FModuleManager::LoadModulePtr<IDisplayCluster>(IDisplayCluster::ModuleName); const IDisplayCluster* DisplayCluster = FModuleManager::LoadModulePtr<IDisplayCluster>(IDisplayCluster::ModuleName);
if (DisplayCluster && !ClusterEventListenerDelegate.IsBound()) if (DisplayCluster && !ClusterEventListenerDelegate.IsBound())
{ {
ClusterEventListenerDelegate = FOnClusterEventJsonListener::CreateLambda([](const FDisplayClusterClusterEventJson& Event) ClusterEventListenerDelegate = FOnClusterEventJsonListener::CreateLambda(
[](const FDisplayClusterClusterEventJson& Event)
{ {
/* Actual handling */ /* Actual handling */
if (Event.Category.Equals("NDisplayClusterExecute") && Event.Parameters.Contains("Command") && GEngine) if (Event.Category.Equals("NDisplayClusterExecute") && Event.Parameters.Contains("Command") && GEngine)
...@@ -36,9 +39,8 @@ void FClusterConsole::Register() ...@@ -36,9 +39,8 @@ void FClusterConsole::Register()
} }
} }
void FClusterConsole::Unregister() void FClusterConsole::Unregister() const
{ {
IConsoleManager::Get().UnregisterConsoleObject(ClusterConsoleCommand); IConsoleManager::Get().UnregisterConsoleObject(ClusterConsoleCommand);
IDisplayCluster::Get().GetClusterMgr()->RemoveClusterEventJsonListener(ClusterEventListenerDelegate); IDisplayCluster::Get().GetClusterMgr()->RemoveClusterEventJsonListener(ClusterEventListenerDelegate);
} }
...@@ -7,6 +7,7 @@ void FRWTHVRClusterModule::StartupModule () ...@@ -7,6 +7,7 @@ void FRWTHVRClusterModule::StartupModule ()
ClusterConsole.Register(); ClusterConsole.Register();
CAVEOverlay.Register(); CAVEOverlay.Register();
} }
void FRWTHVRClusterModule::ShutdownModule() void FRWTHVRClusterModule::ShutdownModule()
{ {
ClusterConsole.Unregister(); ClusterConsole.Unregister();
......
...@@ -56,8 +56,8 @@ private: ...@@ -56,8 +56,8 @@ private:
UStaticMeshComponent* CreateMeshComponent(const FName& Name, UStaticMesh* Mesh, USceneComponent* Parent); UStaticMeshComponent* CreateMeshComponent(const FName& Name, UStaticMesh* Mesh, USceneComponent* Parent);
UPROPERTY() UMaterial* TapeMaterial = nullptr; UPROPERTY() UMaterial* TapeMaterial = nullptr;
UPROPERTY() UMaterial* SignMaterial = nullptr; UPROPERTY() UMaterial* SignMaterial = nullptr;
float CalculateOpacityFromPosition(FVector Position) const; float CalculateOpacityFromPosition(const FVector& Position) const;
bool PositionInDoorOpening(FVector Position) const; bool PositionInDoorOpening(const FVector& Position) const;
//Pawn Components //Pawn Components
bool bAttachedToCAVEOrigin = false; bool bAttachedToCAVEOrigin = false;
......
...@@ -22,5 +22,5 @@ private: ...@@ -22,5 +22,5 @@ private:
public: public:
void Register(); void Register();
void Unregister(); void Unregister() const;
}; };
...@@ -3,7 +3,8 @@ ...@@ -3,7 +3,8 @@
void FActivateConsoleInShipping::Register() void FActivateConsoleInShipping::Register()
{ {
if(FApp::GetBuildConfiguration() != EBuildConfiguration::Shipping) return; /* Should only enable console in shipping */ if (FApp::GetBuildConfiguration() != EBuildConfiguration::Shipping) return;
/* Should only enable console in shipping */
On_Post_World_Initialization_Delegate.BindRaw(this, &FActivateConsoleInShipping::OnSessionStart); On_Post_World_Initialization_Delegate.BindRaw(this, &FActivateConsoleInShipping::OnSessionStart);
StartHandle = FWorldDelegates::OnPostWorldInitialization.Add(On_Post_World_Initialization_Delegate); StartHandle = FWorldDelegates::OnPostWorldInitialization.Add(On_Post_World_Initialization_Delegate);
...@@ -18,7 +19,8 @@ void FActivateConsoleInShipping::Unregister() const ...@@ -18,7 +19,8 @@ void FActivateConsoleInShipping::Unregister() const
void FActivateConsoleInShipping::OnSessionStart(UWorld* World, const UWorld::InitializationValues Values) const void FActivateConsoleInShipping::OnSessionStart(UWorld* World, const UWorld::InitializationValues Values) const
{ {
if(!World->IsGameWorld() || !World->GetGameViewport() || World->GetGameViewport()->ViewportConsole != nullptr) return; if (!World->IsGameWorld() || !World->GetGameViewport() || World->GetGameViewport()->ViewportConsole != nullptr)
return;
World->GetGameViewport()->ViewportConsole = NewObject<UConsole>(World->GetGameViewport()); World->GetGameViewport()->ViewportConsole = NewObject<UConsole>(World->GetGameViewport());
} }
...@@ -11,12 +11,10 @@ UClickBehaviour::UClickBehaviour() ...@@ -11,12 +11,10 @@ UClickBehaviour::UClickBehaviour()
void UClickBehaviour::OnClickStart(USceneComponent* TriggeredComponent, const FInputActionValue& Value) void UClickBehaviour::OnClickStart(USceneComponent* TriggeredComponent, const FInputActionValue& Value)
{ {
} }
void UClickBehaviour::OnClickEnd(USceneComponent* TriggeredComponent, const FInputActionValue& Value) void UClickBehaviour::OnClickEnd(USceneComponent* TriggeredComponent, const FInputActionValue& Value)
{ {
} }
void UClickBehaviour::BeginPlay() void UClickBehaviour::BeginPlay()
...@@ -27,10 +25,8 @@ void UClickBehaviour::BeginPlay() ...@@ -27,10 +25,8 @@ void UClickBehaviour::BeginPlay()
OnClickEndEvent.AddDynamic(this, &UClickBehaviour::OnClickEnd); OnClickEndEvent.AddDynamic(this, &UClickBehaviour::OnClickEnd);
} }
// Called every frame // Called every frame
void UClickBehaviour::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) void UClickBehaviour::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
{ {
Super::TickComponent(DeltaTime, TickType, ThisTickFunction); Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
} }
// Fill out your copyright notice in the Description page of Project Settings.
#include "Interaction/Clickable.h"
UClickable::UClickable(const FObjectInitializer& ObjectInitializer)
:Super(ObjectInitializer)
{}
...@@ -8,7 +8,6 @@ ...@@ -8,7 +8,6 @@
#include "Interaction/GrabbableComponent.h" #include "Interaction/GrabbableComponent.h"
#include "Kismet/GameplayStatics.h" #include "Kismet/GameplayStatics.h"
#include "Utility/VirtualRealityUtilities.h"
// Sets default values for this component's properties // Sets default values for this component's properties
UGrabComponent::UGrabComponent() UGrabComponent::UGrabComponent()
...@@ -34,7 +33,8 @@ void UGrabComponent::TickComponent(float DeltaTime, ELevelTick TickType, FActorC ...@@ -34,7 +33,8 @@ void UGrabComponent::TickComponent(float DeltaTime, ELevelTick TickType, FActorC
auto DebugTrace = bShowDebugTrace ? EDrawDebugTrace::ForOneFrame : EDrawDebugTrace::None; auto DebugTrace = bShowDebugTrace ? EDrawDebugTrace::ForOneFrame : EDrawDebugTrace::None;
UKismetSystemLibrary::SphereTraceMulti(GetWorld(), GetAttachParent()->GetComponentLocation(), UKismetSystemLibrary::SphereTraceMulti(GetWorld(), GetAttachParent()->GetComponentLocation(),
GetAttachParent()->GetComponentLocation(),GrabSphereRadius,TraceType,true,ActorsToIgnore,DebugTrace, GetAttachParent()->GetComponentLocation(), GrabSphereRadius, TraceType, true,
ActorsToIgnore, DebugTrace,
OutHits, true, FColor::Green); OutHits, true, FColor::Green);
for (FHitResult Hit : OutHits) for (FHitResult Hit : OutHits)
...@@ -61,7 +61,6 @@ void UGrabComponent::TickComponent(float DeltaTime, ELevelTick TickType, FActorC ...@@ -61,7 +61,6 @@ void UGrabComponent::TickComponent(float DeltaTime, ELevelTick TickType, FActorC
PreviousGrabbablesInRange.Add(CurrentGrabbale); PreviousGrabbablesInRange.Add(CurrentGrabbale);
CurrentGrabbale->HandleOnHoverStartEvents(this); CurrentGrabbale->HandleOnHoverStartEvents(this);
} }
} }
TArray<UGrabbableComponent*> ComponentsToRemove; TArray<UGrabbableComponent*> ComponentsToRemove;
...@@ -82,24 +81,18 @@ void UGrabComponent::TickComponent(float DeltaTime, ELevelTick TickType, FActorC ...@@ -82,24 +81,18 @@ void UGrabComponent::TickComponent(float DeltaTime, ELevelTick TickType, FActorC
} }
} }
// Called when the game starts void UGrabComponent::SetupPlayerInput(UInputComponent* PlayerInputComponent)
void UGrabComponent::BeginPlay()
{ {
Super::BeginPlay(); IInputExtensionInterface::SetupPlayerInput(PlayerInputComponent);
SetupInputActions();
// ...
}
void UGrabComponent::SetupInputActions()
{
const APawn* Pawn = Cast<APawn>(GetOwner()); const APawn* Pawn = Cast<APawn>(GetOwner());
const APlayerController* PlayerController = Cast<APlayerController>(Pawn->GetController()); if (!Pawn)
const ULocalPlayer* LP = PlayerController ? PlayerController->GetLocalPlayer() : nullptr; return;
if (LP == nullptr)
auto* InputSubsystem = GetEnhancedInputLocalPlayerSubsystem(Pawn);
if (!InputSubsystem)
return; return;
UEnhancedInputLocalPlayerSubsystem* InputSubsystem = LP->GetSubsystem<UEnhancedInputLocalPlayerSubsystem>();
// add Input Mapping context // add Input Mapping context
InputSubsystem->AddMappingContext(IMCGrab, 0); InputSubsystem->AddMappingContext(IMCGrab, 0);
...@@ -109,7 +102,6 @@ void UGrabComponent::SetupInputActions() ...@@ -109,7 +102,6 @@ void UGrabComponent::SetupInputActions()
EI->BindAction(GrabInputAction, ETriggerEvent::Started, this, &UGrabComponent::OnBeginGrab); EI->BindAction(GrabInputAction, ETriggerEvent::Started, this, &UGrabComponent::OnBeginGrab);
EI->BindAction(GrabInputAction, ETriggerEvent::Completed, this, &UGrabComponent::OnEndGrab); EI->BindAction(GrabInputAction, ETriggerEvent::Completed, this, &UGrabComponent::OnEndGrab);
} }
void UGrabComponent::OnBeginGrab(const FInputActionValue& Value) void UGrabComponent::OnBeginGrab(const FInputActionValue& Value)
...@@ -127,5 +119,3 @@ void UGrabComponent::OnEndGrab(const FInputActionValue& Value) ...@@ -127,5 +119,3 @@ void UGrabComponent::OnEndGrab(const FInputActionValue& Value)
Grabbale->HandleOnClickEndEvents(this, Value); Grabbale->HandleOnClickEndEvents(this, Value);
} }
} }
// Fill out your copyright notice in the Description page of Project Settings.
#include "Interaction/Grabable.h"
// to avoid some bugs
UGrabable::UGrabable(const FObjectInitializer& ObjectInitializer)
:Super(ObjectInitializer)
{}
...@@ -19,8 +19,10 @@ UPrimitiveComponent* UGrabbingBehaviorComponent::GetFirstComponentSimulatingPhys ...@@ -19,8 +19,10 @@ UPrimitiveComponent* UGrabbingBehaviorComponent::GetFirstComponentSimulatingPhys
TargetActor->GetComponents<UPrimitiveComponent>(PrimitiveComponents); TargetActor->GetComponents<UPrimitiveComponent>(PrimitiveComponents);
// find any component that simulates physics, then traverse the hierarchy // find any component that simulates physics, then traverse the hierarchy
for (UPrimitiveComponent* const& Component : PrimitiveComponents) { for (UPrimitiveComponent* const& Component : PrimitiveComponents)
if (Component->IsSimulatingPhysics()) { {
if (Component->IsSimulatingPhysics())
{
return GetHighestParentSimulatingPhysics(Component); return GetHighestParentSimulatingPhysics(Component);
} }
} }
...@@ -30,17 +32,18 @@ UPrimitiveComponent* UGrabbingBehaviorComponent::GetFirstComponentSimulatingPhys ...@@ -30,17 +32,18 @@ UPrimitiveComponent* UGrabbingBehaviorComponent::GetFirstComponentSimulatingPhys
// recursively goes up the hierarchy and returns the highest parent simulating physics // recursively goes up the hierarchy and returns the highest parent simulating physics
UPrimitiveComponent* UGrabbingBehaviorComponent::GetHighestParentSimulatingPhysics(UPrimitiveComponent* Comp) UPrimitiveComponent* UGrabbingBehaviorComponent::GetHighestParentSimulatingPhysics(UPrimitiveComponent* Comp)
{ {
if (Cast<UPrimitiveComponent>(Comp->GetAttachParent()) && Comp->GetAttachParent()->IsSimulatingPhysics()) { if (Cast<UPrimitiveComponent>(Comp->GetAttachParent()) && Comp->GetAttachParent()->IsSimulatingPhysics())
{
return GetHighestParentSimulatingPhysics(Cast<UPrimitiveComponent>(Comp->GetAttachParent())); return GetHighestParentSimulatingPhysics(Cast<UPrimitiveComponent>(Comp->GetAttachParent()));
} }
else { else
{
return Comp; return Comp;
} }
} }
void UGrabbingBehaviorComponent::HandleGrabHold(FVector Position, FQuat Orientation) void UGrabbingBehaviorComponent::HandleGrabHold(FVector Position, FQuat Orientation)
{ {
} }
void UGrabbingBehaviorComponent::HandleGrabStart(AActor* GrabbedBy) void UGrabbingBehaviorComponent::HandleGrabStart(AActor* GrabbedBy)
...@@ -51,11 +54,13 @@ void UGrabbingBehaviorComponent::HandleGrabStart(AActor* GrabbedBy) ...@@ -51,11 +54,13 @@ void UGrabbingBehaviorComponent::HandleGrabStart(AActor* GrabbedBy)
MyPhysicsComponent = GetFirstComponentSimulatingPhysics(GetOwner()); MyPhysicsComponent = GetFirstComponentSimulatingPhysics(GetOwner());
if (MyPhysicsComponent) { if (MyPhysicsComponent)
{
MyPhysicsComponent->SetSimulatePhysics(false); MyPhysicsComponent->SetSimulatePhysics(false);
MyPhysicsComponent->AttachToComponent(RightHand, Rules); MyPhysicsComponent->AttachToComponent(RightHand, Rules);
} }
else { else
{
GetOwner()->GetRootComponent()->AttachToComponent(RightHand, Rules); GetOwner()->GetRootComponent()->AttachToComponent(RightHand, Rules);
} }
...@@ -69,7 +74,8 @@ void UGrabbingBehaviorComponent::HandleGrabEnd() ...@@ -69,7 +74,8 @@ void UGrabbingBehaviorComponent::HandleGrabEnd()
{ {
MyPhysicsComponent->DetachFromComponent(FDetachmentTransformRules::KeepWorldTransform); MyPhysicsComponent->DetachFromComponent(FDetachmentTransformRules::KeepWorldTransform);
MyPhysicsComponent->SetSimulatePhysics(true); MyPhysicsComponent->SetSimulatePhysics(true);
}else }
else
{ {
GetOwner()->GetRootComponent()->DetachFromComponent(FDetachmentTransformRules::KeepWorldTransform); GetOwner()->GetRootComponent()->DetachFromComponent(FDetachmentTransformRules::KeepWorldTransform);
} }
...@@ -82,10 +88,8 @@ void UGrabbingBehaviorComponent::BeginPlay() ...@@ -82,10 +88,8 @@ void UGrabbingBehaviorComponent::BeginPlay()
Super::BeginPlay(); Super::BeginPlay();
} }
void UGrabbingBehaviorComponent::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) void UGrabbingBehaviorComponent::TickComponent(float DeltaTime, ELevelTick TickType,
FActorComponentTickFunction* ThisTickFunction)
{ {
Super::TickComponent(DeltaTime, TickType, ThisTickFunction); Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
} }
...@@ -10,47 +10,43 @@ UGrabbingBehaviorOnLineComponent::UGrabbingBehaviorOnLineComponent() ...@@ -10,47 +10,43 @@ UGrabbingBehaviorOnLineComponent::UGrabbingBehaviorOnLineComponent()
// off to improve performance if you don't need them. // off to improve performance if you don't need them.
PrimaryComponentTick.bCanEverTick = true; PrimaryComponentTick.bCanEverTick = true;
this->Distance = 0; Distance = 0;
} }
void UGrabbingBehaviorOnLineComponent::SetDistance(float Dist) void UGrabbingBehaviorOnLineComponent::SetDistance(float Dist)
{ {
check(Dist > 0 && "max distance has to be greater than 0"); check(Dist > 0 && "max distance has to be greater than 0");
this->Distance = Dist; Distance = Dist;
} }
float UGrabbingBehaviorOnLineComponent::GetDistance() const float UGrabbingBehaviorOnLineComponent::GetDistance() const
{ {
return this->Distance; return Distance;
} }
void UGrabbingBehaviorOnLineComponent::SetDiscreteNumberOfPoints(int Num) void UGrabbingBehaviorOnLineComponent::SetDiscreteNumberOfPoints(int Num)
{ {
NumPoints = Num; NumPoints = Num;
bIsDiscrete = true; bIsDiscrete = true;
} }
void UGrabbingBehaviorOnLineComponent::HandleGrabHold(FVector Position, FQuat Orientation) void UGrabbingBehaviorOnLineComponent::HandleGrabHold(FVector Position, FQuat Orientation)
{ {
FVector AttachmentPoint = this->GetRelativeLocation(); const FVector AttachmentPoint = this->GetRelativeLocation();
FVector ConstraintAxis = this->GetComponentQuat().GetUpVector(); const FVector ConstraintAxis = this->GetComponentQuat().GetUpVector();
FVector Direction = Orientation.GetForwardVector(); const FVector Direction = Orientation.GetForwardVector();
FVector FromHandToMe = -Position + AttachmentPoint; const FVector FromHandToMe = -Position + AttachmentPoint;
// Vector perpendicular to both points // Vector perpendicular to both points
FVector Temp = FVector::CrossProduct(FromHandToMe, ConstraintAxis); FVector Temp = FVector::CrossProduct(FromHandToMe, ConstraintAxis);
Temp.Normalize(); Temp.Normalize();
FVector PlaneNormal = FVector::CrossProduct(ConstraintAxis, Temp); const FVector PlaneNormal = FVector::CrossProduct(ConstraintAxis, Temp);
// get intersection point defined by plane // get intersection point defined by plane
FVector Intersection = FMath::LinePlaneIntersection(Position, Position + Direction, AttachmentPoint, PlaneNormal); const FVector Intersection = FMath::LinePlaneIntersection(Position, Position + Direction, AttachmentPoint,
FVector FromOriginToIntersection = Intersection - AttachmentPoint; PlaneNormal);
const FVector FromOriginToIntersection = Intersection - AttachmentPoint;
// point along the constraint axis with length of the projection from intersection point onto the axis // point along the constraint axis with length of the projection from intersection point onto the axis
FVector NewPosition = FVector::DotProduct(FromOriginToIntersection, ConstraintAxis) * ConstraintAxis; FVector NewPosition = FVector::DotProduct(FromOriginToIntersection, ConstraintAxis) * ConstraintAxis;
...@@ -59,9 +55,10 @@ void UGrabbingBehaviorOnLineComponent::HandleGrabHold(FVector Position, FQuat Or ...@@ -59,9 +55,10 @@ void UGrabbingBehaviorOnLineComponent::HandleGrabHold(FVector Position, FQuat Or
if (bIsDiscrete) if (bIsDiscrete)
{ {
float lengthOfSegment = 1.f / static_cast<float>(NumPoints + 1.f); const float lengthOfSegment = 1.f / static_cast<float>(NumPoints + 1.f);
FVector LineBeginning = -ConstraintAxis * Distance; const FVector LineBeginning = -ConstraintAxis * Distance;
float LengthOnLine = (FVector::DotProduct(FromOriginToIntersection, ConstraintAxis) / Distance + 1.f) / 2.f; // is between 0 and 1 const float LengthOnLine = (FVector::DotProduct(FromOriginToIntersection, ConstraintAxis) / Distance + 1.f) / 2.f;
// is between 0 and 1
float VectorSize = FMath::CeilToFloat(LengthOnLine / lengthOfSegment); float VectorSize = FMath::CeilToFloat(LengthOnLine / lengthOfSegment);
if (VectorSize <= 0) VectorSize = 1; if (VectorSize <= 0) VectorSize = 1;
...@@ -75,22 +72,3 @@ void UGrabbingBehaviorOnLineComponent::HandleGrabHold(FVector Position, FQuat Or ...@@ -75,22 +72,3 @@ void UGrabbingBehaviorOnLineComponent::HandleGrabHold(FVector Position, FQuat Or
// here rotation is not changed // here rotation is not changed
GetOwner()->SetActorLocation(NewPosition); GetOwner()->SetActorLocation(NewPosition);
} }
// Called when the game starts
void UGrabbingBehaviorOnLineComponent::BeginPlay()
{
Super::BeginPlay();
// ...
}
// Called every frame
void UGrabbingBehaviorOnLineComponent::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
{
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
}
...@@ -3,15 +3,6 @@ ...@@ -3,15 +3,6 @@
#include "Interaction/GrabbingBehaviorOnPlaneComponent.h" #include "Interaction/GrabbingBehaviorOnPlaneComponent.h"
// Sets default values for this component's properties
UGrabbingBehaviorOnPlaneComponent::UGrabbingBehaviorOnPlaneComponent()
{
// Set this component to be initialized when the game starts, and to be ticked every frame. You can turn these features
// off to improve performance if you don't need them.
PrimaryComponentTick.bCanEverTick = true;
}
void UGrabbingBehaviorOnPlaneComponent::SetDistance(float Dist) void UGrabbingBehaviorOnPlaneComponent::SetDistance(float Dist)
{ {
check(Dist > 0 && "max distance has to be greater than 0"); check(Dist > 0 && "max distance has to be greater than 0");
...@@ -23,7 +14,6 @@ float UGrabbingBehaviorOnPlaneComponent::GetDistance() const ...@@ -23,7 +14,6 @@ float UGrabbingBehaviorOnPlaneComponent::GetDistance() const
return this->Distance; return this->Distance;
} }
void UGrabbingBehaviorOnPlaneComponent::HandleGrabHold(FVector Position, FQuat Orientation) void UGrabbingBehaviorOnPlaneComponent::HandleGrabHold(FVector Position, FQuat Orientation)
{ {
FVector AttachmentPoint = this->GetRelativeLocation(); FVector AttachmentPoint = this->GetRelativeLocation();
...@@ -44,24 +34,3 @@ void UGrabbingBehaviorOnPlaneComponent::HandleGrabHold(FVector Position, FQuat O ...@@ -44,24 +34,3 @@ void UGrabbingBehaviorOnPlaneComponent::HandleGrabHold(FVector Position, FQuat O
// here rotation is not changed // here rotation is not changed
GetOwner()->SetActorLocation(NewPosition); GetOwner()->SetActorLocation(NewPosition);
} }
\ No newline at end of file
// Called when the game starts
void UGrabbingBehaviorOnPlaneComponent::BeginPlay()
{
Super::BeginPlay();
// ...
}
// Called every frame
void UGrabbingBehaviorOnPlaneComponent::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
{
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
// ...
}
...@@ -3,16 +3,6 @@ ...@@ -3,16 +3,6 @@
#include "Interaction/HoverBehaviour.h" #include "Interaction/HoverBehaviour.h"
// Sets default values for this component's properties
UHoverBehaviour::UHoverBehaviour()
{
// Set this component to be initialized when the game starts, and to be ticked every frame. You can turn these features
// off to improve performance if you don't need them.
PrimaryComponentTick.bCanEverTick = true;
// ...
}
void UHoverBehaviour::OnHoverStart(const USceneComponent* TriggeredComponent, FHitResult Hit) void UHoverBehaviour::OnHoverStart(const USceneComponent* TriggeredComponent, FHitResult Hit)
{ {
} }
...@@ -21,21 +11,10 @@ void UHoverBehaviour::OnHoverEnd(const USceneComponent* TriggeredComponent) ...@@ -21,21 +11,10 @@ void UHoverBehaviour::OnHoverEnd(const USceneComponent* TriggeredComponent)
{ {
} }
void UHoverBehaviour::BeginPlay() void UHoverBehaviour::BeginPlay()
{ {
Super::BeginPlay(); Super::BeginPlay();
OnHoverStartEvent.AddDynamic(this, &UHoverBehaviour::OnHoverStart); OnHoverStartEvent.AddDynamic(this, &UHoverBehaviour::OnHoverStart);
OnHoverEndEvent.AddDynamic(this, &UHoverBehaviour::OnHoverEnd); OnHoverEndEvent.AddDynamic(this, &UHoverBehaviour::OnHoverEnd);
} }
void UHoverBehaviour::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
{
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
}
...@@ -5,20 +5,8 @@ ...@@ -5,20 +5,8 @@
#include "Interaction/ClickBehaviour.h" #include "Interaction/ClickBehaviour.h"
#include "Interaction/HoverBehaviour.h" #include "Interaction/HoverBehaviour.h"
#include "Utility/VirtualRealityUtilities.h"
// Sets default values for this component's properties void UInteractableBase::RestrictInteractionToComponents(const TArray<USceneComponent*>& Components)
UInteractableBase::UInteractableBase()
{
// Set this component to be initialized when the game starts, and to be ticked every frame. You can turn these features
// off to improve performance if you don't need them.
PrimaryComponentTick.bCanEverTick = true;
// ...
}
void UInteractableBase::RestrictInteractionToComponents(TArray<USceneComponent*> Components)
{ {
if(Components.IsEmpty()) if(Components.IsEmpty())
{ {
...@@ -49,16 +37,6 @@ void UInteractableBase::BeginPlay() ...@@ -49,16 +37,6 @@ void UInteractableBase::BeginPlay()
{ {
Super::BeginPlay(); Super::BeginPlay();
InitDefaultBehaviourReferences(); InitDefaultBehaviourReferences();
// ...
}
// Called every frame
void UInteractableBase::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
{
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
// ...
} }
void UInteractableBase::HandleOnHoverStartEvents(USceneComponent* TriggerComponent) void UInteractableBase::HandleOnHoverStartEvents(USceneComponent* TriggerComponent)
......
...@@ -3,40 +3,9 @@ ...@@ -3,40 +3,9 @@
#include "Interaction/OnClickGrabBehavior.h" #include "Interaction/OnClickGrabBehavior.h"
#include "Interaction/GrabbableComponent.h"
#include "Interaction/InteractableBase.h" #include "Interaction/InteractableBase.h"
#include "Kismet/GameplayStatics.h" #include "Kismet/GameplayStatics.h"
#include "Serialization/JsonTypes.h" #include "Serialization/JsonTypes.h"
#include "Utility/VirtualRealityUtilities.h"
// Sets default values for this component's properties
UOnClickGrabBehavior::UOnClickGrabBehavior()
{
// Set this component to be initialized when the game starts, and to be ticked every frame. You can turn these features
// off to improve performance if you don't need them.
PrimaryComponentTick.bCanEverTick = true;
// ...
}
// Called when the game starts
void UOnClickGrabBehavior::BeginPlay()
{
Super::BeginPlay();
// ...
}
// Called every frame
void UOnClickGrabBehavior::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
{
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
// ...
}
UPrimitiveComponent* UOnClickGrabBehavior::GetFirstComponentSimulatingPhysics(const AActor* TargetActor) UPrimitiveComponent* UOnClickGrabBehavior::GetFirstComponentSimulatingPhysics(const AActor* TargetActor)
{ {
...@@ -44,8 +13,10 @@ UPrimitiveComponent* UOnClickGrabBehavior::GetFirstComponentSimulatingPhysics(co ...@@ -44,8 +13,10 @@ UPrimitiveComponent* UOnClickGrabBehavior::GetFirstComponentSimulatingPhysics(co
TargetActor->GetComponents<UPrimitiveComponent>(PrimitiveComponents); TargetActor->GetComponents<UPrimitiveComponent>(PrimitiveComponents);
// find any component that simulates physics, then traverse the hierarchy // find any component that simulates physics, then traverse the hierarchy
for (UPrimitiveComponent* const& Component : PrimitiveComponents) { for (UPrimitiveComponent* const& Component : PrimitiveComponents)
if (Component->IsSimulatingPhysics()) { {
if (Component->IsSimulatingPhysics())
{
return GetHighestParentSimulatingPhysics(Component); return GetHighestParentSimulatingPhysics(Component);
} }
} }
...@@ -55,10 +26,12 @@ UPrimitiveComponent* UOnClickGrabBehavior::GetFirstComponentSimulatingPhysics(co ...@@ -55,10 +26,12 @@ UPrimitiveComponent* UOnClickGrabBehavior::GetFirstComponentSimulatingPhysics(co
// recursively goes up the hierarchy and returns the highest parent simulating physics // recursively goes up the hierarchy and returns the highest parent simulating physics
UPrimitiveComponent* UOnClickGrabBehavior::GetHighestParentSimulatingPhysics(UPrimitiveComponent* Comp) UPrimitiveComponent* UOnClickGrabBehavior::GetHighestParentSimulatingPhysics(UPrimitiveComponent* Comp)
{ {
if (Cast<UPrimitiveComponent>(Comp->GetAttachParent()) && Comp->GetAttachParent()->IsSimulatingPhysics()) { if (Cast<UPrimitiveComponent>(Comp->GetAttachParent()) && Comp->GetAttachParent()->IsSimulatingPhysics())
{
return GetHighestParentSimulatingPhysics(Cast<UPrimitiveComponent>(Comp->GetAttachParent())); return GetHighestParentSimulatingPhysics(Cast<UPrimitiveComponent>(Comp->GetAttachParent()));
} }
else { else
{
return Comp; return Comp;
} }
} }
...@@ -73,7 +46,8 @@ void UOnClickGrabBehavior::OnClickStart(USceneComponent* TriggeredComponent, con ...@@ -73,7 +46,8 @@ void UOnClickGrabBehavior::OnClickStart(USceneComponent* TriggeredComponent, con
MyPhysicsComponent = GetFirstComponentSimulatingPhysics(GetOwner()); MyPhysicsComponent = GetFirstComponentSimulatingPhysics(GetOwner());
if (MyPhysicsComponent) { if (MyPhysicsComponent)
{
MyPhysicsComponent->SetSimulatePhysics(false); MyPhysicsComponent->SetSimulatePhysics(false);
MyPhysicsComponent->AttachToComponent(Hand, Rules); MyPhysicsComponent->AttachToComponent(Hand, Rules);
} }
...@@ -100,7 +74,8 @@ void UOnClickGrabBehavior::OnClickEnd(USceneComponent* TriggeredComponent, const ...@@ -100,7 +74,8 @@ void UOnClickGrabBehavior::OnClickEnd(USceneComponent* TriggeredComponent, const
{ {
MyPhysicsComponent->DetachFromComponent(FDetachmentTransformRules::KeepWorldTransform); MyPhysicsComponent->DetachFromComponent(FDetachmentTransformRules::KeepWorldTransform);
MyPhysicsComponent->SetSimulatePhysics(true); MyPhysicsComponent->SetSimulatePhysics(true);
}else }
else
{ {
GetOwner()->GetRootComponent()->DetachFromComponent(FDetachmentTransformRules::KeepWorldTransform); GetOwner()->GetRootComponent()->DetachFromComponent(FDetachmentTransformRules::KeepWorldTransform);
} }
...@@ -115,5 +90,3 @@ void UOnClickGrabBehavior::OnClickEnd(USceneComponent* TriggeredComponent, const ...@@ -115,5 +90,3 @@ void UOnClickGrabBehavior::OnClickEnd(USceneComponent* TriggeredComponent, const
} }
} }
} }
...@@ -6,7 +6,6 @@ ...@@ -6,7 +6,6 @@
#include "EnhancedInputComponent.h" #include "EnhancedInputComponent.h"
#include "EnhancedInputSubsystems.h" #include "EnhancedInputSubsystems.h"
#include "Kismet/KismetSystemLibrary.h" #include "Kismet/KismetSystemLibrary.h"
#include "Utility/VirtualRealityUtilities.h"
// Sets default values for this component's properties // Sets default values for this component's properties
URaycastSelectionComponent::URaycastSelectionComponent() URaycastSelectionComponent::URaycastSelectionComponent()
...@@ -18,18 +17,9 @@ URaycastSelectionComponent::URaycastSelectionComponent() ...@@ -18,18 +17,9 @@ URaycastSelectionComponent::URaycastSelectionComponent()
// ... // ...
} }
// Called when the game starts
void URaycastSelectionComponent::BeginPlay()
{
Super::BeginPlay();
SetupInputActions();
// ...
}
// Called every frame // Called every frame
void URaycastSelectionComponent::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) void URaycastSelectionComponent::TickComponent(float DeltaTime, ELevelTick TickType,
FActorComponentTickFunction* ThisTickFunction)
{ {
Super::TickComponent(DeltaTime, TickType, ThisTickFunction); Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
...@@ -59,7 +49,6 @@ void URaycastSelectionComponent::TickComponent(float DeltaTime, ELevelTick TickT ...@@ -59,7 +49,6 @@ void URaycastSelectionComponent::TickComponent(float DeltaTime, ELevelTick TickT
} }
} }
CurrentRaycastSelectable = CurrentSelectable; CurrentRaycastSelectable = CurrentSelectable;
if (CurrentRaycastSelectable != PreviousRaycastSelectable) if (CurrentRaycastSelectable != PreviousRaycastSelectable)
...@@ -77,26 +66,6 @@ void URaycastSelectionComponent::TickComponent(float DeltaTime, ELevelTick TickT ...@@ -77,26 +66,6 @@ void URaycastSelectionComponent::TickComponent(float DeltaTime, ELevelTick TickT
PreviousRaycastSelectable = CurrentRaycastSelectable; PreviousRaycastSelectable = CurrentRaycastSelectable;
} }
void URaycastSelectionComponent::SetupInputActions()
{
const APawn* Pawn = Cast<APawn>(GetOwner());
const APlayerController* PlayerController = Cast<APlayerController>(Pawn->GetController());
const ULocalPlayer* LP = PlayerController ? PlayerController->GetLocalPlayer() : nullptr;
if (LP == nullptr)
return;
UEnhancedInputLocalPlayerSubsystem* InputSubsystem = LP->GetSubsystem<UEnhancedInputLocalPlayerSubsystem>();
// add Input Mapping context
InputSubsystem->AddMappingContext(IMCRaycastSelection,0);
UEnhancedInputComponent* EI = Cast<UEnhancedInputComponent>(Pawn->InputComponent);
if (EI == nullptr)
return;
EI->BindAction(RayCastSelectInputAction, ETriggerEvent::Started, this, &URaycastSelectionComponent::OnBeginSelect);
EI->BindAction(RayCastSelectInputAction, ETriggerEvent::Completed, this, &URaycastSelectionComponent::OnEndSelect);
}
void URaycastSelectionComponent::OnBeginSelect(const FInputActionValue& Value) void URaycastSelectionComponent::OnBeginSelect(const FInputActionValue& Value)
{ {
if (CurrentRaycastSelectable) if (CurrentRaycastSelectable)
...@@ -111,3 +80,25 @@ void URaycastSelectionComponent::OnEndSelect(const FInputActionValue& Value) ...@@ -111,3 +80,25 @@ void URaycastSelectionComponent::OnEndSelect(const FInputActionValue& Value)
CurrentRaycastSelectable->HandleOnClickEndEvents(this, Value); CurrentRaycastSelectable->HandleOnClickEndEvents(this, Value);
} }
void URaycastSelectionComponent::SetupPlayerInput(UInputComponent* PlayerInputComponent)
{
IInputExtensionInterface::SetupPlayerInput(PlayerInputComponent);
const APawn* Pawn = Cast<APawn>(GetOwner());
if (!Pawn)
return;
auto* InputSubsystem = GetEnhancedInputLocalPlayerSubsystem(Pawn);
if (!InputSubsystem)
return;
// add Input Mapping context
InputSubsystem->AddMappingContext(IMCRaycastSelection, 0);
UEnhancedInputComponent* EI = Cast<UEnhancedInputComponent>(Pawn->InputComponent);
if (!EI)
return;
EI->BindAction(RayCastSelectInputAction, ETriggerEvent::Started, this, &URaycastSelectionComponent::OnBeginSelect);
EI->BindAction(RayCastSelectInputAction, ETriggerEvent::Completed, this, &URaycastSelectionComponent::OnEndSelect);
}
// Fill out your copyright notice in the Description page of Project Settings.
#include "Interaction/Targetable.h"
UTargetable::UTargetable(const FObjectInitializer& ObjectInitializer)
:Super(ObjectInitializer)
{}
...@@ -8,7 +8,6 @@ ...@@ -8,7 +8,6 @@
#include "Interaction/Targetable.h" #include "Interaction/Targetable.h"
#include "Interaction/GrabbingBehaviorComponent.h" #include "Interaction/GrabbingBehaviorComponent.h"
#include "Misc/Optional.h" #include "Misc/Optional.h"
#include "DrawDebugHelpers.h"
DEFINE_LOG_CATEGORY(LogVRInteractionComponent); DEFINE_LOG_CATEGORY(LogVRInteractionComponent);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment