Skip to content
Snippets Groups Projects
Select Git revision
  • a5dc8c43b44425eedcdbde56230e2d9181fc51e1
  • develop default protected
  • 5.5
  • 5.1
  • master protected
  • deprecated/4-22
6 results

IUniversalLogging.h

Blame
  • GrabbingBehaviorOnPlaneComponent.cpp 1.25 KiB
    // Fill out your copyright notice in the Description page of Project Settings.
    //TODO rename distance to maxDistance
    
    #include "Interaction/GrabbingBehaviorOnPlaneComponent.h"
    
    void UGrabbingBehaviorOnPlaneComponent::SetDistance(float Dist)
    {
    	check(Dist > 0 && "max distance has to be greater than 0");
    	this->Distance = Dist;
    }
    
    float UGrabbingBehaviorOnPlaneComponent::GetDistance() const
    {
    	return this->Distance;
    }
    
    void UGrabbingBehaviorOnPlaneComponent::HandleGrabHold(FVector Position, FQuat Orientation)
    {
    	FVector AttachmentPoint = this->GetRelativeLocation();
    	FVector PlaneNormal = this->GetComponentQuat().GetUpVector();
    	FVector Direction = Orientation.GetForwardVector();
    
    	// calculate point on plane which is pointed to by hand ray
    	FVector Intersection = FMath::LinePlaneIntersection(Position, Position + Direction, AttachmentPoint, PlaneNormal);
    	FVector NewPosition = -AttachmentPoint + Intersection;
    
    	// clamp size by maxDistance
    	NewPosition = NewPosition.GetClampedToMaxSize(Distance);
    
    	// after this NewPoint is in world position
    	NewPosition += AttachmentPoint;
    
    	// set new position and orientation using calculated quaternion and position
    	// here rotation is not changed
    	GetOwner()->SetActorLocation(NewPosition);
    }