From fedc7a3da57d8742b194c95f0fb06e304e3212c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20Kr=C3=BCger?= <krueger@vr.rwth-aachen.de> Date: Fri, 11 Jun 2021 10:31:25 +0000 Subject: [PATCH] Remove IntersectionRay reference --- .../Public/Pawn/BasicVRInteractionComponent.h | 127 +++++++++--------- 1 file changed, 63 insertions(+), 64 deletions(-) diff --git a/Source/DisplayClusterExtensions/Public/Pawn/BasicVRInteractionComponent.h b/Source/DisplayClusterExtensions/Public/Pawn/BasicVRInteractionComponent.h index bf02488..893c9fd 100644 --- a/Source/DisplayClusterExtensions/Public/Pawn/BasicVRInteractionComponent.h +++ b/Source/DisplayClusterExtensions/Public/Pawn/BasicVRInteractionComponent.h @@ -1,64 +1,63 @@ -// Fill out your copyright notice in the Description page of Project Settings. - -#pragma once - -#include "CoreMinimal.h" -#include "Components/ActorComponent.h" -#include "BasicVRInteractionComponent.generated.h" - -class UGrabbingBehaviorComponent; - - -UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) ) -class DISPLAYCLUSTEREXTENSIONS_API UBasicVRInteractionComponent : public UActorComponent -{ - GENERATED_BODY() - -public: - // Sets default values for this component's properties - UBasicVRInteractionComponent(); - - UFUNCTION(BlueprintCallable) void BeginInteraction(); - UFUNCTION(BlueprintCallable) void EndInteraction(); - - // Called every frame - virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override; - - UPROPERTY(BlueprintReadWrite) float MaxGrabDistance = 50; - UPROPERTY(BlueprintReadWrite) float MaxClickDistance = 500; - // Enable this if you want to interact with Targetable classes - UPROPERTY(EditAnywhere) bool bCanRaytraceEveryTick = false; - - UFUNCTION(BlueprintCallable) void Initialize(USceneComponent* RayEmitter, float InMaxGrabDistance = 50, float InMaxClickDistance = 500); - - UFUNCTION(BlueprintCallable, BlueprintPure) AActor* GetGrabbedActor() const { return GrabbedActor;} - UFUNCTION(BlueprintCallable, BlueprintPure) USceneComponent* GetInteractionRayEmitter() const { return InteractionRayEmitter; } -private: - /* Holding a reference to the actor that is currently being grabbed */ - UPROPERTY() AActor* GrabbedActor; - /* Holds a reference to the grabbed actors physics simulating component if there was one*/ - UPROPERTY() UPrimitiveComponent* ComponentSimulatingPhysics = nullptr; - UPROPERTY() UGrabbingBehaviorComponent* Behavior = nullptr; - UPROPERTY() USceneComponent* InteractionRayEmitter = nullptr; - UPROPERTY() UStaticMeshComponent* InteractionRay = nullptr; - /* Stores the reference of the Actor that was hit in the last frame*/ - UPROPERTY() AActor* LastActorHit = nullptr; - void HandlePhysicsAndAttachActor(AActor* HitActor); - FTwoVectors GetHandRay(float Length) const; - TOptional<FHitResult> RaytraceForFirstHit(const FTwoVectors& Ray) const; -}; - -// Free utility functions -/* - Returns the UPrimitiveComponent simulating physics that is highest in the hierarchy -*/ -UPrimitiveComponent* GetFirstComponentSimulatingPhysics(const AActor* TargetActor); -/* - Recursive Function - If parent component simulates physics returns GetHighestParentSimulatingPhysics(Parent) - else returns Comp itself -*/ -UPrimitiveComponent* GetHighestParentSimulatingPhysics(UPrimitiveComponent* Comp); - - - +// Fill out your copyright notice in the Description page of Project Settings. + +#pragma once + +#include "CoreMinimal.h" +#include "Components/ActorComponent.h" +#include "BasicVRInteractionComponent.generated.h" + +class UGrabbingBehaviorComponent; + + +UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) ) +class DISPLAYCLUSTEREXTENSIONS_API UBasicVRInteractionComponent : public UActorComponent +{ + GENERATED_BODY() + +public: + // Sets default values for this component's properties + UBasicVRInteractionComponent(); + + UFUNCTION(BlueprintCallable) void BeginInteraction(); + UFUNCTION(BlueprintCallable) void EndInteraction(); + + // Called every frame + virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override; + + UPROPERTY(BlueprintReadWrite) float MaxGrabDistance = 50; + UPROPERTY(BlueprintReadWrite) float MaxClickDistance = 500; + // Enable this if you want to interact with Targetable classes + UPROPERTY(EditAnywhere) bool bCanRaytraceEveryTick = false; + + UFUNCTION(BlueprintCallable) void Initialize(USceneComponent* RayEmitter, float InMaxGrabDistance = 50, float InMaxClickDistance = 500); + + UFUNCTION(BlueprintCallable, BlueprintPure) AActor* GetGrabbedActor() const { return GrabbedActor;} + UFUNCTION(BlueprintCallable, BlueprintPure) USceneComponent* GetInteractionRayEmitter() const { return InteractionRayEmitter; } +private: + /* Holding a reference to the actor that is currently being grabbed */ + UPROPERTY() AActor* GrabbedActor; + /* Holds a reference to the grabbed actors physics simulating component if there was one*/ + UPROPERTY() UPrimitiveComponent* ComponentSimulatingPhysics = nullptr; + UPROPERTY() UGrabbingBehaviorComponent* Behavior = nullptr; + UPROPERTY() USceneComponent* InteractionRayEmitter = nullptr; + /* Stores the reference of the Actor that was hit in the last frame*/ + UPROPERTY() AActor* LastActorHit = nullptr; + void HandlePhysicsAndAttachActor(AActor* HitActor); + FTwoVectors GetHandRay(float Length) const; + TOptional<FHitResult> RaytraceForFirstHit(const FTwoVectors& Ray) const; +}; + +// Free utility functions +/* + Returns the UPrimitiveComponent simulating physics that is highest in the hierarchy +*/ +UPrimitiveComponent* GetFirstComponentSimulatingPhysics(const AActor* TargetActor); +/* + Recursive Function + If parent component simulates physics returns GetHighestParentSimulatingPhysics(Parent) + else returns Comp itself +*/ +UPrimitiveComponent* GetHighestParentSimulatingPhysics(UPrimitiveComponent* Comp); + + + -- GitLab