diff --git a/Source/DisplayClusterExtensions/Private/Fixes/FixNDisplayStereoDevice.cpp b/Source/DisplayClusterExtensions/Private/Fixes/FixNDisplayStereoDevice.cpp index afa806dc6949c5db0c652e3972564840da3c4515..3b946733acc7e188612b9e449773154db58b9993 100644 --- a/Source/DisplayClusterExtensions/Private/Fixes/FixNDisplayStereoDevice.cpp +++ b/Source/DisplayClusterExtensions/Private/Fixes/FixNDisplayStereoDevice.cpp @@ -1,4 +1,4 @@ -#include "FixNDisplayStereoDevice.h" +#include "Fixes/FixNDisplayStereoDevice.h" void FFixNDisplayStereoDevice::Register() { diff --git a/Source/DisplayClusterExtensions/Private/Interaction/Clickable.cpp b/Source/DisplayClusterExtensions/Private/Interaction/Clickable.cpp index 38d5fd80840f3358866775e20e1e98f97d64c871..16de826a57db7e3784ecba88bbb9233ac52827f3 100644 --- a/Source/DisplayClusterExtensions/Private/Interaction/Clickable.cpp +++ b/Source/DisplayClusterExtensions/Private/Interaction/Clickable.cpp @@ -1,8 +1,8 @@ -// Fill out your copyright notice in the Description page of Project Settings. - - -#include "Clickable.h" - -UClickable::UClickable(const FObjectInitializer& ObjectInitializer) - :Super(ObjectInitializer) -{} +// Fill out your copyright notice in the Description page of Project Settings. + + +#include "Interaction/Clickable.h" + +UClickable::UClickable(const FObjectInitializer& ObjectInitializer) + :Super(ObjectInitializer) +{} diff --git a/Source/DisplayClusterExtensions/Private/Interaction/Grabable.cpp b/Source/DisplayClusterExtensions/Private/Interaction/Grabable.cpp index 99330b38597c05fb5e3ea8d476edd77c3e16b797..ab420ac4e5450137993546266ca1496132b618fd 100644 --- a/Source/DisplayClusterExtensions/Private/Interaction/Grabable.cpp +++ b/Source/DisplayClusterExtensions/Private/Interaction/Grabable.cpp @@ -1,10 +1,10 @@ -// Fill out your copyright notice in the Description page of Project Settings. - - -#include "Grabable.h" - -// to avoid some bugs -UGrabable::UGrabable(const FObjectInitializer& ObjectInitializer) - :Super(ObjectInitializer) -{} - +// 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) +{} + diff --git a/Source/DisplayClusterExtensions/Private/Interaction/GrabbingBehaviorComponent.cpp b/Source/DisplayClusterExtensions/Private/Interaction/GrabbingBehaviorComponent.cpp index 5942605fe35abe48776669c183c4d0e17264e6c4..2371e27a7f2cee47073ef4f130fdbd0bb9f603aa 100644 --- a/Source/DisplayClusterExtensions/Private/Interaction/GrabbingBehaviorComponent.cpp +++ b/Source/DisplayClusterExtensions/Private/Interaction/GrabbingBehaviorComponent.cpp @@ -1,34 +1,34 @@ -// Fill out your copyright notice in the Description page of Project Settings. - - -#include "GrabbingBehaviorComponent.h" - -// Sets default values for this component's properties -UGrabbingBehaviorComponent::UGrabbingBehaviorComponent() -{ - // 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 UGrabbingBehaviorComponent::BeginPlay() -{ - Super::BeginPlay(); - - // ... - -} - - -// Called every frame -void UGrabbingBehaviorComponent::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) -{ - Super::TickComponent(DeltaTime, TickType, ThisTickFunction); - - // ... -} - +// Fill out your copyright notice in the Description page of Project Settings. + + +#include "Interaction/GrabbingBehaviorComponent.h" + +// Sets default values for this component's properties +UGrabbingBehaviorComponent::UGrabbingBehaviorComponent() +{ + // 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 UGrabbingBehaviorComponent::BeginPlay() +{ + Super::BeginPlay(); + + // ... + +} + + +// Called every frame +void UGrabbingBehaviorComponent::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) +{ + Super::TickComponent(DeltaTime, TickType, ThisTickFunction); + + // ... +} + diff --git a/Source/DisplayClusterExtensions/Private/Interaction/GrabbingBehaviorOnLineComponent.cpp b/Source/DisplayClusterExtensions/Private/Interaction/GrabbingBehaviorOnLineComponent.cpp index f9247fce6a6c35cf1f3f0c9460d8acaabcd10d51..f57b28f7e9284bedeff9ae2198a13e8ad2635b33 100644 --- a/Source/DisplayClusterExtensions/Private/Interaction/GrabbingBehaviorOnLineComponent.cpp +++ b/Source/DisplayClusterExtensions/Private/Interaction/GrabbingBehaviorOnLineComponent.cpp @@ -1,7 +1,7 @@ // Fill out your copyright notice in the Description page of Project Settings. -#include "GrabbingBehaviorOnLineComponent.h" +#include "Interaction/GrabbingBehaviorOnLineComponent.h" // Sets default values for this component's properties UGrabbingBehaviorOnLineComponent::UGrabbingBehaviorOnLineComponent() diff --git a/Source/DisplayClusterExtensions/Private/Interaction/GrabbingBehaviorOnPlaneComponent.cpp b/Source/DisplayClusterExtensions/Private/Interaction/GrabbingBehaviorOnPlaneComponent.cpp index 5fa0b78272ad75cb2624fbed03a82c5d1798ea8d..dfc8e0ef5f7c2013c3dce5b452752d2e7466a216 100644 --- a/Source/DisplayClusterExtensions/Private/Interaction/GrabbingBehaviorOnPlaneComponent.cpp +++ b/Source/DisplayClusterExtensions/Private/Interaction/GrabbingBehaviorOnPlaneComponent.cpp @@ -1,7 +1,7 @@ // Fill out your copyright notice in the Description page of Project Settings. //TODO rename distance to maxDistance -#include "GrabbingBehaviorOnPlaneComponent.h" +#include "Interaction/GrabbingBehaviorOnPlaneComponent.h" // Sets default values for this component's properties UGrabbingBehaviorOnPlaneComponent::UGrabbingBehaviorOnPlaneComponent() diff --git a/Source/DisplayClusterExtensions/Private/Pawn/BasicVRInteractionComponent.cpp b/Source/DisplayClusterExtensions/Private/Pawn/BasicVRInteractionComponent.cpp index 88bb0ef84c688993707aabc00722233ebfe4736f..04541adfe9e1abb292d1cdfcf8da294a427c6405 100644 --- a/Source/DisplayClusterExtensions/Private/Pawn/BasicVRInteractionComponent.cpp +++ b/Source/DisplayClusterExtensions/Private/Pawn/BasicVRInteractionComponent.cpp @@ -1,132 +1,132 @@ -// Fill out your copyright notice in the Description page of Project Settings. - - -#include "BasicVRInteractionComponent.h" - - -#include "Clickable.h" -#include "Grabable.h" -#include "GrabbingBehaviorComponent.h" - -// Sets default values for this component's properties -UBasicVRInteractionComponent::UBasicVRInteractionComponent() -{ - // 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 UBasicVRInteractionComponent::BeginInteraction() -{ - if(!InteractionRayEmitter) return; - - // start and end point for raytracing - const FTwoVectors StartEnd = GetHandRay(MaxClickDistance); - const FVector Start = StartEnd.v1; - const FVector End = StartEnd.v2; - - // will be filled by the Line Trace Function - FHitResult Hit; - - //if hit was not found return - const FCollisionObjectQueryParams Params; - if (!GetWorld()->LineTraceSingleByObjectType(Hit, Start, End, Params)) - return; - - AActor* HitActor = Hit.GetActor(); - - // try to cast HitActor into a Grabable if not succeeded will become a nullptr - IGrabable* GrabableActor = Cast<IGrabable>(HitActor); - IClickable* ClickableActor = Cast<IClickable>(HitActor); - - if (GrabableActor != nullptr && Hit.Distance < MaxGrabDistance) - { - // call grabable actors function so he reacts to our grab - GrabableActor->OnGrabbed_Implementation(); - - // save it for later, is needed every tick - Behavior = HitActor->FindComponentByClass<UGrabbingBehaviorComponent>(); - if ( Behavior == nullptr) - HandlePhysicsAndAttachActor(HitActor); - - // we save the grabbedActor in a general form to access all of AActors functions easily later - GrabbedActor = HitActor; - } - else if (ClickableActor != nullptr && Hit.Distance < MaxClickDistance) - { - ClickableActor->OnClicked_Implementation(Hit.Location); - } -} - - -void UBasicVRInteractionComponent::EndInteraction() -{ - if(!InteractionRayEmitter) return; - - // if we didnt grab anyone there is no need to release - if (GrabbedActor == nullptr) - return; - - // let the grabbed object react to release - Cast<IGrabable>(GrabbedActor)->OnReleased_Implementation(); - - // Detach the Actor - if (GrabbedActor->FindComponentByClass<UGrabbingBehaviorComponent>() == nullptr) - { - GrabbedActor->GetRootComponent()->DetachFromComponent(FDetachmentTransformRules::KeepWorldTransform); - GrabbedActor->FindComponentByClass<UPrimitiveComponent>()->SetSimulatePhysics(bDidSimulatePhysics); - } - - // forget about the actor - GrabbedActor = nullptr; - Behavior = nullptr; -} - -// Called every frame -void UBasicVRInteractionComponent::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) -{ - Super::TickComponent(DeltaTime, TickType, ThisTickFunction); - - // if an actor is grabbed and a behavior is defined move move him accordingly - if (GrabbedActor == nullptr || InteractionRayEmitter == nullptr) return; - - // if our Grabable Actor is not constrained - if (Behavior != nullptr) - { - // specifies the hand in space - const FVector HandPos = InteractionRayEmitter->GetComponentLocation(); - const FQuat HandQuat = InteractionRayEmitter->GetComponentQuat(); - - Behavior->HandleNewPositionAndDirection(HandPos, HandQuat); - } -} - -void UBasicVRInteractionComponent::Initialize(USceneComponent* RayEmitter, float InMaxGrabDistance, float InMaxClickDistance) -{ - if(RayEmitter != nullptr) return; /* Return if already initialized */ - - InteractionRayEmitter = RayEmitter; - MaxGrabDistance = InMaxGrabDistance; - MaxClickDistance = InMaxClickDistance; -} - -void UBasicVRInteractionComponent::HandlePhysicsAndAttachActor(AActor* HitActor) -{ - UPrimitiveComponent* PhysicsComp = HitActor->FindComponentByClass<UPrimitiveComponent>(); - - bDidSimulatePhysics = PhysicsComp->IsSimulatingPhysics(); // remember if we need to tun physics back on or not - PhysicsComp->SetSimulatePhysics(false); - FAttachmentTransformRules Rules = FAttachmentTransformRules(EAttachmentRule::KeepWorld, true); - HitActor->AttachToComponent(InteractionRayEmitter, Rules); -} - -FTwoVectors UBasicVRInteractionComponent::GetHandRay(const float Length) const -{ - const FVector Start = InteractionRayEmitter->GetComponentLocation(); - const FVector Direction = InteractionRayEmitter->GetForwardVector(); - const FVector End = Start + Length * Direction; - - return FTwoVectors(Start, End); -} +// Fill out your copyright notice in the Description page of Project Settings. + + +#include "Pawn/BasicVRInteractionComponent.h" + + +#include "Interaction/Clickable.h" +#include "Interaction/Grabable.h" +#include "Interaction/GrabbingBehaviorComponent.h" + +// Sets default values for this component's properties +UBasicVRInteractionComponent::UBasicVRInteractionComponent() +{ + // 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 UBasicVRInteractionComponent::BeginInteraction() +{ + if(!InteractionRayEmitter) return; + + // start and end point for raytracing + const FTwoVectors StartEnd = GetHandRay(MaxClickDistance); + const FVector Start = StartEnd.v1; + const FVector End = StartEnd.v2; + + // will be filled by the Line Trace Function + FHitResult Hit; + + //if hit was not found return + const FCollisionObjectQueryParams Params; + if (!GetWorld()->LineTraceSingleByObjectType(Hit, Start, End, Params)) + return; + + AActor* HitActor = Hit.GetActor(); + + // try to cast HitActor into a Grabable if not succeeded will become a nullptr + IGrabable* GrabableActor = Cast<IGrabable>(HitActor); + IClickable* ClickableActor = Cast<IClickable>(HitActor); + + if (GrabableActor != nullptr && Hit.Distance < MaxGrabDistance) + { + // call grabable actors function so he reacts to our grab + GrabableActor->OnGrabbed_Implementation(); + + // save it for later, is needed every tick + Behavior = HitActor->FindComponentByClass<UGrabbingBehaviorComponent>(); + if ( Behavior == nullptr) + HandlePhysicsAndAttachActor(HitActor); + + // we save the grabbedActor in a general form to access all of AActors functions easily later + GrabbedActor = HitActor; + } + else if (ClickableActor != nullptr && Hit.Distance < MaxClickDistance) + { + ClickableActor->OnClicked_Implementation(Hit.Location); + } +} + + +void UBasicVRInteractionComponent::EndInteraction() +{ + if(!InteractionRayEmitter) return; + + // if we didnt grab anyone there is no need to release + if (GrabbedActor == nullptr) + return; + + // let the grabbed object react to release + Cast<IGrabable>(GrabbedActor)->OnReleased_Implementation(); + + // Detach the Actor + if (GrabbedActor->FindComponentByClass<UGrabbingBehaviorComponent>() == nullptr) + { + GrabbedActor->GetRootComponent()->DetachFromComponent(FDetachmentTransformRules::KeepWorldTransform); + GrabbedActor->FindComponentByClass<UPrimitiveComponent>()->SetSimulatePhysics(bDidSimulatePhysics); + } + + // forget about the actor + GrabbedActor = nullptr; + Behavior = nullptr; +} + +// Called every frame +void UBasicVRInteractionComponent::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) +{ + Super::TickComponent(DeltaTime, TickType, ThisTickFunction); + + // if an actor is grabbed and a behavior is defined move move him accordingly + if (GrabbedActor == nullptr || InteractionRayEmitter == nullptr) return; + + // if our Grabable Actor is not constrained + if (Behavior != nullptr) + { + // specifies the hand in space + const FVector HandPos = InteractionRayEmitter->GetComponentLocation(); + const FQuat HandQuat = InteractionRayEmitter->GetComponentQuat(); + + Behavior->HandleNewPositionAndDirection(HandPos, HandQuat); + } +} + +void UBasicVRInteractionComponent::Initialize(USceneComponent* RayEmitter, float InMaxGrabDistance, float InMaxClickDistance) +{ + if(RayEmitter != nullptr) return; /* Return if already initialized */ + + InteractionRayEmitter = RayEmitter; + MaxGrabDistance = InMaxGrabDistance; + MaxClickDistance = InMaxClickDistance; +} + +void UBasicVRInteractionComponent::HandlePhysicsAndAttachActor(AActor* HitActor) +{ + UPrimitiveComponent* PhysicsComp = HitActor->FindComponentByClass<UPrimitiveComponent>(); + + bDidSimulatePhysics = PhysicsComp->IsSimulatingPhysics(); // remember if we need to tun physics back on or not + PhysicsComp->SetSimulatePhysics(false); + FAttachmentTransformRules Rules = FAttachmentTransformRules(EAttachmentRule::KeepWorld, true); + HitActor->AttachToComponent(InteractionRayEmitter, Rules); +} + +FTwoVectors UBasicVRInteractionComponent::GetHandRay(const float Length) const +{ + const FVector Start = InteractionRayEmitter->GetComponentLocation(); + const FVector Direction = InteractionRayEmitter->GetForwardVector(); + const FVector End = Start + Length * Direction; + + return FTwoVectors(Start, End); +} diff --git a/Source/DisplayClusterExtensions/Private/Pawn/UniversalTrackedComponent.cpp b/Source/DisplayClusterExtensions/Private/Pawn/UniversalTrackedComponent.cpp index 42d47b894c28a494e4e87114de2bb67a955f2f03..cc8e3b2fda6afbd661a991d801e96897f040fd39 100644 --- a/Source/DisplayClusterExtensions/Private/Pawn/UniversalTrackedComponent.cpp +++ b/Source/DisplayClusterExtensions/Private/Pawn/UniversalTrackedComponent.cpp @@ -1,11 +1,11 @@ // Fill out your copyright notice in the Description page of Project Settings. -#include "UniversalTrackedComponent.h" +#include "Pawn/UniversalTrackedComponent.h" #include "Camera/CameraComponent.h" -#include "VirtualRealityUtilities.h" +#include "Utility/VirtualRealityUtilities.h" // Sets default values for this component's properties UUniversalTrackedComponent::UUniversalTrackedComponent() diff --git a/Source/DisplayClusterExtensions/Private/Pawn/VRPawnMovement.cpp b/Source/DisplayClusterExtensions/Private/Pawn/VRPawnMovement.cpp index ec71285feb6c26c91db75c51cac96edaf2b5a562..5cceb96c00fde4c6491cda9c33ac28390e871501 100644 --- a/Source/DisplayClusterExtensions/Private/Pawn/VRPawnMovement.cpp +++ b/Source/DisplayClusterExtensions/Private/Pawn/VRPawnMovement.cpp @@ -1,5 +1,5 @@ -#include "VRPawnMovement.h" +#include "Pawn/VRPawnMovement.h" #include "DrawDebugHelpers.h" UVRPawnMovement::UVRPawnMovement(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer) diff --git a/Source/DisplayClusterExtensions/Private/Pawn/VirtualRealityPawn.cpp b/Source/DisplayClusterExtensions/Private/Pawn/VirtualRealityPawn.cpp index 4d77d4937932ef016edaf5d3f8fe79b5f7fbef17..3a078bd5f53b27d5bc3fee2ad39603edbe821219 100644 --- a/Source/DisplayClusterExtensions/Private/Pawn/VirtualRealityPawn.cpp +++ b/Source/DisplayClusterExtensions/Private/Pawn/VirtualRealityPawn.cpp @@ -1,15 +1,15 @@ // Fill out your copyright notice in the Description page of Project Settings. -#include "VirtualRealityPawn.h" +#include "Pawn/VirtualRealityPawn.h" #include "GameFramework/InputSettings.h" #include "GameFramework/PlayerInput.h" -#include "UniversalTrackedComponent.h" -#include "VirtualRealityUtilities.h" -#include "VRPawnMovement.h" +#include "Pawn/UniversalTrackedComponent.h" +#include "Utility/VirtualRealityUtilities.h" +#include "Pawn/VRPawnMovement.h" AVirtualRealityPawn::AVirtualRealityPawn(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer) diff --git a/Source/DisplayClusterExtensions/Private/Utility/VirtualRealityUtilities.cpp b/Source/DisplayClusterExtensions/Private/Utility/VirtualRealityUtilities.cpp index 3c7d270c51564c42e7923883c033b71c6a7a7c38..d4876cc577c7b041bcae2ec0b9a09ade8cb370be 100644 --- a/Source/DisplayClusterExtensions/Private/Utility/VirtualRealityUtilities.cpp +++ b/Source/DisplayClusterExtensions/Private/Utility/VirtualRealityUtilities.cpp @@ -1,4 +1,4 @@ -#include "VirtualRealityUtilities.h" +#include "Utility/VirtualRealityUtilities.h" #include "Cluster/IDisplayClusterClusterManager.h" #include "Components/DisplayClusterCameraComponent.h" diff --git a/Source/DisplayClusterExtensions/Public/Cluster/Events/DisplayClusterEventWrapper.h b/Source/DisplayClusterExtensions/Public/Cluster/Events/DisplayClusterEventWrapper.h index 3ed716cdd5d9c22a8286058782a5b434a69880ba..8ad2c51f4aaf59efd1a5aee5bc4e417ae165519c 100644 --- a/Source/DisplayClusterExtensions/Public/Cluster/Events/DisplayClusterEventWrapper.h +++ b/Source/DisplayClusterExtensions/Public/Cluster/Events/DisplayClusterEventWrapper.h @@ -1,108 +1,108 @@ -#pragma once - -#include "IDisplayCluster.h" -#include "IDisplayClusterClusterManager.h" -#include "Cluster/DisplayClusterClusterEvent.h" -#include "DisplayClusterEventParameterHelper.h" -#include "Templates/IsInvocable.h" - -template <typename MemberFunctionType, MemberFunctionType MemberFunction> -class ClusterEventWrapperEvent; - -template <typename ObjectType, typename ReturnType, typename... ArgTypes, ReturnType (ObjectType::*MemberFunction)(ArgTypes...)> -class ClusterEventWrapperEvent<ReturnType (ObjectType::*)(ArgTypes...), MemberFunction> -{ - static_assert(TIsDerivedFrom<ObjectType, AActor>::IsDerived, "Object needs to derive from AActor"); - -public: - using MemberFunctionType = decltype(MemberFunction); - - ClusterEventWrapperEvent(const TCHAR* EventTypeName) : EventTypeName{EventTypeName} - { - } - - void Attach(ObjectType* NewObject) - { - IDisplayClusterClusterManager* ClusterManager = IDisplayCluster::Get().GetClusterMgr(); - check(ClusterManager != nullptr); - - checkf(Object == nullptr, TEXT("The event is already attached.")); - Object = NewObject; - ObjectName = AActor::GetDebugName(Object); - - if (!ClusterManager->IsStandalone()) - { - check(!ClusterEventListenerDelegate.IsBound()); - ClusterEventListenerDelegate = FOnClusterEventListener::CreateLambda([this](const FDisplayClusterClusterEvent& Event) { - if (Event.Type == EventTypeName && Event.Name == ObjectName) - { - // Create a tuple that holds all arguments. This assumes that all - // argument types are default constructible. However, all - // types that overload the FArchive "<<" operator probably are. - TTuple<typename TRemoveCV<typename TRemoveReference<ArgTypes>::Type>::Type...> ArgumentTuple; - - // This call will parse the string map and fill all values in the - // tuple appropriately. - FillArgumentTuple<0>(&ArgumentTuple, Event.Parameters); - - ArgumentTuple.ApplyBefore([this](const ArgTypes&... Arguments) { - (Object->*MemberFunction)(Forward<const ArgTypes&>(Arguments)...); - }); - } - }); - ClusterManager->AddClusterEventListener(ClusterEventListenerDelegate); - } - } - - void Detach() - { - checkf(Object != nullptr, TEXT("The event was never attached.")); - - IDisplayClusterClusterManager* ClusterManager = IDisplayCluster::Get().GetClusterMgr(); - check(ClusterManager != nullptr); - - if (!ClusterManager->IsStandalone()) - { - // check(ClusterEventListenerDelegate.IsBound()); - ClusterManager->RemoveClusterEventListener(ClusterEventListenerDelegate); - } - } - - void Send(ArgTypes&&... Arguments) - { - IDisplayClusterClusterManager* ClusterManager = IDisplayCluster::Get().GetClusterMgr(); - check(ClusterManager != nullptr); - - checkf(Object != nullptr, TEXT("The event was not attached.")); - - if (ClusterManager->IsStandalone()) - { - (Object->*MemberFunction)(Forward<ArgTypes>(Arguments)...); - } - else - { - FDisplayClusterClusterEvent ClusterEvent; - ClusterEvent.Category = "DisplayClusterEventWrapper"; - ClusterEvent.Type = EventTypeName; - ClusterEvent.Name = ObjectName; - ClusterEvent.Parameters = CreateParameterMap(Forward<ArgTypes>(Arguments)...); - - ClusterManager->EmitClusterEvent(ClusterEvent, true); - } - } - -private: - const TCHAR* EventTypeName; - ObjectType* Object = nullptr; - FString ObjectName; - FOnClusterEventListener ClusterEventListenerDelegate; -}; - -#define DCEW_STRINGIFY(x) #x -#define DCEW_TOSTRING(x) DCEW_STRINGIFY(x) - -#define DECLARE_DISPLAY_CLUSTER_EVENT(OwningType, MethodIdentifier) \ - ClusterEventWrapperEvent<decltype(&OwningType::MethodIdentifier), &OwningType::MethodIdentifier> MethodIdentifier##Event \ - { \ - TEXT(DCEW_TOSTRING(OwningType) DCEW_TOSTRING(MethodIdentifier)) \ - } +#pragma once + +#include "IDisplayCluster.h" +#include "Cluster/IDisplayClusterClusterManager.h" +#include "Cluster/DisplayClusterClusterEvent.h" +#include "DisplayClusterEventParameterHelper.h" +#include "Templates/IsInvocable.h" + +template <typename MemberFunctionType, MemberFunctionType MemberFunction> +class ClusterEventWrapperEvent; + +template <typename ObjectType, typename ReturnType, typename... ArgTypes, ReturnType (ObjectType::*MemberFunction)(ArgTypes...)> +class ClusterEventWrapperEvent<ReturnType (ObjectType::*)(ArgTypes...), MemberFunction> +{ + static_assert(TIsDerivedFrom<ObjectType, AActor>::IsDerived, "Object needs to derive from AActor"); + +public: + using MemberFunctionType = decltype(MemberFunction); + + ClusterEventWrapperEvent(const TCHAR* EventTypeName) : EventTypeName{EventTypeName} + { + } + + void Attach(ObjectType* NewObject) + { + IDisplayClusterClusterManager* ClusterManager = IDisplayCluster::Get().GetClusterMgr(); + check(ClusterManager != nullptr); + + checkf(Object == nullptr, TEXT("The event is already attached.")); + Object = NewObject; + ObjectName = AActor::GetDebugName(Object); + + if (!ClusterManager->IsStandalone()) + { + check(!ClusterEventListenerDelegate.IsBound()); + ClusterEventListenerDelegate = FOnClusterEventListener::CreateLambda([this](const FDisplayClusterClusterEvent& Event) { + if (Event.Type == EventTypeName && Event.Name == ObjectName) + { + // Create a tuple that holds all arguments. This assumes that all + // argument types are default constructible. However, all + // types that overload the FArchive "<<" operator probably are. + TTuple<typename TRemoveCV<typename TRemoveReference<ArgTypes>::Type>::Type...> ArgumentTuple; + + // This call will parse the string map and fill all values in the + // tuple appropriately. + FillArgumentTuple<0>(&ArgumentTuple, Event.Parameters); + + ArgumentTuple.ApplyBefore([this](const ArgTypes&... Arguments) { + (Object->*MemberFunction)(Forward<const ArgTypes&>(Arguments)...); + }); + } + }); + ClusterManager->AddClusterEventListener(ClusterEventListenerDelegate); + } + } + + void Detach() + { + checkf(Object != nullptr, TEXT("The event was never attached.")); + + IDisplayClusterClusterManager* ClusterManager = IDisplayCluster::Get().GetClusterMgr(); + check(ClusterManager != nullptr); + + if (!ClusterManager->IsStandalone()) + { + // check(ClusterEventListenerDelegate.IsBound()); + ClusterManager->RemoveClusterEventListener(ClusterEventListenerDelegate); + } + } + + void Send(ArgTypes&&... Arguments) + { + IDisplayClusterClusterManager* ClusterManager = IDisplayCluster::Get().GetClusterMgr(); + check(ClusterManager != nullptr); + + checkf(Object != nullptr, TEXT("The event was not attached.")); + + if (ClusterManager->IsStandalone()) + { + (Object->*MemberFunction)(Forward<ArgTypes>(Arguments)...); + } + else + { + FDisplayClusterClusterEvent ClusterEvent; + ClusterEvent.Category = "DisplayClusterEventWrapper"; + ClusterEvent.Type = EventTypeName; + ClusterEvent.Name = ObjectName; + ClusterEvent.Parameters = CreateParameterMap(Forward<ArgTypes>(Arguments)...); + + ClusterManager->EmitClusterEvent(ClusterEvent, true); + } + } + +private: + const TCHAR* EventTypeName; + ObjectType* Object = nullptr; + FString ObjectName; + FOnClusterEventListener ClusterEventListenerDelegate; +}; + +#define DCEW_STRINGIFY(x) #x +#define DCEW_TOSTRING(x) DCEW_STRINGIFY(x) + +#define DECLARE_DISPLAY_CLUSTER_EVENT(OwningType, MethodIdentifier) \ + ClusterEventWrapperEvent<decltype(&OwningType::MethodIdentifier), &OwningType::MethodIdentifier> MethodIdentifier##Event \ + { \ + TEXT(DCEW_TOSTRING(OwningType) DCEW_TOSTRING(MethodIdentifier)) \ + } diff --git a/Source/DisplayClusterExtensions/Public/DisplayClusterExtensions.h b/Source/DisplayClusterExtensions/Public/DisplayClusterExtensions.h index 4ce11fec96a4e0e47b897569e5e606336f5c1b17..ae1839f647feb393918dc4f7e3a078551ad0791f 100644 --- a/Source/DisplayClusterExtensions/Public/DisplayClusterExtensions.h +++ b/Source/DisplayClusterExtensions/Public/DisplayClusterExtensions.h @@ -1,7 +1,7 @@ #pragma once #include "CoreMinimal.h" -#include "FixNDisplayStereoDevice.h" +#include "Fixes/FixNDisplayStereoDevice.h" #include "Modules/ModuleManager.h" diff --git a/Source/DisplayClusterExtensions/Public/Pawn/VirtualRealityPawn.h b/Source/DisplayClusterExtensions/Public/Pawn/VirtualRealityPawn.h index d23192d53239a120136bcfb59c3044b5f7c72a67..d729c7dbf659d14414f3b1bfe69ca25afdf6f708 100644 --- a/Source/DisplayClusterExtensions/Public/Pawn/VirtualRealityPawn.h +++ b/Source/DisplayClusterExtensions/Public/Pawn/VirtualRealityPawn.h @@ -5,7 +5,6 @@ #include "BasicVRInteractionComponent.h" #include "CoreMinimal.h" #include "GameFramework/DefaultPawn.h" -#include "GameFramework/RotatingMovementComponent.h" #include "UniversalTrackedComponent.h" #include "VRPawnMovement.h" #include "VirtualRealityPawn.generated.h" diff --git a/Source/DisplayClusterExtensionsEditor/Private/DisplayClusterExtensionsEditor.cpp b/Source/DisplayClusterExtensionsEditor/Private/DisplayClusterExtensionsEditor.cpp index 22fcd5862b5a97353cc8ca08990999095d7ce25f..bc1dccee6411aa6937d246ee3abe02262762a8e2 100644 --- a/Source/DisplayClusterExtensionsEditor/Private/DisplayClusterExtensionsEditor.cpp +++ b/Source/DisplayClusterExtensionsEditor/Private/DisplayClusterExtensionsEditor.cpp @@ -1,48 +1,48 @@ -#include "DisplayClusterExtensionsEditor.h" - -#include "ComponentVisualizers.h" -#include "GrabbingBehaviorOnLineVisualizer.h" -#include "GrabbingBehaviorPlaneVisualizer.h" - -#include "GrabbingBehaviorOnPlaneComponent.h" -#include "GrabbingBehaviorOnLineComponent.h" - -#include "UnrealEdGlobals.h" -#include "Editor/UnrealEdEngine.h" - -IMPLEMENT_GAME_MODULE(FDisplayClusterExtensionsEditorModule, DisplayClusterExtensionsEditor); - -#define LOCTEXT_NAMESPACE "DisplayClusterExtensionsEdito" - -void FDisplayClusterExtensionsEditorModule::StartupModule() -{ - if (GUnrealEd != NULL) - { - TSharedPtr<FComponentVisualizer> LineVisualizer = MakeShareable(new FGrabbingBehaviorOnLineVisualizer()); - - if (LineVisualizer.IsValid()) - { - GUnrealEd->RegisterComponentVisualizer(UGrabbingBehaviorOnLineComponent::StaticClass()->GetFName(), LineVisualizer); - LineVisualizer->OnRegister(); - } - - TSharedPtr<FComponentVisualizer> PlaneVisualizer = MakeShareable(new FGrabbingBehaviorPlaneVisualizer()); - - if (PlaneVisualizer.IsValid()) - { - GUnrealEd->RegisterComponentVisualizer(UGrabbingBehaviorOnPlaneComponent::StaticClass()->GetFName(), PlaneVisualizer); - PlaneVisualizer->OnRegister(); - } - } -} - -void FDisplayClusterExtensionsEditorModule::ShutdownModule() -{ - if (GUnrealEd != NULL) - { - GUnrealEd->UnregisterComponentVisualizer(UGrabbingBehaviorOnLineComponent::StaticClass()->GetFName()); - GUnrealEd->UnregisterComponentVisualizer(UGrabbingBehaviorOnPlaneComponent::StaticClass()->GetFName()); - } -} - +#include "DisplayClusterExtensionsEditor.h" + +#include "ComponentVisualizers.h" +#include "Interaction/GrabbingBehaviorOnLineVisualizer.h" +#include "Interaction/GrabbingBehaviorPlaneVisualizer.h" + +#include "Interaction/GrabbingBehaviorOnPlaneComponent.h" +#include "Interaction/GrabbingBehaviorOnLineComponent.h" + +#include "UnrealEdGlobals.h" +#include "Editor/UnrealEdEngine.h" + +IMPLEMENT_GAME_MODULE(FDisplayClusterExtensionsEditorModule, DisplayClusterExtensionsEditor); + +#define LOCTEXT_NAMESPACE "DisplayClusterExtensionsEdito" + +void FDisplayClusterExtensionsEditorModule::StartupModule() +{ + if (GUnrealEd != NULL) + { + TSharedPtr<FComponentVisualizer> LineVisualizer = MakeShareable(new FGrabbingBehaviorOnLineVisualizer()); + + if (LineVisualizer.IsValid()) + { + GUnrealEd->RegisterComponentVisualizer(UGrabbingBehaviorOnLineComponent::StaticClass()->GetFName(), LineVisualizer); + LineVisualizer->OnRegister(); + } + + TSharedPtr<FComponentVisualizer> PlaneVisualizer = MakeShareable(new FGrabbingBehaviorPlaneVisualizer()); + + if (PlaneVisualizer.IsValid()) + { + GUnrealEd->RegisterComponentVisualizer(UGrabbingBehaviorOnPlaneComponent::StaticClass()->GetFName(), PlaneVisualizer); + PlaneVisualizer->OnRegister(); + } + } +} + +void FDisplayClusterExtensionsEditorModule::ShutdownModule() +{ + if (GUnrealEd != NULL) + { + GUnrealEd->UnregisterComponentVisualizer(UGrabbingBehaviorOnLineComponent::StaticClass()->GetFName()); + GUnrealEd->UnregisterComponentVisualizer(UGrabbingBehaviorOnPlaneComponent::StaticClass()->GetFName()); + } +} + #undef LOCTEXT_NAMESPACE \ No newline at end of file diff --git a/Source/DisplayClusterExtensionsEditor/Private/Interaction/GrabbingBehaviorOnLineVisualizer.cpp b/Source/DisplayClusterExtensionsEditor/Private/Interaction/GrabbingBehaviorOnLineVisualizer.cpp index 27fee70ab128be1dbc83ca76a191ac3e531f1efe..3cc4699ef9bac5e7415dcb0bece71552e5122117 100644 --- a/Source/DisplayClusterExtensionsEditor/Private/Interaction/GrabbingBehaviorOnLineVisualizer.cpp +++ b/Source/DisplayClusterExtensionsEditor/Private/Interaction/GrabbingBehaviorOnLineVisualizer.cpp @@ -1,35 +1,35 @@ -// Fill out your copyright notice in the Description page of Project Settings. - - -#include "GrabbingBehaviorOnLineVisualizer.h" -#include "GrabbingBehaviorOnLineComponent.h" - -#include "SceneManagement.h" - -FGrabbingBehaviorOnLineVisualizer::FGrabbingBehaviorOnLineVisualizer() -{ -} - -FGrabbingBehaviorOnLineVisualizer::~FGrabbingBehaviorOnLineVisualizer() -{ -} - - -// Fill out your copyright notice in the Description page of Project Settings. - -void FGrabbingBehaviorOnLineVisualizer::DrawVisualization(const UActorComponent* Component, const FSceneView* View, FPrimitiveDrawInterface* PDI) { - - - const UGrabbingBehaviorOnLineComponent* LineBehavior = Cast<const UGrabbingBehaviorOnLineComponent>(Component); - - if (LineBehavior != nullptr) - { - FVector Attachment = LineBehavior->GetComponentLocation(); - FVector Forward = LineBehavior->GetComponentQuat().GetUpVector(); - float Distance = LineBehavior->GetDistance(); - - PDI->DrawLine(Attachment + Forward * Distance, Attachment - Forward * Distance, FColor::Blue, SDPG_World); - } -} - - +// Fill out your copyright notice in the Description page of Project Settings. + + +#include "Interaction/GrabbingBehaviorOnLineVisualizer.h" +#include "Interaction/GrabbingBehaviorOnLineComponent.h" + +#include "SceneManagement.h" + +FGrabbingBehaviorOnLineVisualizer::FGrabbingBehaviorOnLineVisualizer() +{ +} + +FGrabbingBehaviorOnLineVisualizer::~FGrabbingBehaviorOnLineVisualizer() +{ +} + + +// Fill out your copyright notice in the Description page of Project Settings. + +void FGrabbingBehaviorOnLineVisualizer::DrawVisualization(const UActorComponent* Component, const FSceneView* View, FPrimitiveDrawInterface* PDI) { + + + const UGrabbingBehaviorOnLineComponent* LineBehavior = Cast<const UGrabbingBehaviorOnLineComponent>(Component); + + if (LineBehavior != nullptr) + { + FVector Attachment = LineBehavior->GetComponentLocation(); + FVector Forward = LineBehavior->GetComponentQuat().GetUpVector(); + float Distance = LineBehavior->GetDistance(); + + PDI->DrawLine(Attachment + Forward * Distance, Attachment - Forward * Distance, FColor::Blue, SDPG_World); + } +} + + diff --git a/Source/DisplayClusterExtensionsEditor/Private/Interaction/GrabbingBehaviorPlaneVisualizer.cpp b/Source/DisplayClusterExtensionsEditor/Private/Interaction/GrabbingBehaviorPlaneVisualizer.cpp index 455e62ce23a46d09f771097bbac41c61a1c54bba..d2c940b6893374378ce7f41fa3d8dfa5449932fc 100644 --- a/Source/DisplayClusterExtensionsEditor/Private/Interaction/GrabbingBehaviorPlaneVisualizer.cpp +++ b/Source/DisplayClusterExtensionsEditor/Private/Interaction/GrabbingBehaviorPlaneVisualizer.cpp @@ -1,43 +1,43 @@ -// Fill out your copyright notice in the Description page of Project Settings. - - -#include "GrabbingBehaviorPlaneVisualizer.h" -#include "GrabbingBehaviorOnPlaneComponent.h" -#include "SceneManagement.h" - -FGrabbingBehaviorPlaneVisualizer::FGrabbingBehaviorPlaneVisualizer() -{ -} - -FGrabbingBehaviorPlaneVisualizer::~FGrabbingBehaviorPlaneVisualizer() -{ -} - -void FGrabbingBehaviorPlaneVisualizer::DrawVisualization(const UActorComponent* Component, const FSceneView* View, FPrimitiveDrawInterface* PDI) { - - - const UGrabbingBehaviorOnPlaneComponent* PlaneBehavior = Cast<const UGrabbingBehaviorOnPlaneComponent>(Component); - - if (PlaneBehavior != nullptr) - { - FVector Attachment = PlaneBehavior->GetComponentLocation(); - FVector Forward = PlaneBehavior->GetComponentQuat().GetUpVector(); - FVector Right = PlaneBehavior->GetComponentQuat().GetRightVector(); - FVector Next; - Right.Normalize(); - - - float Distance = PlaneBehavior->GetDistance(); - int Segments = 60; - check(360% Segments == 0 && "circle cannot be divided equally"); - - for (int i = 1; i < Segments + 1; i++) // draw circle using lines - { - Next = Right.RotateAngleAxis(360/Segments, Forward); - - PDI->DrawLine(Attachment + Right*Distance,Attachment + Next*Distance, FColor::Blue, SDPG_World); - Right = Next; - } - } -} - +// Fill out your copyright notice in the Description page of Project Settings. + + +#include "Interaction/GrabbingBehaviorPlaneVisualizer.h" +#include "Interaction/GrabbingBehaviorOnPlaneComponent.h" +#include "SceneManagement.h" + +FGrabbingBehaviorPlaneVisualizer::FGrabbingBehaviorPlaneVisualizer() +{ +} + +FGrabbingBehaviorPlaneVisualizer::~FGrabbingBehaviorPlaneVisualizer() +{ +} + +void FGrabbingBehaviorPlaneVisualizer::DrawVisualization(const UActorComponent* Component, const FSceneView* View, FPrimitiveDrawInterface* PDI) { + + + const UGrabbingBehaviorOnPlaneComponent* PlaneBehavior = Cast<const UGrabbingBehaviorOnPlaneComponent>(Component); + + if (PlaneBehavior != nullptr) + { + FVector Attachment = PlaneBehavior->GetComponentLocation(); + FVector Forward = PlaneBehavior->GetComponentQuat().GetUpVector(); + FVector Right = PlaneBehavior->GetComponentQuat().GetRightVector(); + FVector Next; + Right.Normalize(); + + + float Distance = PlaneBehavior->GetDistance(); + int Segments = 60; + check(360% Segments == 0 && "circle cannot be divided equally"); + + for (int i = 1; i < Segments + 1; i++) // draw circle using lines + { + Next = Right.RotateAngleAxis(360/Segments, Forward); + + PDI->DrawLine(Attachment + Right*Distance,Attachment + Next*Distance, FColor::Blue, SDPG_World); + Right = Next; + } + } +} +