本文整理汇总了C++中FVector::GetSafeNormal方法的典型用法代码示例。如果您正苦于以下问题:C++ FVector::GetSafeNormal方法的具体用法?C++ FVector::GetSafeNormal怎么用?C++ FVector::GetSafeNormal使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FVector
的用法示例。
在下文中一共展示了FVector::GetSafeNormal方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: DeprojectScreenToWorld
void FSceneView::DeprojectScreenToWorld(const FVector2D& ScreenPos, const FIntRect& ViewRect, const FMatrix& InvViewMatrix, const FMatrix& InvProjectionMatrix, FVector& out_WorldOrigin, FVector& out_WorldDirection)
{
int32 PixelX = FMath::TruncToInt(ScreenPos.X);
int32 PixelY = FMath::TruncToInt(ScreenPos.Y);
// Get the eye position and direction of the mouse cursor in two stages (inverse transform projection, then inverse transform view).
// This avoids the numerical instability that occurs when a view matrix with large translation is composed with a projection matrix
// Get the pixel coordinates into 0..1 normalized coordinates within the constrained view rectangle
const float NormalizedX = (PixelX - ViewRect.Min.X) / ((float)ViewRect.Width());
const float NormalizedY = (PixelY - ViewRect.Min.Y) / ((float)ViewRect.Height());
// Get the pixel coordinates into -1..1 projection space
const float ScreenSpaceX = (NormalizedX - 0.5f) * 2.0f;
const float ScreenSpaceY = ((1.0f - NormalizedY) - 0.5f) * 2.0f;
// The start of the raytrace is defined to be at mousex,mousey,1 in projection space (z=1 is near, z=0 is far - this gives us better precision)
// To get the direction of the raytrace we need to use any z between the near and the far plane, so let's use (mousex, mousey, 0.5)
const FVector4 RayStartProjectionSpace = FVector4(ScreenSpaceX, ScreenSpaceY, 1.0f, 1.0f);
const FVector4 RayEndProjectionSpace = FVector4(ScreenSpaceX, ScreenSpaceY, 0.5f, 1.0f);
// Projection (changing the W coordinate) is not handled by the FMatrix transforms that work with vectors, so multiplications
// by the projection matrix should use homogeneous coordinates (i.e. FPlane).
const FVector4 HGRayStartViewSpace = InvProjectionMatrix.TransformFVector4(RayStartProjectionSpace);
const FVector4 HGRayEndViewSpace = InvProjectionMatrix.TransformFVector4(RayEndProjectionSpace);
FVector RayStartViewSpace(HGRayStartViewSpace.X, HGRayStartViewSpace.Y, HGRayStartViewSpace.Z);
FVector RayEndViewSpace(HGRayEndViewSpace.X, HGRayEndViewSpace.Y, HGRayEndViewSpace.Z);
// divide vectors by W to undo any projection and get the 3-space coordinate
if (HGRayStartViewSpace.W != 0.0f)
{
RayStartViewSpace /= HGRayStartViewSpace.W;
}
if (HGRayEndViewSpace.W != 0.0f)
{
RayEndViewSpace /= HGRayEndViewSpace.W;
}
FVector RayDirViewSpace = RayEndViewSpace - RayStartViewSpace;
RayDirViewSpace = RayDirViewSpace.GetSafeNormal();
// The view transform does not have projection, so we can use the standard functions that deal with vectors and normals (normals
// are vectors that do not use the translational part of a rotation/translation)
const FVector RayStartWorldSpace = InvViewMatrix.TransformPosition(RayStartViewSpace);
const FVector RayDirWorldSpace = InvViewMatrix.TransformVector(RayDirViewSpace);
// Finally, store the results in the hitcheck inputs. The start position is the eye, and the end position
// is the eye plus a long distance in the direction the mouse is pointing.
out_WorldOrigin = RayStartWorldSpace;
out_WorldDirection = RayDirWorldSpace.GetSafeNormal();
}
示例2: AimAt
void UTankAimingComponent::AimAt(const FVector& HitLocation)
{
AActor* const Owner = GetOwner();
if (IsInitialised())
{
FVector OutLaunchVelocity;
FVector StartLocation = Barrel->GetSocketLocation(FName(TEXT("Projectile")));
// Only for DebugTrace purpose - if not ignore them
FCollisionResponseParams DummyParams; TArray<AActor*> DummyIgnores;
// Calculate the OutLaunchVelocity
bool bHaveAimSolution = UGameplayStatics::SuggestProjectileVelocity
(
this,
OutLaunchVelocity,
StartLocation,
HitLocation,
LaunchSpeed,
false,
10.f,
0.f,
ESuggestProjVelocityTraceOption::DoNotTrace
//, DummyParams, DummyIgnores, true // comment line to remove Debug DrawLine
);
if (bHaveAimSolution)
{
AimForwardDirection = OutLaunchVelocity.GetSafeNormal();
MoveBarrelTowards(AimForwardDirection);
}
}
}
示例3: AimAt
void UTankAimingComponent::AimAt(FVector HitLocation, float LaunchSpeed)
{
if (!Barrel) { return; }
FVector OutLaunchVelocity;
FVector StartLocation = Barrel->GetSocketLocation(FName("Projectile"));
//FVector AimDirection;
bool bHaveAimSolution = UGameplayStatics::SuggestProjectileVelocity
(
this,
OutLaunchVelocity,
StartLocation,
HitLocation,
LaunchSpeed,
false,
0,
0,
ESuggestProjVelocityTraceOption::DoNotTrace // Paramater must be present to prevent bug
);
auto timestamp = GetWorld()->GetTimeSeconds();
if (bHaveAimSolution)
{
FVector AimDirection = OutLaunchVelocity.GetSafeNormal();
MoveBarrelTowards(AimDirection);
//UE_LOG(LogTemp, Warning, TEXT("%f: We're aiming"), timestamp);
}
}
示例4: AimAt
void UTankAimingComponent::AimAt(FVector HitLocation, float LaunchSpeed) {
if (!Barrel) { return; }
FVector OutLaunchVelocity;
FVector StartLocation = Barrel->GetSocketLocation(FName("End"));
bool bHasAimSolution = UGameplayStatics::SuggestProjectileVelocity(
this,
OutLaunchVelocity,
StartLocation,
HitLocation,
LaunchSpeed,
false,
0,
0,
ESuggestProjVelocityTraceOption::DoNotTrace
);
if (bHasAimSolution) {
auto AimDirection = OutLaunchVelocity.GetSafeNormal();
MoveBarrelTowards(AimDirection);
}
return;
}
示例5: ShootArrow
void AMMO_Character::ShootArrow()
{
if(Role<ROLE_Authority)
ArrowsLeft--;
FActorSpawnParameters spawnParams;
spawnParams.Owner = this;
spawnParams.Instigator = Instigator;
FVector SpawnLoc = FVector(0);
FVector DirHelper = FVector(0);
if (LockedTarget)
{
SpawnLoc = Player_SkeletalMeshComponent->GetComponentLocation();
DirHelper = LockedTarget->GetActorLocation() - SpawnLoc;
}
else
{
SpawnLoc = ShootingLocation->GetComponentLocation();
DirHelper = LastKnownLocationOfTarget - SpawnLoc;
}
FRotator SpawnRot = Player_SpringArmComponent->GetComponentRotation() + FRotator(0,-90,0);
if(Role == ROLE_Authority)
FinalArrowDamage = BaseAttack + FMath::RandRange(AttackBonusMin, AttackBonusMax);
AArcherArrow* OurNewObject = GetWorld()->SpawnActor<AArcherArrow>(MyArrowObject, SpawnLoc , SpawnRot, spawnParams);
OurNewObject->ApplyForce(ArrowForce, this, DirHelper.GetSafeNormal());
}
示例6: PullBall
void AMagnetTile::PullBall( ABallPawn* ball )
{
auto prim = Cast<UPrimitiveComponent>( ball->GetRootComponent() );
UWorld* world = GetWorld();
auto DeltaTime = world->DeltaTimeSeconds;
AProjectTapGameState* gameState;
if ( world != nullptr && ( gameState = world->GetGameState<AProjectTapGameState>() ) != nullptr && gameState->SetMagnetTile( this ) != this )
{
FVector angular = FVector::ZeroVector;
prim->SetPhysicsAngularVelocity( angular );
float distanceAtNormal = FVector::DotProduct( ball->GetActorLocation() - GetActorLocation() , GetActorForwardVector() );
FVector normalLoc = ( distanceAtNormal * GetActorForwardVector() ) + GetActorLocation();
FVector normalToBall = ball->GetActorLocation() - normalLoc;
float dist = normalToBall.Size();
if ( dist > centerTolerance )
{
FVector toAdd = dist * -normalToBall.GetSafeNormal();
toAdd.Z = 0;
prim->AddRelativeLocation( toAdd );
}
}
if ( isVertical )
{
attractionSpeed *= verticalForceMultiplier;
}
float originalSpeed = prim->GetPhysicsLinearVelocity().Size();
float newSpeed = attractionSpeed + originalSpeed;
prim->SetPhysicsLinearVelocity(newSpeed * -GetActorForwardVector());
}
示例7: AreLineSegmentsCrossing
bool UTKMathFunctionLibrary::AreLineSegmentsCrossing(FVector pointA1, FVector pointA2, FVector pointB1, FVector pointB2)
{
FVector closestPointA;
FVector closestPointB;
int32 sideA;
int32 sideB;
FVector lineVecA = pointA2 - pointA1;
FVector lineVecB = pointB2 - pointB1;
bool valid = ClosestPointsOnTwoLines(closestPointA, closestPointB, pointA1, lineVecA.GetSafeNormal(), pointB1, lineVecB.GetSafeNormal());
//lines are not parallel
if (valid)
{
sideA = PointOnWhichSideOfLineSegment(pointA1, pointA2, closestPointA);
sideB = PointOnWhichSideOfLineSegment(pointB1, pointB2, closestPointB);
if ((sideA == 0) && (sideB == 0))
{
return true;
}
else
{
return false;
}
}
//lines are parallel
else
{
return false;
}
}
示例8: AimAt
void UTankAimingComponent::AimAt(FVector HitLocation)
{
if (!Barrel) { return; }
FVector OutLaunchVelocity;
FVector StartLocation = Barrel->GetSocketLocation(FName("Projectile"));
bool bHaveAimSolution = UGameplayStatics::SuggestProjectileVelocity
(
this,
OutLaunchVelocity,
StartLocation,
HitLocation,
LaunchSpeed,
false,
0,
0,
ESuggestProjVelocityTraceOption::DoNotTrace // Paramater must be present to prevent bug
);
if (bHaveAimSolution)
{
AimDirection = OutLaunchVelocity.GetSafeNormal();
MoveBarrelTowards(AimDirection);
}
// If no solution found do nothing
}
示例9: AimAt
void UTankAimingComponent::AimAt(FVector HitLocation)
{
if (!ensure(Barrel)) { return; }
FVector OutLaunchVelocity;
FVector StartLocation = Barrel->GetSocketLocation(FName("Projectile"));//This gets the socket location
//Calculate the OutLaunchVelocity
//The was a porblem with the code, even thought the default value was set we still must
//specify the parameter
bool bHaveAimSolution = UGameplayStatics::SuggestProjectileVelocity
(
this,
OutLaunchVelocity,
StartLocation,
HitLocation,
LaunchSpeed,
false,
0,
0,
ESuggestProjVelocityTraceOption::DoNotTrace //Parameter must be present to prevent bug
);
if(bHaveAimSolution)
{
AimDirection = OutLaunchVelocity.GetSafeNormal();
MoveBarrelTowards(AimDirection);
}
}
示例10: AimAt
void UTankAimingComponent::AimAt(FVector HitLocation)
{
if (!ensure(Barrel)) { return; }
FVector OutLaunchVelocity;
FVector StartLocation = Barrel->GetSocketLocation(FName("Projectile"));
//calculate the OutLaunchVelocity
bool bHaveAimSolution = UGameplayStatics::SuggestProjectileVelocity
(
this,
OutLaunchVelocity,
StartLocation,
HitLocation,
LaunchSpeed,
false,
0,
0,
ESuggestProjVelocityTraceOption::DoNotTrace
);
if (bHaveAimSolution)
{
AimDirection = OutLaunchVelocity.GetSafeNormal();
MoveBarrelTowards(AimDirection);
}
// no aim solution found, do nothing
}
示例11: Draw
void UAnimGraphNode_BoneDrivenController::Draw(FPrimitiveDrawInterface* PDI, USkeletalMeshComponent* SkelMeshComp) const
{
static const float ArrowHeadWidth = 5.0f;
static const float ArrowHeadHeight = 8.0f;
const int32 SourceIdx = SkelMeshComp->GetBoneIndex(Node.SourceBone.BoneName);
const int32 TargetIdx = SkelMeshComp->GetBoneIndex(Node.TargetBone.BoneName);
if ((SourceIdx != INDEX_NONE) && (TargetIdx != INDEX_NONE))
{
const FTransform SourceTM = SkelMeshComp->GetSpaceBases()[SourceIdx] * SkelMeshComp->ComponentToWorld;
const FTransform TargetTM = SkelMeshComp->GetSpaceBases()[TargetIdx] * SkelMeshComp->ComponentToWorld;
PDI->DrawLine(TargetTM.GetLocation(), SourceTM.GetLocation(), FLinearColor(0.0f, 0.0f, 1.0f), SDPG_Foreground, 0.5f);
const FVector ToTarget = TargetTM.GetTranslation() - SourceTM.GetTranslation();
const FVector UnitToTarget = ToTarget.GetSafeNormal();
FVector Midpoint = SourceTM.GetTranslation() + 0.5f * ToTarget + 0.5f * UnitToTarget * ArrowHeadHeight;
FVector YAxis;
FVector ZAxis;
UnitToTarget.FindBestAxisVectors(YAxis, ZAxis);
const FMatrix ArrowMatrix(UnitToTarget, YAxis, ZAxis, Midpoint);
DrawConnectedArrow(PDI, ArrowMatrix, FLinearColor(0.0f, 1.0f, 0.0), ArrowHeadHeight, ArrowHeadWidth, SDPG_Foreground);
PDI->DrawPoint(SourceTM.GetTranslation(), FLinearColor(0.8f, 0.8f, 0.2f), 5.0f, SDPG_Foreground);
PDI->DrawPoint(SourceTM.GetTranslation() + ToTarget, FLinearColor(0.8f, 0.8f, 0.2f), 5.0f, SDPG_Foreground);
}
}
示例12: TwoWallAdjust
void UMovementComponent::TwoWallAdjust(FVector& OutDelta, const FHitResult& Hit, const FVector& OldHitNormal) const
{
FVector Delta = OutDelta;
const FVector HitNormal = Hit.Normal;
if ((OldHitNormal | HitNormal) <= 0.f) //90 or less corner, so use cross product for direction
{
const FVector DesiredDir = Delta;
FVector NewDir = (HitNormal ^ OldHitNormal);
NewDir = NewDir.GetSafeNormal();
Delta = (Delta | NewDir) * (1.f - Hit.Time) * NewDir;
if ((DesiredDir | Delta) < 0.f)
{
Delta = -1.f * Delta;
}
}
else //adjust to new wall
{
const FVector DesiredDir = Delta;
Delta = ComputeSlideVector(Delta, 1.f - Hit.Time, HitNormal, Hit);
if ((Delta | DesiredDir) <= 0.f)
{
Delta = FVector::ZeroVector;
}
else if ( FMath::Abs((HitNormal | OldHitNormal) - 1.f) < KINDA_SMALL_NUMBER )
{
// we hit the same wall again even after adjusting to move along it the first time
// nudge away from it (this can happen due to precision issues)
Delta += HitNormal * 0.01f;
}
}
OutDelta = Delta;
}
示例13: HandleSliding
bool UProjectileMovementComponent::HandleSliding(FHitResult& Hit, float& SubTickTimeRemaining)
{
FHitResult InitialHit(Hit);
const FVector OldHitNormal = ConstrainDirectionToPlane(Hit.Normal);
// Velocity is now parallel to the impact surface.
// Perform the move now, before adding gravity/accel again, so we don't just keep hitting the surface.
SafeMoveUpdatedComponent(Velocity * SubTickTimeRemaining, UpdatedComponent->GetComponentQuat(), true, Hit);
if (HasStoppedSimulation())
{
return false;
}
// A second hit can deflect the velocity (through the normal bounce code), for the next iteration.
if (Hit.bBlockingHit)
{
const float TimeTick = SubTickTimeRemaining;
SubTickTimeRemaining = TimeTick * (1.f - Hit.Time);
if (HandleBlockingHit(Hit, TimeTick, Velocity * TimeTick, SubTickTimeRemaining) == EHandleBlockingHitResult::Abort ||
HasStoppedSimulation())
{
return false;
}
}
else
{
// Find velocity after elapsed time
const FVector PostTickVelocity = ComputeVelocity(Velocity, SubTickTimeRemaining);
// If pointing back into surface, apply friction and acceleration.
const FVector Force = (PostTickVelocity - Velocity);
const float ForceDotN = (Force | OldHitNormal);
if (ForceDotN < 0.f)
{
const FVector ProjectedForce = FVector::VectorPlaneProject(Force, OldHitNormal);
const FVector NewVelocity = Velocity + ProjectedForce;
const FVector FrictionForce = -NewVelocity.GetSafeNormal() * FMath::Min(-ForceDotN * Friction, NewVelocity.Size());
Velocity = ConstrainDirectionToPlane(NewVelocity + FrictionForce);
}
else
{
Velocity = PostTickVelocity;
}
// Check min velocity
if (Velocity.SizeSquared() < FMath::Square(BounceVelocityStopSimulatingThreshold))
{
StopSimulating(InitialHit);
return false;
}
SubTickTimeRemaining = 0.f;
}
return true;
}
示例14: RequestDirectMove
void UTankMovementComponent::RequestDirectMove(const FVector& MoveVelocity, bool bForceMaxSpeed)
{
auto TankForward = GetOwner()->GetActorForwardVector().GetSafeNormal();
auto AIForwardIntention = MoveVelocity.GetSafeNormal();
auto ForwardThrow = FVector::DotProduct(TankForward, AIForwardIntention);
auto RightThrow = FVector::CrossProduct(AIForwardIntention, TankForward);
IntendMoveForward(ForwardThrow);
IntendTurnRight(RightThrow.GetSafeNormal().Z);
}
示例15: TakeDamageFromEnemy
void AMMO_Character::TakeDamageFromEnemy(int32 Damage, AActor* Monster)
{
FRotator Rot = Player_SkeletalMeshComponent->GetSocketRotation(TEXT("Head"));
Rot = FRotator(0, Rot.Yaw, 0);
Rot += FRotator(0, 90, 0);
FVector ForwardVector = (Rot.Vector() * 500);
FVector DirToGobo = Monster->GetActorLocation() - GetActorLocation();
ForwardVector = FVector(ForwardVector.X, ForwardVector.Y, 0);
DirToGobo = FVector(DirToGobo.X, DirToGobo.Y, 0);
float DotProduct = FVector::DotProduct(ForwardVector.GetSafeNormal(), DirToGobo.GetSafeNormal());
float Radians = FMath::RadiansToDegrees(acosf(DotProduct));
if (Cast<AMMO_Mob_Character>(Monster))
{
Damage = Cast<AMMO_Mob_Character>(Monster)->Attack + FMath::RandRange(Cast<AMMO_Mob_Character>(Monster)->AttackBonusMin, Cast<AMMO_Mob_Character>(Monster)->AttackBonusMax);
Multicast_PlaySound(GlobalPool->GenericSoundEffects.FindRef(ESoundEffectLibrary::SFX_DaggerHit), GetActorLocation());
}
else if(Cast<ABoss>(Monster))
{
Damage = Cast<ABoss>(Monster)->BaseDamage + FMath::RandRange(Cast<ABoss>(Monster)->BonusDamage_Min, Cast<ABoss>(Monster)->BonusDamage_Max);
Multicast_PlaySound(GlobalPool->GenericSoundEffects.FindRef(ESoundEffectLibrary::SFX_BossHit), GetActorLocation());
}
Damage -= Damage*BaseDamageReduction;
if (FMath::Abs(Radians) <= 55.f && bIsShieldBlocking)
{
Damage = FMath::DivideAndRoundDown(Damage, 3);
Multicast_PlayAnimation(GetHurtMontageShield);
}
else
{
if (!(AnimInstance->Montage_IsPlaying(AttackMontage) || AnimInstance->Montage_IsPlaying(SecondAttackMontage)))
{
Multicast_PlayAnimation(GetHurtMontage);
}
}
UpdateHealth(Damage);
}