本文整理汇总了C++中FVector2D类的典型用法代码示例。如果您正苦于以下问题:C++ FVector2D类的具体用法?C++ FVector2D怎么用?C++ FVector2D使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了FVector2D类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: DrawConnection
void FStateMachineConnectionDrawingPolicy::DrawConnection(int32 LayerId, const FVector2D& Start, const FVector2D& End, const FLinearColor& InColor, float Thickness, bool bDrawBubbles)
{
const FVector2D& P0 = Start;
const FVector2D& P1 = End;
const FVector2D Delta = End-Start;
const FVector2D NormDelta = Delta.SafeNormal();
const FVector2D P0Tangent = NormDelta;
const FVector2D P1Tangent = NormDelta;
// Draw the spline itself
FSlateDrawElement::MakeDrawSpaceSpline(
DrawElementsList,
LayerId,
P0, P0Tangent,
P1, P1Tangent,
ClippingRect,
Thickness,
ESlateDrawEffect::None,
InColor
);
//@TODO: Handle bDrawBubbles
}
示例2: OnMouseButtonUp
FReply SProfilerThreadView::OnMouseButtonUp( const FGeometry& MyGeometry, const FPointerEvent& MouseEvent )
{
FReply Reply = FReply::Unhandled();
if( IsReady() )
{
const FVector2D MousePositionOnButtonUp = MyGeometry.AbsoluteToLocal( MouseEvent.GetScreenSpacePosition() );
const bool bIsValidForMouseClick = MousePositionOnButtonUp.Equals( MousePositionOnButtonDown, MOUSE_SNAP_DISTANCE );
if( MouseEvent.GetEffectingButton() == EKeys::LeftMouseButton )
{
if( bIsLeftMousePressed )
{
// Release the mouse, we are no longer dragging.
Reply = FReply::Handled().ReleaseMouseCapture();
}
bIsLeftMousePressed = false;
}
else if( MouseEvent.GetEffectingButton() == EKeys::RightMouseButton )
{
if( bIsRightMousePressed )
{
if( bIsValidForMouseClick )
{
ShowContextMenu( MouseEvent.GetScreenSpacePosition() );
Reply = FReply::Handled();
}
}
bIsRightMousePressed = false;
}
}
return Reply;
}
示例3: MakeSplineReparamTable
void FBehaviorTreeConnectionDrawingPolicy::DrawConnection(int32 LayerId, const FVector2D& Start, const FVector2D& End, const FLinearColor& InColor, float Thickness, bool bDrawBubbles)
{
const FVector2D& P0 = Start;
const FVector2D& P1 = End;
const FVector2D Delta = End-Start;
const FVector2D NormDelta = Delta.SafeNormal();
const FVector2D P0Tangent = NormDelta;
const FVector2D P1Tangent = NormDelta;
// Draw the spline itself
FSlateDrawElement::MakeDrawSpaceSpline(
DrawElementsList,
LayerId,
P0, P0Tangent,
P1, P1Tangent,
ClippingRect,
Thickness,
ESlateDrawEffect::None,
InColor
);
if (bDrawBubbles)
{
// This table maps distance along curve to alpha
FInterpCurve<float> SplineReparamTable;
float SplineLength = MakeSplineReparamTable(P0, P0Tangent, P1, P1Tangent, SplineReparamTable);
// Draw bubbles on the spline
const float BubbleSpacing = 64.f * ZoomFactor;
const float BubbleSpeed = 192.f * ZoomFactor;
const FVector2D BubbleSize = BubbleImage->ImageSize * ZoomFactor * 0.1f * Thickness;
float Time = (FPlatformTime::Seconds() - GStartTime);
const float BubbleOffset = FMath::Fmod(Time * BubbleSpeed, BubbleSpacing);
const int32 NumBubbles = FMath::CeilToInt(SplineLength/BubbleSpacing);
for (int32 i = 0; i < NumBubbles; ++i)
{
const float Distance = ((float)i * BubbleSpacing) + BubbleOffset;
if (Distance < SplineLength)
{
const float Alpha = SplineReparamTable.Eval(Distance, 0.f);
FVector2D BubblePos = FMath::CubicInterp(P0, P0Tangent, P1, P1Tangent, Alpha);
BubblePos -= (BubbleSize * 0.5f);
FSlateDrawElement::MakeBox(
DrawElementsList,
LayerId,
FPaintGeometry( BubblePos, BubbleSize, ZoomFactor ),
BubbleImage,
ClippingRect,
ESlateDrawEffect::None,
InColor
);
}
}
}
}
示例4: FVector2D
float FEyeXUtils::CalculateRotationAngle(const FVector2D& Left, const FVector2D& Right)
{
static const FVector2D Y = FVector2D(0.0f, 1.0f);
FVector2D LeftToRight = Right - Left;
LeftToRight.Normalize();
const float Radians = FMath::Acos(LeftToRight | Y);
return FMath::RadiansToDegrees(Radians) - 90.0f;
}
示例5: FindClosestPointOnLine
/** Find the point on line segment from LineStart to LineEnd which is closest to Point */
FVector2D FGeometryHelper::FindClosestPointOnLine(const FVector2D& LineStart, const FVector2D& LineEnd, const FVector2D& TestPoint)
{
const FVector2D LineVector = LineEnd - LineStart;
const float A = -FVector2D::DotProduct(LineStart - TestPoint, LineVector);
const float B = LineVector.SizeSquared();
const float T = FMath::Clamp<float>(A / B, 0.0f, 1.0f);
// Generate closest point
return LineStart + (T * LineVector);
}
示例6: Tick
virtual void Tick(const FGeometry& AllottedGeometry, const double InCurrentTime, const float InDeltaTime) override
{
TArray<UWidgetComponent*, TInlineAllocator<1>> DeadComponents;
for ( TWeakObjectPtr<UWidgetComponent> Component : Components )
{
if ( UWidgetComponent* WidgetComponent = Component.Get() )
{
if ( ULocalPlayer* LocalPlayer = WidgetComponent->GetOwnerPlayer() )
{
if ( APlayerController* PlayerController = LocalPlayer->PlayerController )
{
FVector WorldLocation = WidgetComponent->GetComponentLocation();
FVector ScreenPosition;
const bool bProjected = UWidgetLayoutLibrary::ProjectWorldLocationToWidgetPositionWithDistance(PlayerController, WorldLocation, ScreenPosition);
if ( bProjected )
{
WidgetComponent->GetUserWidgetObject()->SetVisibility(ESlateVisibility::SelfHitTestInvisible);
if ( SConstraintCanvas::FSlot* CanvasSlot = ComponentToSlot.FindRef(WidgetComponent) )
{
FVector2D DrawSize = WidgetComponent->GetDrawSize();
FVector2D Pivot = WidgetComponent->GetPivot();
CanvasSlot->AutoSize(DrawSize.IsZero());
CanvasSlot->Offset(FMargin(ScreenPosition.X, ScreenPosition.Y, DrawSize.X, DrawSize.Y));
CanvasSlot->Anchors(FAnchors(0, 0, 0, 0));
CanvasSlot->Alignment(Pivot);
CanvasSlot->ZOrder(-ScreenPosition.Z);
}
}
else
{
WidgetComponent->GetUserWidgetObject()->SetVisibility(ESlateVisibility::Hidden);
}
}
}
}
else
{
DeadComponents.Add(WidgetComponent);
}
}
// Normally components should be removed by someone calling remove component, but just in case it was
// deleted in a way where they didn't happen, this is our backup solution to enure we remove stale widgets.
for ( int32 Index = 0; Index < DeadComponents.Num(); Index++ )
{
RemoveComponent(DeadComponents[Index]);
}
}
示例7: ComputeActionAtLocation
ETransformAction STransformHandle::ComputeActionAtLocation(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent) const
{
FVector2D LocalPosition = MyGeometry.AbsoluteToLocal(MouseEvent.GetScreenSpacePosition());
FVector2D GrabOriginOffset = LocalPosition - DragOrigin;
if ( GrabOriginOffset.SizeSquared() < 36.f )
{
return ETransformAction::Primary;
}
else
{
return ETransformAction::Secondary;
}
}
示例8: FVector2D
float AMurphysLawCharacter::TakeDamage(float DamageAmount, struct FDamageEvent const & DamageEvent, class AController * EventInstigator, AActor * DamageCauser)
{
float ActualDamage = 0.f;
if (CurrentHealth > 0.f)
{
if (Role == ROLE_Authority)
{
ActualDamage = Super::TakeDamage(DamageAmount, DamageEvent, EventInstigator, DamageCauser);
// If the player actually took damage
if (ActualDamage > 0.f)
{
// If the character has a HUD, we show the damages on it
auto MyController = Cast<AMurphysLawPlayerController>(GetController());
if (MyController != nullptr)
{
// We start by getting best info on the hit
FVector ImpulseDirection;
FHitResult Hit;
DamageEvent.GetBestHitInfo(this, DamageCauser, Hit, ImpulseDirection);
// We calculate the vector from the character to the damage causer
FVector2D HitVector = FVector2D(FRotationMatrix(GetControlRotation()).InverseTransformVector(-ImpulseDirection));
HitVector.Normalize();
// We compute the vector representing the ForwardVector
FVector2D StraightVector = FVector2D(1.f, 0.f);
StraightVector.Normalize();
// Finally, we calculate the angle where the hit came from
float Angle = UKismetMathLibrary::DegAcos(FVector2D::DotProduct(StraightVector, HitVector));
// The angle ranges from -180.f to 180.f
Angle = HitVector.Y < 0.f ? -Angle : Angle;
// Dispatch to the controller
MyController->ShowDamage(Angle);
}
}
}
else
{
// Let the server do it
Server_TakeDamage(DamageAmount, DamageEvent, EventInstigator, DamageCauser);
}
}
return ActualDamage;
}
示例9: FVector2D
FMargin UUserWidget::GetFullScreenOffset() const
{
// If the size is zero, and we're not stretched, then use the desired size.
FVector2D FinalSize = FVector2D(ViewportOffsets.Right, ViewportOffsets.Bottom);
if ( FinalSize.IsZero() && !ViewportAnchors.IsStretchedVertical() && !ViewportAnchors.IsStretchedHorizontal() )
{
TSharedPtr<SWidget> CachedWidget = GetCachedWidget();
if ( CachedWidget.IsValid() )
{
FinalSize = CachedWidget->GetDesiredSize();
}
}
return FMargin(ViewportOffsets.Left, ViewportOffsets.Top, FinalSize.X, FinalSize.Y);
}
示例10: DesiredSizeFrom
/** @return the size of the DockNode that looks good in a preview given the initial size of the tab that we grabbed. */
FVector2D FDockingDragOperation::DesiredSizeFrom( const FVector2D& InitialTabSize )
{
// Just make sure it isn't too big so it doesn't cover up the whole screen.
const float MaxSideSizeAllowed = 800;
const float SizeCoefficient = FMath::Clamp( MaxSideSizeAllowed / InitialTabSize.GetMax(), 0.1f, 1.0f );
return InitialTabSize * SizeCoefficient;
}
示例11: DrawText
void SProfilerThreadView::DrawText( const FString& Text, const FSlateFontInfo& FontInfo, FVector2D Position, const FColor& TextColor, const FColor& ShadowColor, FVector2D ShadowOffset, const FSlateRect* ClippingRect /*= nullptr*/ ) const
{
check( PaintState );
if( ShadowOffset.Size() > 0.0f )
{
FSlateDrawElement::MakeText
(
PaintState->OutDrawElements,
PaintState->LayerId,
PaintState->AllottedGeometry.ToOffsetPaintGeometry( Position + ShadowOffset ),
Text,
FontInfo,
ClippingRect ? *ClippingRect : PaintState->AbsoluteClippingRect,
PaintState->DrawEffects,
ShadowColor
);
}
FSlateDrawElement::MakeText
(
PaintState->OutDrawElements,
++PaintState->LayerId,
PaintState->AllottedGeometry.ToOffsetPaintGeometry( Position ),
Text,
FontInfo,
ClippingRect ? *ClippingRect : PaintState->AbsoluteClippingRect,
PaintState->DrawEffects,
TextColor
);
}
示例12: SetViewportSize
void FWebBrowserWindow::SetViewportSize(FVector2D WindowSize)
{
// Magic number for texture size, can't access GetMax2DTextureDimension easily
FIntPoint ClampedWindowSize = WindowSize.ClampAxes(1, 2048).IntPoint();
if (ViewportSize != ClampedWindowSize)
{
FIntPoint OldViewportSize = MoveTemp(ViewportSize);
TArray<uint8> OldTextureData = MoveTemp(TextureData);
ViewportSize = ClampedWindowSize;
TextureData.SetNumZeroed(ViewportSize.X * ViewportSize.Y * 4);
// copy row by row to avoid texture distortion
const int32 WriteWidth = FMath::Min(OldViewportSize.X, ViewportSize.X) * 4;
const int32 WriteHeight = FMath::Min(OldViewportSize.Y, ViewportSize.Y);
for (int32 RowIndex = 0; RowIndex < WriteHeight; ++RowIndex)
{
FMemory::Memcpy(TextureData.GetData() + ViewportSize.X * RowIndex * 4, OldTextureData.GetData() + OldViewportSize.X * RowIndex * 4, WriteWidth);
}
if (UpdatableTexture != nullptr)
{
UpdatableTexture->ResizeTexture(ViewportSize.X, ViewportSize.Y);
UpdatableTexture->UpdateTexture(TextureData);
}
if (IsValid())
{
InternalCefBrowser->GetHost()->WasResized();
}
}
}
示例13: GetZoomAmount
FReply SPaperEditorViewport::OnMouseMove(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent)
{
const bool bIsRightMouseButtonDown = MouseEvent.IsMouseButtonDown(EKeys::RightMouseButton);
const bool bIsLeftMouseButtonDown = MouseEvent.IsMouseButtonDown(EKeys::LeftMouseButton);
if (HasMouseCapture())
{
// Track how much the mouse moved since the mouse down.
const FVector2D CursorDelta = MouseEvent.GetCursorDelta();
TotalMouseDelta += CursorDelta.Size();
if (bIsRightMouseButtonDown)
{
FReply ReplyState = FReply::Handled();
if (!CursorDelta.IsZero())
{
bShowSoftwareCursor = true;
}
bIsPanning = true;
ViewOffset -= CursorDelta / GetZoomAmount();
return ReplyState;
}
else if (bIsLeftMouseButtonDown)
{
// TSharedPtr<SNode> NodeBeingDragged = NodeUnderMousePtr.Pin();
// Update the amount to pan panel
UpdateViewOffset(MyGeometry, MouseEvent.GetScreenSpacePosition());
const bool bCursorInDeadZone = TotalMouseDelta <= FSlateApplication::Get().GetDragTriggerDistance();
{
// We are marquee selecting
const FVector2D GraphMousePos = PanelCoordToGraphCoord( MyGeometry.AbsoluteToLocal( MouseEvent.GetScreenSpacePosition() ) );
Marquee.Rect.UpdateEndPoint(GraphMousePos);
return FReply::Handled();
}
}
}
return FReply::Unhandled();
}
示例14: GetPreferredVelocity
FVector2D UAvoidanceComponent::GetPreferredVelocity()
{
FVector2D ToTarget;
if (bUseAITargetLocation && aiController)
{
ToTarget = FVector2D{ aiController->GetPathFollowingComponent()->GetCurrentTargetLocation() };
//FVector2D actLoc {pawn->GetActorLocation() };
//UE_LOG(LogRVOTest, Warning, TEXT("UAv::prefv GetCurrentTargetLocation, %f %f, actloc: %f %f"), CurrentTarget.X, CurrentTarget.Y, actLoc.X, actLoc.Y);
//UE_LOG(LogRVOTest, Warning, TEXT("UAv::Totarget: %f %f"), ToTarget.X, ToTarget.Y);
}
else
{
ToTarget = FVector2D{ CurrentTarget - FVector2D{ pawn->GetActorLocation() } };
}
float sqrDist = ToTarget.SizeSquared();
if (sqrDist < AcceptanceSquared)
return FVector2D::ZeroVector;
float m = 1.f / (SlowdownSquared - AcceptanceSquared);
float b = -m * AcceptanceSquared;
float k = (sqrDist < SlowdownSquared && pathFollowSlowdown) ? sqrDist * m + b : 1.f;
if (k < SMALL_NUMBER)
{
return FVector2D::ZeroVector;
}
FVector2D res = ToTarget.GetSafeNormal() * MaxVelocity * k;
if (res.ContainsNaN())
{
UE_LOG(LogRVOTest, VeryVerbose, TEXT("UAvoidanceComp:: GetPreferredV , %f %f"), res.X, res.Y);
}
return res;
}
示例15: MaterialObject
FSlateMaterialResource::FSlateMaterialResource(const UMaterialInterface& InMaterial, const FVector2D& InImageSize, FSlateShaderResource* InTextureMask )
: MaterialObject( &InMaterial )
, SlateProxy( new FSlateShaderResourceProxy )
, TextureMaskResource( InTextureMask )
, Width(FMath::RoundToInt(InImageSize.X))
, Height(FMath::RoundToInt(InImageSize.Y))
{
SlateProxy->ActualSize = InImageSize.IntPoint();
SlateProxy->Resource = this;
}