From c7770f8161da8dea9243ddfd2660a6604ab10e8e Mon Sep 17 00:00:00 2001
From: Sebastian Pape <Sebastian.Pape@rwth-aachen.de>
Date: Fri, 2 Aug 2019 15:38:13 +0200
Subject: [PATCH] Changed moving to attachment. Fixed attachment and forced
 door position to be in the correct side. Rebound function to Action1 instead
 of DisplayClusterAction1

---
 .../Private/CAVEOverlayController.cpp         | 21 ++++++++++++-------
 .../Public/CAVEOverlayController.h            |  1 +
 2 files changed, 15 insertions(+), 7 deletions(-)

diff --git a/Source/CAVEOverlay/Private/CAVEOverlayController.cpp b/Source/CAVEOverlay/Private/CAVEOverlayController.cpp
index d10d2db..d859093 100644
--- a/Source/CAVEOverlay/Private/CAVEOverlayController.cpp
+++ b/Source/CAVEOverlay/Private/CAVEOverlayController.cpp
@@ -156,7 +156,7 @@ void ACAVEOverlayController::BeginPlay()
 	if (!display_cluster_mode_) return; // Not our business
 
 	//Actor config
-	InputComponent->BindAction("DisplayClusterAction1", EInputEvent::IE_Pressed, this, &ACAVEOverlayController::CycleDoorType);
+	InputComponent->BindAction("Action1", EInputEvent::IE_Pressed, this, &ACAVEOverlayController::CycleDoorType);
 	InputComponent->BindKey(EKeys::F10, EInputEvent::IE_Pressed, this, &ACAVEOverlayController::CycleDoorType);
 
 	//Determine the screentype for later usage
@@ -180,15 +180,20 @@ void ACAVEOverlayController::BeginPlay()
 
 	player_pawn_ = Cast<AVirtualRealityPawn>(GetWorld()->GetFirstPlayerController()->GetPawn());
 	refreshPawnComponents();
+
+	if (!attached_ && cave_origin_) {
+		AttachToComponent(cave_origin_, FAttachmentTransformRules::SnapToTargetNotIncludingScale);
+		attached_ = true;
+	}
 }
 
 float ACAVEOverlayController::calculateOpacityFromPosition(FVector position) {
-	return FMath::Clamp(((FVector2D(position).GetAbs() - FVector2D(wall_distance_ - wall_close_distance_, wall_distance_ - wall_close_distance_)) / wall_fade_distance_).GetAbsMax(), 0.0f, 1.0f);
+	return 1 - FMath::Clamp(((FVector2D(position).GetAbs() - FVector2D(wall_distance_ - wall_close_distance_, wall_distance_ - wall_close_distance_)) / wall_fade_distance_).GetAbsMax(), 0.0f, 1.0f);
 }
 
 bool ACAVEOverlayController::positionInDoorOpening(FVector position) {
-	return FMath::IsWithinInclusive(position.X, wall_distance_ + 10 - 20 - wall_close_distance_, wall_distance_ + 10) //Overlap both sides 10cm
-		&& FMath::IsWithinInclusive(position.Y, wall_distance_ + 10 - door_current_opening_width_absolute_, wall_distance_ + 10); //Overlap one side 10cm
+	return FMath::IsWithinInclusive(-position.X, wall_distance_ + 10 - 20 - wall_close_distance_, wall_distance_ + 10) //Overlap both sides 10cm
+		&& FMath::IsWithinInclusive(-position.Y, wall_distance_ + 10 - door_current_opening_width_absolute_, wall_distance_ + 10); //Overlap one side 10cm
 }
 
 void ACAVEOverlayController::refreshPawnComponents(){
@@ -208,10 +213,12 @@ void ACAVEOverlayController::Tick(float DeltaTime)
 	if (!display_cluster_mode_) return; // Not our business
 
 	refreshPawnComponents();
-	if (!cave_origin_ || !shutter_glasses_) return; //Display Cluster not initialized
+	if (!attached_ && cave_origin_) {
+		AttachToComponent(cave_origin_, FAttachmentTransformRules::SnapToTargetNotIncludingScale);
+		attached_ = true;
+	}
 
-	//Move complete actor around
-	SetActorLocationAndRotation(cave_origin_->GetComponentLocation(), cave_origin_->GetComponentQuat());
+	if (!shutter_glasses_) return; //Display Cluster not initialized
 
 	//Tape Logic
 	FVector shutter_position = shutter_glasses_->GetRelativeTransform().GetLocation();
diff --git a/Source/CAVEOverlay/Public/CAVEOverlayController.h b/Source/CAVEOverlay/Public/CAVEOverlayController.h
index 89679d1..08a7110 100644
--- a/Source/CAVEOverlay/Public/CAVEOverlayController.h
+++ b/Source/CAVEOverlay/Public/CAVEOverlayController.h
@@ -72,6 +72,7 @@ private:
 	bool positionInDoorOpening(FVector position);
 
 	//Pawn Components
+	bool attached_ = false;
 	void refreshPawnComponents();
 	AVirtualRealityPawn* player_pawn_;
 	UDisplayClusterSceneComponent* cave_origin_;
-- 
GitLab