本文整理汇总了C++中FVector::GridSnap方法的典型用法代码示例。如果您正苦于以下问题:C++ FVector::GridSnap方法的具体用法?C++ FVector::GridSnap怎么用?C++ FVector::GridSnap使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FVector
的用法示例。
在下文中一共展示了FVector::GridSnap方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: TickComponent
void UInfiniteSystemComponent::TickComponent(float DeltaTime, enum ELevelTick TickType, FActorComponentTickFunction *ThisTickFunction)
{
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
// If disabled or we are not attached to a parent component, return.
if (!bIsActive || !AttachParent || !GetWorld()) return;
FVector CamLoc;
FRotator CamRot;
FVector PawnLoc;
FVector NewLoc;
#if WITH_EDITOR
if (GIsEditor)
{
if (!UpdateInEditor) return;
TArray<FVector> viewLocations = GetWorld()->ViewLocationsRenderedLastFrame;
if (viewLocations.Num() != 0)
{
CamLoc = viewLocations[0];
}
//FEditorViewportClient* client = (FEditorViewportClient*)GEditor->GetActiveViewport()->GetClient();
//CamLoc = client->GetViewLocation();
//CamRot = client->GetViewRotation();
if (FollowMethod == LookAtLocation || FollowMethod == FollowCamera)
{
NewLoc = CamLoc;
NewLoc = NewLoc.GridSnap(GridSnapSize);
NewLoc.Z = AttachParent->GetComponentLocation().Z;
AttachParent->SetWorldLocation(NewLoc);
}
else
{
AttachParent->SetRelativeLocation(FVector(0, 0, 0)); //Reset location
}
if (ScaleByDistance && FMath::Abs(CamLoc.Z - AttachParent->GetComponentLocation().Z) > ScaleStartDistance)
{
float DistScale = FMath::Abs(CamLoc.Z - AttachParent->GetComponentLocation().Z) / ScaleDistanceFactor;
DistScale = FMath::Clamp(DistScale, ScaleMin, ScaleMax);
AttachParent->SetRelativeScale3D(FVector(DistScale, DistScale, 1)); //Scale only on x & y axis
}
else if (!ScaleByDistance)
{
AttachParent->SetRelativeScale3D(FVector(1, 1, 1)); //Reset scale
}
return;
}
#endif
if (GetWorld()->WorldType == EWorldType::Game || GetWorld()->WorldType == EWorldType::PIE)
{
if (!GEngine || !GEngine->GetFirstLocalPlayerController(GetWorld())) return;
GEngine->GetFirstLocalPlayerController(GetWorld())->PlayerCameraManager->GetCameraViewPoint(CamLoc, CamRot);
if (GEngine->GetFirstLocalPlayerController(GetWorld())->GetPawn()) //null check
{
PawnLoc = GEngine->GetFirstLocalPlayerController(GetWorld())->GetPawn()->GetActorLocation();
}
else
{
PawnLoc = AttachParent->GetComponentLocation();
}
}
switch (FollowMethod)
{
case LookAtLocation:
if (!FMath::SegmentPlaneIntersection(CamLoc, CamLoc + CamRot.Vector() * MaxLookAtDistance, FPlane(AttachParent->GetComponentLocation(), FVector(0, 0, 1)), NewLoc))
{
NewLoc = CamLoc + CamRot.Vector() * MaxLookAtDistance;
}
break;
case FollowCamera:
NewLoc = CamLoc;
break;
case FollowPawn:
NewLoc = PawnLoc;
break;
default:
break;
};
//UE_LOG(LogTemp, Warning, TEXT("Camera Z Distance from Plane: %f"), FMath::Abs(CamLoc.Z - AttachParent->GetComponentLocation().Z));
if (ScaleByDistance && FMath::Abs(CamLoc.Z - AttachParent->GetComponentLocation().Z) > ScaleStartDistance)
{
float DistScale = FMath::Abs(CamLoc.Z - AttachParent->GetComponentLocation().Z) / ScaleDistanceFactor;
DistScale = FMath::Clamp(DistScale, ScaleMin, ScaleMax);
AttachParent->SetRelativeScale3D(FVector(DistScale, DistScale, 1)); //Scale only on x & y axis
}
if (FollowMethod == Stationary) return;
NewLoc = NewLoc.GridSnap(GridSnapSize);
NewLoc.Z = AttachParent->GetComponentLocation().Z;
//.........这里部分代码省略.........
示例2: GridSnap
FVector UTKMathFunctionLibrary::GridSnap(FVector A, float Grid)
{
return A.GridSnap(Grid);
}