本文整理汇总了C++中ACharacter::GetActorForwardVector方法的典型用法代码示例。如果您正苦于以下问题:C++ ACharacter::GetActorForwardVector方法的具体用法?C++ ACharacter::GetActorForwardVector怎么用?C++ ACharacter::GetActorForwardVector使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ACharacter
的用法示例。
在下文中一共展示了ACharacter::GetActorForwardVector方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: FindScreenLocationForWorldLocation
void UHUDBlueprintLibrary::FindScreenLocationForWorldLocation(UObject* WorldContextObject, const FVector& InLocation, const float EdgePercent, FVector2D& OutScreenPosition, float& OutRotationAngleDegrees, bool &bIsOnScreen)
{
bIsOnScreen = false;
OutRotationAngleDegrees = 0.f;
FVector2D *ScreenPosition = new FVector2D();
UWorld* World = GEngine->GetWorldFromContextObject(WorldContextObject);
if (!World->IsValidLowLevel()) return;
if (GEngine->GameViewport == NULL) return;
if (GEngine->GameViewport->Viewport == NULL) return;
const FVector2D ViewportSize = FVector2D(GEngine->GameViewport->Viewport->GetSizeXY());
const FVector2D ViewportCenter = FVector2D(ViewportSize.X/2, ViewportSize.Y/2);
APlayerController* PlayerController = (WorldContextObject ? UGameplayStatics::GetPlayerController(WorldContextObject, 0) : NULL);
ACharacter *PlayerCharacter = static_cast<ACharacter *> (PlayerController->GetPawn());
if (!PlayerCharacter) return;
FVector Forward = PlayerCharacter->GetActorForwardVector();
FVector Offset = (InLocation - PlayerCharacter->GetActorLocation()).GetSafeNormal();
float DotProduct = FVector::DotProduct(Forward, Offset);
bool bLocationIsBehindCamera = (DotProduct < 0);
if (bLocationIsBehindCamera)
{
// For behind the camera situation, we cheat a little to put the
// marker at the bottom of the screen so that it moves smoothly
// as you turn around. Could stand some refinement, but results
// are decent enough for most purposes.
FVector DiffVector = InLocation - PlayerCharacter->GetActorLocation();
FVector Inverted = DiffVector * -1.f;
FVector NewInLocation = PlayerCharacter->GetActorLocation() * Inverted;
NewInLocation.Z -= 5000;
PlayerController->ProjectWorldLocationToScreen(NewInLocation, *ScreenPosition);
ScreenPosition->Y = (EdgePercent * ViewportCenter.X) * 2.f;
ScreenPosition->X = -ViewportCenter.X - ScreenPosition->X;
}
PlayerController->ProjectWorldLocationToScreen(InLocation, *ScreenPosition);
// Check to see if it's on screen. If it is, ProjectWorldLocationToScreen is all we need, return it.
if (ScreenPosition->X >= 0.f && ScreenPosition->X <= ViewportSize.X
&& ScreenPosition->Y >= 0.f && ScreenPosition->Y <= ViewportSize.Y)
{
OutScreenPosition = *ScreenPosition;
bIsOnScreen = true;
return;
}
*ScreenPosition -= ViewportCenter;
float AngleRadians = FMath::Atan2(ScreenPosition->Y, ScreenPosition->X);
AngleRadians -= FMath::DegreesToRadians(90.f);
OutRotationAngleDegrees = FMath::RadiansToDegrees(AngleRadians) + 180.f;
float Cos = cosf(AngleRadians);
float Sin = -sinf(AngleRadians);
ScreenPosition = new FVector2D(ViewportCenter.X + (Sin * 150.f), ViewportCenter.Y + Cos * 150.f);
float m = Cos / Sin;
FVector2D ScreenBounds = ViewportCenter * EdgePercent;
if (Cos > 0)
{
ScreenPosition = new FVector2D(ScreenBounds.Y/m, ScreenBounds.Y);
}
else
{
ScreenPosition = new FVector2D(-ScreenBounds.Y/m, -ScreenBounds.Y);
}
if (ScreenPosition->X > ScreenBounds.X)
{
ScreenPosition = new FVector2D(ScreenBounds.X, ScreenBounds.X*m);
}
else if (ScreenPosition->X < -ScreenBounds.X)
{
ScreenPosition = new FVector2D(-ScreenBounds.X, -ScreenBounds.X*m);
}
*ScreenPosition += ViewportCenter;
OutScreenPosition = *ScreenPosition;
}