本文整理汇总了C++中FVector::Rotation方法的典型用法代码示例。如果您正苦于以下问题:C++ FVector::Rotation方法的具体用法?C++ FVector::Rotation怎么用?C++ FVector::Rotation使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FVector
的用法示例。
在下文中一共展示了FVector::Rotation方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: FaceTowardSource
void AGameplayAbilityWorldReticle::FaceTowardSource(bool bFaceIn2D)
{
if (TargetingActor)
{
if (bFaceIn2D)
{
FVector FacingVector = (TargetingActor->StartLocation.GetTargetingTransform().GetLocation() - GetActorLocation()).GetSafeNormal2D();
if (FacingVector.IsZero())
{
FacingVector = -GetActorForwardVector().GetSafeNormal2D();
}
if (!FacingVector.IsZero())
{
SetActorRotation(FacingVector.Rotation());
}
}
else
{
FVector FacingVector = (TargetingActor->StartLocation.GetTargetingTransform().GetLocation() - GetActorLocation()).GetSafeNormal();
if (FacingVector.IsZero())
{
FacingVector = -GetActorForwardVector().GetSafeNormal();
}
SetActorRotation(FacingVector.Rotation());
}
}
}
示例2: AimWithPlayerController
void AGameplayAbilityTargetActor_Trace::AimWithPlayerController(const AActor* InSourceActor, FCollisionQueryParams Params, const FVector& TraceStart, FVector& OutTraceEnd, bool bIgnorePitch) const
{
if (!OwningAbility) // Server and launching client only
{
return;
}
APlayerController* PC = OwningAbility->GetCurrentActorInfo()->PlayerController.Get();
check(PC);
FVector ViewStart;
FRotator ViewRot;
PC->GetPlayerViewPoint(ViewStart, ViewRot);
const FVector ViewDir = ViewRot.Vector();
FVector ViewEnd = ViewStart + (ViewDir * MaxRange);
ClipCameraRayToAbilityRange(ViewStart, ViewDir, TraceStart, MaxRange, ViewEnd);
FHitResult HitResult;
LineTraceWithFilter(HitResult, InSourceActor->GetWorld(), Filter, ViewStart, ViewEnd, TraceProfile.Name, Params);
const bool bUseTraceResult = HitResult.bBlockingHit && (FVector::DistSquared(TraceStart, HitResult.Location) <= (MaxRange * MaxRange));
const FVector AdjustedEnd = (bUseTraceResult) ? HitResult.Location : ViewEnd;
FVector AdjustedAimDir = (AdjustedEnd - TraceStart).GetSafeNormal();
if (AdjustedAimDir.IsZero())
{
AdjustedAimDir = ViewDir;
}
if (!bTraceAffectsAimPitch && bUseTraceResult)
{
FVector OriginalAimDir = (ViewEnd - TraceStart).GetSafeNormal();
if (!OriginalAimDir.IsZero())
{
// Convert to angles and use original pitch
const FRotator OriginalAimRot = OriginalAimDir.Rotation();
FRotator AdjustedAimRot = AdjustedAimDir.Rotation();
AdjustedAimRot.Pitch = OriginalAimRot.Pitch;
AdjustedAimDir = AdjustedAimRot.Vector();
}
}
OutTraceEnd = TraceStart + (AdjustedAimDir * MaxRange);
}
示例3: GetArcBisectorAngle
float UEnvQueryGenerator_Donut::GetArcBisectorAngle(FEnvQueryInstance& QueryInstance) const
{
float BisectAngle = 0.0f;
FVector Direction;
if (bDefineArc)
{
if (ArcDirection.DirMode == EEnvDirection::TwoPoints)
{
TArray<FVector> Start;
TArray<FVector> End;
QueryInstance.PrepareContext(ArcDirection.LineFrom, Start);
QueryInstance.PrepareContext(ArcDirection.LineTo, End);
if (Start.Num() > 0 && End.Num() > 0)
{
const FVector LineDir = (End[0] - Start[0]).GetSafeNormal();
const FRotator LineRot = LineDir.Rotation();
BisectAngle = LineRot.Yaw;
}
}
else
{
TArray<FRotator> Rot;
QueryInstance.PrepareContext(ArcDirection.Rotation, Rot);
if (Rot.Num() > 0)
{
BisectAngle = Rot[0].Yaw;
}
}
}
return BisectAngle;
}
示例4: Tick
// Called every frame
void AMonster::Tick( float DeltaTime )
{
Super::Tick( DeltaTime );
ARaiderCharacter *avatar = Cast<ARaiderCharacter>(UGameplayStatics::GetPlayerPawn(GetWorld(), 0));
if (!avatar) return;
FVector toPlayer = avatar->GetActorLocation() - GetActorLocation();
this->GetCharacterMovement()->bOrientRotationToMovement = true; // Rotate character to moving direction
float distanceToPlayer = toPlayer.Size();
// If the player is not in the SightSphere of the monster,
// go back
if (distanceToPlayer > SightSphere->GetScaledSphereRadius())
{
// If the player is out of sight,
// then the enemy cannot chase
return;
}
toPlayer /= distanceToPlayer; // normalizes the vector
FRotator Rotation = toPlayer.Rotation();
const FVector Direction = FRotationMatrix(Rotation).GetScaledAxis(EAxis::X);
AddMovementInput(Direction, m_fSpeed * DeltaTime);
}
示例5: GetAim
FVector2D AOrionPlaceableItem::GetAim(FVector WorldAim)
{
const FVector AimDirLS = ActorToWorld().InverseTransformVectorNoScale(WorldAim);
const FRotator AimRotLS = AimDirLS.Rotation();
return FVector2D(AimRotLS.Yaw, AimRotLS.Pitch);
}
示例6: LookAt
void UMWBotSensorComponent::LookAt(const AActor* Actor, const FVector Point)
{
//if (bCrazy)
//{
// return;
//}
// Convert aim direction to eye parent's local space
FVector aimDirWS = Actor ? Actor->GetActorLocation() : Point; // world space
aimDirWS -= GetComponentLocation();
FVector aimDirLS; // local space
if (AttachParent)
{
// If attached to socket, use socket transform
if (!AttachSocketName.IsNone())
{
aimDirLS = AttachParent->GetSocketTransform(AttachSocketName, ERelativeTransformSpace::RTS_World).InverseTransformVectorNoScale(aimDirWS);
}
else
{
aimDirLS = AttachParent->GetComponentTransform().InverseTransformVectorNoScale(aimDirWS);
}
}
else
{
aimDirLS = aimDirWS;
}
DesiredRotation = aimDirLS.Rotation();
}
示例7: FireShot
void ATP_TwinStickPawn::FireShot(FVector FireDirection)
{
// If we it's ok to fire again
if (bCanFire == true)
{
// If we are pressing fire stick in a direction
if (FireDirection.SizeSquared() > 0.0f)
{
const FRotator FireRotation = FireDirection.Rotation();
// Spawn projectile at an offset from this pawn
const FVector SpawnLocation = GetActorLocation() + FireRotation.RotateVector(GunOffset);
UWorld* const World = GetWorld();
if (World != NULL)
{
// spawn the projectile
World->SpawnActor<ATP_TwinStickProjectile>(SpawnLocation, FireRotation);
}
bCanFire = false;
World->GetTimerManager().SetTimer(TimerHandle_ShotTimerExpired, this, &ATP_TwinStickPawn::ShotTimerExpired, FireRate);
// try and play the sound if specified
if (FireSound != nullptr)
{
UGameplayStatics::PlaySoundAtLocation(this, FireSound, GetActorLocation());
}
bCanFire = false;
}
}
}
示例8: UpdateControlRotation
void AAIController::UpdateControlRotation(float DeltaTime, bool bUpdatePawn)
{
// Look toward focus
FVector FocalPoint = GetFocalPoint();
APawn* const Pawn = GetPawn();
if (Pawn)
{
FVector Direction = FAISystem::IsValidLocation(FocalPoint) ? (FocalPoint - Pawn->GetPawnViewLocation()) : Pawn->GetActorForwardVector();
FRotator NewControlRotation = Direction.Rotation();
// Don't pitch view unless looking at another pawn
if (Cast<APawn>(GetFocusActor()) == nullptr)
{
NewControlRotation.Pitch = 0.f;
}
NewControlRotation.Yaw = FRotator::ClampAxis(NewControlRotation.Yaw);
if (GetControlRotation().Equals(NewControlRotation, 1e-3f) == false)
{
SetControlRotation(NewControlRotation);
if (bUpdatePawn)
{
Pawn->FaceRotation(NewControlRotation, DeltaTime);
}
}
}
}
示例9: RenderScreen
// Render onto tt (using renderer) sitting @ cameraPos,
// facing cameraDir, an object with radiusWorldUnits.
void ATheHUD::RenderScreen( USceneCaptureComponent2D* renderer, FVector lookPos, float radiusWorldUnits, FVector cameraDir )
{
UTextureRenderTarget2D* tt = renderer->TextureTarget;
// http://stackoverflow.com/questions/3717226/
// radiusOnScreenPX = radiusWorldUnits*SW/(tan(fov / 2) * Z);
// ZBack = radiusWorldUnits*SW/(tan( fovy / 2 )*radiusOnScreenPX)
// Calculate Z distance back for a given pixel radius
// Set particular render properties & render the screen
// to texture in w.
float D = GetZDistance( radiusWorldUnits, tt->GetSurfaceWidth(), tt->GetSurfaceHeight(), renderer->FOVAngle );
FVector eyePos = lookPos - cameraDir * D;
FQuat quat = cameraDir.Rotation().Quaternion();
renderer->SetRelativeLocationAndRotation( eyePos, quat );
FVector2D screenSize = ui->gameChrome->gameCanvas->Size;
screenSize.X -= ui->gameChrome->rightPanel->Size.X;
FVector up = renderer->GetUpVector();
FLookAtMatrix lookAt( eyePos, lookPos, up );
FPerspectiveMatrix persp( rendererMinimap->FOVAngle/2.f, 1.f, 1.f, 0.5f );
FMatrix mvp1 = lookAt * persp;
vector<Ray> rays = Game->pc->GetFrustumRays( FBox2DU( 0.f, 0.f, screenSize.X, screenSize.Y ) );
float zValue = lookPos.Z;
FPlane plane( FVector(0.f, 0.f, 1.f), zValue );
vector<FVector> pts;
for( int i = 0; i < rays.size(); i++ )
{
FVector pt = FMath::LinePlaneIntersection( rays[i].start, rays[i].end, plane );
//Game->flycam->DrawDebug( pt, 25.f, FLinearColor::White, .25f );
pts.push_back( pt );
}
//FLinearColor Cyan(0,1,1,1);
//for( int i = 0; i < pts.size() - 1; i++ )
//{
// Game->flycam->DrawDebug( pts[i], pts[i+1], 25.f, Cyan, .25f );
//}
//if( pts.size() > 1 )
//{
// Game->flycam->DrawDebug( pts[pts.size()-1], pts[0], 25.f, Cyan, .25f );
//}
ui->gameChrome->rightPanel->minimap->pts.clear();
FVector2D minimapSize = ui->gameChrome->rightPanel->minimap->Size;
for( int i = 0; i < pts.size(); i++ )
{
FVector4 transformedPt = mvp1.TransformPosition( pts[i] );
float div = transformedPt.W;
transformedPt /= FVector4( div, div, div, div );
FVector2D p( transformedPt.X, transformedPt.Y ); // between [-1,1]
p *= 4.f/3.f; //!! Multiplying P by 4./3 req'd.. double-check
p *= minimapSize/2.f;
p.Y *= -1.f;
p += minimapSize/2.f;
p += ui->gameChrome->rightPanel->minimap->GetAbsPos();
ui->gameChrome->rightPanel->minimap->pts.push_back( p );
}
}
示例10: Tick
void ATP_TopDownCharacter::Tick(float DeltaSeconds)
{
if (CursorToWorld != nullptr)
{
if (UHeadMountedDisplayFunctionLibrary::IsHeadMountedDisplayEnabled())
{
if (UWorld* World = GetWorld())
{
FHitResult HitResult;
FCollisionQueryParams Params;
FVector StartLocation = TopDownCameraComponent->GetComponentLocation();
FVector EndLocation = TopDownCameraComponent->GetComponentRotation().Vector() * 2000.0f;
Params.AddIgnoredActor(this);
World->LineTraceSingleByChannel(HitResult, StartLocation, EndLocation, ECC_Visibility, Params);
FQuat SurfaceRotation = HitResult.ImpactNormal.ToOrientationRotator().Quaternion();
CursorToWorld->SetWorldLocationAndRotation(HitResult.Location, SurfaceRotation);
}
}
else if (APlayerController* PC = Cast<APlayerController>(GetController()))
{
FHitResult TraceHitResult;
PC->GetHitResultUnderCursor(ECC_Visibility, true, TraceHitResult);
FVector CursorFV = TraceHitResult.ImpactNormal;
FRotator CursorR = CursorFV.Rotation();
CursorToWorld->SetWorldLocation(TraceHitResult.Location);
CursorToWorld->SetWorldRotation(CursorR);
}
}
}
示例11: MoveBarrelTowards
void UTankAimingComponent::MoveBarrelTowards(FVector AimDirection) {
auto BarrelRotator = Barrel->GetForwardVector().Rotation();
auto AimAsRotator = AimDirection.Rotation();
auto DeltaRotator = AimAsRotator - BarrelRotator;
Barrel->Elevate(DeltaRotator.Pitch);
}
示例12: CalculateFacing
void AZombieShooterCharacter::CalculateFacing()
{
// Rotate character towards the mouse pointer
FVector PlaneNormal;
PlaneNormal.X = 0.f;
PlaneNormal.Y = 0.f;
PlaneNormal.Z = 1.f;
FVector PlanePoint = GetActorLocation();
float PlaneFormulaD = -1 * (PlaneNormal.X * PlanePoint.X + PlaneNormal.Y * PlanePoint.Y + PlaneNormal.Z * PlanePoint.Z);
// Calculate our t to calculate coordinates:
float tLeftSide = PlaneNormal.X*WorldDirection.X + PlaneNormal.Y*WorldDirection.Y + PlaneNormal.Z*WorldDirection.Z;
float tRightSide = -1 * (PlaneFormulaD + PlaneNormal.X*WorldLocation.X + PlaneNormal.Y*WorldLocation.Y + PlaneNormal.Z*WorldLocation.Z);
float t = tRightSide / tLeftSide;
FVector IntersectionPoint; // The result point where the mouse cursor is "projected". This is the point at which the pawn will be looking at.
IntersectionPoint.X = t * WorldDirection.X + WorldLocation.X;
IntersectionPoint.Y = t * WorldDirection.Y + WorldLocation.Y;
IntersectionPoint.Z = t * WorldDirection.Z + WorldLocation.Z;
FVector Direction = IntersectionPoint - PlanePoint;
FRotator NewControlRotation = Direction.Rotation();
NewControlRotation.Pitch = 0.f;
NewControlRotation.Yaw = FRotator::ClampAxis(NewControlRotation.Yaw);
NewControlRotation.Roll = 0.f;
Rotation = NewControlRotation;
ChangeFacing(Rotation);
}
示例13: UpdateControlRotation
void AAIController::UpdateControlRotation(float DeltaTime, bool bUpdatePawn)
{
// Look toward focus
FVector FocalPoint = GetFocalPoint();
if( !FocalPoint.IsZero() && GetPawn())
{
FVector Direction = FocalPoint - GetPawn()->GetActorLocation();
FRotator NewControlRotation = Direction.Rotation();
// Don't pitch view of walking pawns unless looking at another pawn
if ( GetPawn()->GetMovementComponent() && GetPawn()->GetMovementComponent()->IsMovingOnGround() &&
PathFollowingComponent && (!PathFollowingComponent->GetMoveGoal() || !Cast<APawn>(PathFollowingComponent->GetMoveGoal()) ) )
{
NewControlRotation.Pitch = 0.f;
}
NewControlRotation.Yaw = FRotator::ClampAxis(NewControlRotation.Yaw);
SetControlRotation(NewControlRotation);
APawn* const P = GetPawn();
if (P && bUpdatePawn)
{
P->FaceRotation(NewControlRotation, DeltaTime);
}
}
}
示例14: ReceiveHit
void AVehiclePawn::ReceiveHit(class UPrimitiveComponent* MyComp, class AActor* Other, class UPrimitiveComponent* OtherComp, bool bSelfMoved, FVector HitLocation, FVector HitNormal, FVector NormalForce, const FHitResult& Hit)
{
Super::ReceiveHit(MyComp, Other, OtherComp, bSelfMoved, HitLocation, HitNormal, NormalForce, Hit);
if (ImpactTemplate && NormalForce.Size() > ImpactEffectNormalForceThreshold)
{
AVehicleImpactEffect* EffectActor = GetWorld()->SpawnActorDeferred<AVehicleImpactEffect>(ImpactTemplate, HitLocation, HitNormal.Rotation());
if (EffectActor)
{
float DotBetweenHitAndUpRotation = FVector::DotProduct(HitNormal, GetMesh()->GetUpVector());
EffectActor->HitSurface = Hit;
EffectActor->HitForce = NormalForce;
EffectActor->bWheelLand = DotBetweenHitAndUpRotation > 0.8;
UGameplayStatics::FinishSpawningActor(EffectActor, FTransform(HitNormal.Rotation(), HitLocation));
}
}
if (ImpactCameraShake)
{
AVehiclePlayerController* PC = Cast<AVehiclePlayerController>(Controller);
if (PC != NULL && PC->IsLocalController())
{
PC->ClientPlayCameraShake(ImpactCameraShake, 1);
}
}
}
示例15: Tick
void ATP_TwinStickPawn::Tick(float DeltaSeconds)
{
// Find movement direction
const float ForwardValue = GetInputAxisValue(MoveForwardBinding);
const float RightValue = GetInputAxisValue(MoveRightBinding);
// Clamp max size so that (X=1, Y=1) doesn't cause faster movement in diagonal directions
const FVector MoveDirection = FVector(ForwardValue, RightValue, 0.f).GetClampedToMaxSize(1.0f);
// Calculate movement
const FVector Movement = MoveDirection * MoveSpeed * DeltaSeconds;
// If non-zero size, move this actor
if (Movement.SizeSquared() > 0.0f)
{
const FRotator NewRotation = Movement.Rotation();
FHitResult Hit(1.f);
RootComponent->MoveComponent(Movement, NewRotation, true, &Hit);
if (Hit.IsValidBlockingHit())
{
const FVector Normal2D = Hit.Normal.GetSafeNormal2D();
const FVector Deflection = FVector::VectorPlaneProject(Movement, Normal2D) * (1.f - Hit.Time);
RootComponent->MoveComponent(Deflection, NewRotation, true);
}
}
// Create fire direction vector
const float FireForwardValue = GetInputAxisValue(FireForwardBinding);
const float FireRightValue = GetInputAxisValue(FireRightBinding);
const FVector FireDirection = FVector(FireForwardValue, FireRightValue, 0.f);
// Try and fire a shot
FireShot(FireDirection);
}