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


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

本文整理汇总了C++中FVector::ToOrientationRotator方法的典型用法代码示例。如果您正苦于以下问题:C++ FVector::ToOrientationRotator方法的具体用法?C++ FVector::ToOrientationRotator怎么用?C++ FVector::ToOrientationRotator使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在FVector的用法示例。


在下文中一共展示了FVector::ToOrientationRotator方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: FollowPathSegment

void UVehiclePathFollowingComponent::FollowPathSegment(float DeltaTime)
{
    if (MovementComp)
    {
        UWheeledVehicleMovementComponent* VehicleMoveComp =
            Cast<UWheeledVehicleMovementComponent>(MovementComp);

        AWheeledVehicle* Owner = Cast<AWheeledVehicle>(VehicleMoveComp->GetOwner());

        if (Owner && VehicleMoveComp)
        {
            if(DesiredVehicleSpeedInKMH == 0.0f)
                VehicleMoveComp->SetHandbrakeInput(true);
            else
                VehicleMoveComp->SetHandbrakeInput(false);

            FVector VehicleLocation = Owner->GetActorLocation();
            FVector Destination = GetCurrentTargetLocation();
            FVector DirectionToDestination = Destination - VehicleLocation; //Vector pointing to current destination (not necessarily the final destination)

            //____STEERING____
            float DesiredSteering = 0.f;
            float DeltaYaw = (DirectionToDestination.ToOrientationRotator() - Owner->GetActorForwardVector().ToOrientationRotator()).Yaw;
            bool DestinationToRight = DeltaYaw >= 0;

            if (DeltaYaw > 180.f || DeltaYaw < -180.f) {
                DestinationToRight = !DestinationToRight;
                if (DestinationToRight && DeltaYaw >= -360.f + MaxSteeringAngle)
                {
                    DesiredSteering = 1.f;
                }
                else if (!DestinationToRight && DeltaYaw <= 360.f - MaxSteeringAngle)
                {
                    DesiredSteering = -1.f;
                }
                else if(DestinationToRight)
                {
                    DesiredSteering = FMath::GetMappedRangeValueClamped(FVector2D(-360.f, -360.f + MaxSteeringAngle), FVector2D(0, 1.0f), DeltaYaw);
                }
                else
                {
                    DesiredSteering = FMath::GetMappedRangeValueClamped(FVector2D(360.f - MaxSteeringAngle, 360.f), FVector2D(-1.f, 0.f), DeltaYaw);
                }
            }
            else
            {
                if (DestinationToRight && DeltaYaw >= MaxSteeringAngle)
                {
                    DesiredSteering = 1.f;
                }
                else if (!DestinationToRight && DeltaYaw <= -MaxSteeringAngle)
                {
                    DesiredSteering = -1.f;
                }
                else
                    DesiredSteering = FMath::GetMappedRangeValueClamped(FVector2D(-MaxSteeringAngle, MaxSteeringAngle), FVector2D(-1.f, 1.f), DeltaYaw);
            }

            CurrentSteering = DesiredSteering;
            VehicleMoveComp->SetSteeringInput(CurrentSteering);
            //____END STEERING____

            //____THROTTLE____
            float CurrentSpeedInKMH = VehicleMoveComp->GetForwardSpeed() * 0.036f; //Convert to KM/H
            //TODO: Allow speed to be 0, but never 0 if DesiredSpeed is > 0
            float EstiamtedDesiredSpeed = DesiredVehicleSpeedInKMH - (FMath::Abs(CurrentSteering) * DesiredVehicleSpeedInKMH * 0.8);

            CurrentThrottle += UPIDController::NextValue(VelocityController, EstiamtedDesiredSpeed - CurrentSpeedInKMH, DeltaTime);
            CurrentThrottle = FMath::Clamp(CurrentThrottle, 0.f, 1.f);
            VehicleMoveComp->SetThrottleInput(CurrentThrottle);
            //____END THROTTLE____

            //Direction the wheel is facing
            DesiredMoveDirection = Owner->GetActorForwardVector().ToOrientationRotator().Add(0.f, FMath::GetMappedRangeValueClamped(FVector2D(-1.f, 1.f), FVector2D(-90.f, 90.f), CurrentSteering), 0.f).Vector();
            ABikeV3Pawn* BikePawn = Cast<ABikeV3Pawn>(Owner);
            if(BikePawn)
                BikePawn->CurrentHandlingInput = CurrentSteering;

#ifdef NDEBUG
            float DistanceToDestination = DirectionToDestination.Size();
            DrawDebugPoint(GetWorld(), Destination, 50.0f, FColor::Blue);
            DrawDebugLine(GetWorld(), VehicleLocation, VehicleLocation + DirectionToDestination, FColor::Yellow);

            if (GEngine)
            {
                GEngine->AddOnScreenDebugMessage(0, 1.0f, FColor::Cyan, FString::Printf(TEXT("Throttle %0.3f Steering: %0.3f"), CurrentThrottle, CurrentSteering));
                GEngine->AddOnScreenDebugMessage(1, 1.0f, FColor::Cyan, FString::Printf(TEXT("Distance to destination: %0.2f"), DistanceToDestination));
                GEngine->AddOnScreenDebugMessage(2, 1.0f, FColor::Cyan, FString::Printf(TEXT("Current Speed in KM/H: %0.2f"), CurrentSpeedInKMH));
                GEngine->AddOnScreenDebugMessage(3, 1.0f, FColor::Cyan, FString::Printf(TEXT("DeltaYaw %0.3f"), DeltaYaw));
            }
#endif

        }
    }
}
开发者ID:runeabrahams1,项目名称:Unreal-Engine-4-Bicycle-Simulator-with-AI,代码行数:95,代码来源:VehiclePathFollowingComponent.cpp


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