From aba2e4daf58e47972ffde52710df8f191d390579 Mon Sep 17 00:00:00 2001
From: mmeierkrueger <marius.meier-krueger@rwth-aachen.de>
Date: Thu, 24 Nov 2022 11:00:35 +0100
Subject: [PATCH] removed comments & debug content
---
.../GrabbingBehaviorOnPlaneComponent.cpp | 58 ++++---------------
.../GrabbingBehaviorOnPlaneComponent.h | 5 +-
2 files changed, 12 insertions(+), 51 deletions(-)
diff --git a/Source/RWTHVRToolkit/Private/Interaction/GrabbingBehaviorOnPlaneComponent.cpp b/Source/RWTHVRToolkit/Private/Interaction/GrabbingBehaviorOnPlaneComponent.cpp
index 9c895a7e..dde4079b 100644
--- a/Source/RWTHVRToolkit/Private/Interaction/GrabbingBehaviorOnPlaneComponent.cpp
+++ b/Source/RWTHVRToolkit/Private/Interaction/GrabbingBehaviorOnPlaneComponent.cpp
@@ -40,23 +40,17 @@ void UGrabbingBehaviorOnPlaneComponent::HandleNewPositionAndDirection(FVector Po
FVector Intersection = FMath::LinePlaneIntersection(Position, Position + Direction, AttachmentPoint, PlaneNormal);
if(bShouldSnapToRayEnd == true)
{
- //DrawDebugSphere(GetWorld(), Intersection, 10, 5, FColor::Purple, false, 10);
- //DrawDebugSphere(GetWorld(), Intersection.GetClampedToMaxSize(MaxDistance), 10, 5, FColor::Red, false, 10);
- //DrawDebugSphere(GetWorld(), GetComponentLocation(), 15, 5, FColor::Black, false, 10);
-
+ //GetNewPos
FVector NewPosition = -AttachmentPoint + Intersection;
+
// clamp size by maxDistance
- //DrawDebugSphere(GetWorld(), NewPosition, 10, 5, FColor::Green, false, 10);
-
NewPosition = NewPosition.GetClampedToMaxSize(MaxDistance);
- //DrawDebugSphere(GetWorld(), NewPosition, 10, 5, FColor::Red, false, 10);
+
// after this NewPoint is in world position
NewPosition += AttachmentPoint;
- //DrawDebugSphere(GetWorld(), NewPosition, 10 , 5, FColor::Magenta, false, 10);
- // set new position and orientation using calculated quaternion and position
- // here rotation is not changed
- GetOwner()->SetActorLocation(NewPosition);
+ //Set new location
+ GetOwner()->SetActorLocation(NewPosition);
}
else if(bShouldSnapToRayEnd == false)
{
@@ -85,52 +79,30 @@ void UGrabbingBehaviorOnPlaneComponent::HandleNewPositionAndDirection(FVector Po
if(MaxDistance >= 0)
{
//TODO clamp this and add to original position
- float DistanceFromOrigin = FVector::Dist(PointOnConstrainPlane, OriginalPosition); // PointOnConstrainPlane - OriginalPosition;
- PointAsVector = PointOnConstrainPlane - OriginalPosition;
- //DrawDebugSphere(GetWorld(), PointAsVector, 30, 5, FColor::Magenta, false, 10);
- //DrawDebugSphere(GetWorld(), PointOnConstrainPlane, 30, 5, FColor::Blue, false, 10);
- //DrawDebugSphere(GetWorld(), PointOnConstrainPlane.GetClampedToMaxSize(MaxDistance), 30, 30, FColor::Cyan, false, 10);
-
-
- //UE_LOG(LogTemp, Warning, TEXT("DistanceFromOrigin = %f"), DistanceFromOrigin);
+ float const DistanceFromOrigin = FVector::Dist(PointOnConstrainPlane, OriginalPosition); // PointOnConstrainPlane - OriginalPosition;
+ PointAsVector = PointOnConstrainPlane - OriginalPosition;
+
if (DistanceFromOrigin > MaxDistance)
{
-
- //UE_LOG(LogTemp, Error, TEXT("Distance too large"));
-
- //PointOnConstrainPlane = PointOnConstrainPlane.GetClampedToMaxSize(MaxDistance);
- //DrawDebugSphere(GetWorld(), PointAsVector, 30, 5, FColor::Green, false, 10);
FVector ClampedVector = PointAsVector.GetClampedToMaxSize(MaxDistance);
+ //Correct Vector position since clamping moves it to world origin
FVector OffsetForNewPos = ClampedVector - PointAsVector;
- //PointAsVector += GetComponentLocation();
- //DrawDebugSphere(GetWorld(), PointAsVector, 30, 5, FColor::Red, false, 10);
-
-
+
GetOwner()->SetActorLocation(PointOnConstrainPlane + OffsetForNewPos);
}
else
{
GetOwner()->SetActorLocation(PointOnConstrainPlane);
}
-
-
-
}
else
{
- //UE_LOG(LogTemp, Warning, TEXT("No Distance Limit found"));
+ //if MaxDistance == -1 (no limitations)
GetOwner()->SetActorLocation(PointOnConstrainPlane);
}
-
- //GetOwner()->SetActorLocation(PointOnConstrainPlane);
this->SetRelativeLocation(GetOwner()->GetActorLocation());
-
}
}
-
-
- //UE_LOG(LogTemp, Warning, TEXT("Owner = %s"), *GetOwner()->GetName());
- //this->SetWorldLocation(GetOwner()->GetActorLocation());
}
@@ -139,10 +111,6 @@ void UGrabbingBehaviorOnPlaneComponent::BeginPlay()
{
Super::BeginPlay();
SetWorldLocation(GetOwner()->GetActorLocation(), false);
-
-
- // ...
-
}
@@ -150,9 +118,5 @@ void UGrabbingBehaviorOnPlaneComponent::BeginPlay()
void UGrabbingBehaviorOnPlaneComponent::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
{
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
-
-
- // ...
-
}
diff --git a/Source/RWTHVRToolkit/Public/Interaction/GrabbingBehaviorOnPlaneComponent.h b/Source/RWTHVRToolkit/Public/Interaction/GrabbingBehaviorOnPlaneComponent.h
index 8cd5b45e..fb782951 100644
--- a/Source/RWTHVRToolkit/Public/Interaction/GrabbingBehaviorOnPlaneComponent.h
+++ b/Source/RWTHVRToolkit/Public/Interaction/GrabbingBehaviorOnPlaneComponent.h
@@ -35,8 +35,5 @@ private:
UPROPERTY(EditAnywhere) float MaxDistance = -1; // distance the object can be moved from the center. -1 for no limit
UPROPERTY() FPlane ConstraintPlane; //the plane on which the parent actor is allowed to move
UPROPERTY() FPlane InteractionPlane; // the same plane as the ConstraintPlane, but shifted onto the intersection point of the parent object and the interaction ray
- UPROPERTY() FVector OffsetToParentLocation;
-
-
-
+ UPROPERTY() FVector OffsetToParentLocation; //Vector describing the offset between the interaction point of the object and its center
};
--
GitLab