当前位置: 首页>>代码示例>>C++>>正文


C++ FVector::GridSnap方法代码示例

本文整理汇总了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;
//.........这里部分代码省略.........
开发者ID:calben,项目名称:OceanGame,代码行数:101,代码来源:InfiniteSystemComponent.cpp

示例2: GridSnap

FVector UTKMathFunctionLibrary::GridSnap(FVector A, float Grid)
{
	return A.GridSnap(Grid);
}
开发者ID:VulcanRav,项目名称:MainMenu,代码行数:4,代码来源:TKMathFunctionLibrary.cpp


注:本文中的FVector::GridSnap方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。