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


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

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


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

示例1: Explode_Implementation

void ACSExplosive::Explode_Implementation(ACSCharacterBase* InInstigator)
{
	if (!bExploded)
	{
		bExploded = true;

		const FVector MyLocation = GetActorLocation();
		const register float RadiusSq = FMath::Square(ExplodeRadius);
		for (TActorIterator<ACSCharacterBase> I(GetWorld()); I; ++I)
		{
			const FVector OtherLocation = I->GetActorLocation();
			FVector Direction = OtherLocation - MyLocation;
			const register float DistanceSq = Direction.SizeSquared();
			if (DistanceSq <= RadiusSq)
			{
				const register float Distance = FMath::Sqrt(DistanceSq);
				Direction /= Distance;
				const register float Ratio = Distance / ExplodeRadius;
				const int32 Damage = FMath::RoundToInt(FMath::Lerp((float)CenterDamage, (float)BorderDamage, Ratio));
				I->TakeExplosion(this, InInstigator, Direction, Damage, Ratio);
			}
		}

		if (nullptr != ExplodeParticle)
		{
			UGameplayStatics::SpawnEmitterAtLocation(GetWorld(), ExplodeParticle, MyLocation)->SetRelativeScale3D(ExplodeParticleScale);
		}
		if (nullptr != ExplodeSound)
		{
			UGameplayStatics::PlaySoundAtLocation(GetWorld(), ExplodeSound, MyLocation);
		}
		Destroy();

		for (TActorIterator<ACSExplosive> I(GetWorld()); I; ++I)
		{
			if (this != *I && !I->bExploded)
			{
				const FVector OtherLocation = I->GetActorLocation();
				FVector Direction = OtherLocation - MyLocation;
				const register float DistanceSq = Direction.SizeSquared();
				if (DistanceSq <= RadiusSq)
				{
					I->Explode(InInstigator);
				}
			}
		}
	}
}
开发者ID:hhg128,项目名称:UE4_CoolSummer,代码行数:48,代码来源:CSExplosive.cpp

示例2: 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;
		}
	}
}
开发者ID:colwalder,项目名称:unrealengine,代码行数:32,代码来源:TP_TwinStickPawn.cpp

示例3: 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);
}
开发者ID:colwalder,项目名称:unrealengine,代码行数:35,代码来源:TP_TwinStickPawn.cpp

示例4: FindSeparatingAxisGeneric

bool FSeparatingAxisPointCheck::FindSeparatingAxisGeneric()
{
	check(PolyVertices.Num() > 3);
	int32 LastIndex = PolyVertices.Num() - 1;
	for (int32 Index = 0; Index < PolyVertices.Num(); Index++)
	{
		const FVector& V0 = PolyVertices[LastIndex];
		const FVector& V1 = PolyVertices[Index];
		const FVector EdgeDir = V1 - V0;

		// Box edges x polygon edge

		if (!TestSeparatingAxisGeneric(FVector(EdgeDir.Y, -EdgeDir.X, 0.0f)) ||
			!TestSeparatingAxisGeneric(FVector(-EdgeDir.Z, 0.0f, EdgeDir.X)) ||
			!TestSeparatingAxisGeneric(FVector(0.0f, EdgeDir.Z, -EdgeDir.Y)))
		{
			return false;
		}

		LastIndex = Index;
	}

	// Box faces.

	if (!TestSeparatingAxisGeneric(FVector(0.0f, 0.0f, 1.0f)) ||
		!TestSeparatingAxisGeneric(FVector(1.0f, 0.0f, 0.0f)) ||
		!TestSeparatingAxisGeneric(FVector(0.0f, 1.0f, 0.0f)))
	{
		return false;
	}

	// Polygon normal.

	int32 Index0 = PolyVertices.Num() - 2;
	int32 Index1 = Index0 + 1;
	for (int32 Index2 = 0; Index2 < PolyVertices.Num(); Index2++)
	{
		const FVector& V0 = PolyVertices[Index0];
		const FVector& V1 = PolyVertices[Index1];
		const FVector& V2 = PolyVertices[Index2];

		const FVector EdgeDir0 = V1 - V0;
		const FVector EdgeDir1 = V2 - V1;

		FVector Normal = FVector::CrossProduct(EdgeDir1, EdgeDir0);
		if (Normal.SizeSquared() > SMALL_NUMBER)
		{
			if (!TestSeparatingAxisGeneric(Normal))
			{
				return false;
			}
			break;
		}

		Index0 = Index1;
		Index1 = Index2;
	}

	return true;
}
开发者ID:1vanK,项目名称:AHRUnrealEngine,代码行数:60,代码来源:Collision.cpp

示例5: UpdateCachedDirections

void UCrowdFollowingComponent::UpdateCachedDirections(const FVector& NewVelocity, const FVector& NextPathCorner, bool bTraversingLink)
{
	// MoveSegmentDirection = direction on string pulled path
	const FVector AgentLoc = GetCrowdAgentLocation();
	const FVector ToCorner = NextPathCorner - AgentLoc;
	if (ToCorner.SizeSquared() > FMath::Square(10.0f))
	{
		MoveSegmentDirection = ToCorner.GetSafeNormal();
	}

	// CrowdAgentMoveDirection either direction on path or aligned with current velocity
	if (!bTraversingLink)
	{
		CrowdAgentMoveDirection = bRotateToVelocity && (NewVelocity.SizeSquared() > KINDA_SMALL_NUMBER) ? NewVelocity.GetSafeNormal() : MoveSegmentDirection;
	}
}
开发者ID:mysheng8,项目名称:UnrealEngine,代码行数:16,代码来源:CrowdFollowingComponent.cpp

示例6: AddSphereGeomFromVerts

/**
 *	Function for adding a sphere collision primitive to the supplied collision geometry based on a set of Verts.
 *
 *	Simply put an AABB around mesh and use that to generate centre and radius.
 *	It checks that the AABB is square, and that all vertices are either at the
 *	centre, or within 5% of the radius distance away.
 */
void AddSphereGeomFromVerts( const TArray<FVector>& Verts, FKAggregateGeom* AggGeom, const TCHAR* ObjName )
{
    if(Verts.Num() == 0)
    {
        return;
    }

    FBox Box(0);

    for(int32 i=0; i<Verts.Num(); i++)
    {
        Box += Verts[i];
    }

    FVector Center, Extents;
    Box.GetCenterAndExtents(Center, Extents);
    float Longest = 2.f * Extents.GetMax();
    float Shortest = 2.f * Extents.GetMin();

    // check that the AABB is roughly a square (5% tolerance)
    if((Longest - Shortest)/Longest > 0.05f)
    {
        UE_LOG(LogStaticMeshEdit, Log, TEXT("AddSphereGeomFromVerts (%s): Sphere bounding box not square."), ObjName);
        return;
    }

    float Radius = 0.5f * Longest;

    // Test that all vertices are a similar radius (5%) from the sphere centre.
    float MaxR = 0;
    float MinR = BIG_NUMBER;
    for(int32 i=0; i<Verts.Num(); i++)
    {
        FVector CToV = Verts[i] - Center;
        float RSqr = CToV.SizeSquared();

        MaxR = FMath::Max(RSqr, MaxR);

        // Sometimes vertex at centre, so reject it.
        if(RSqr > KINDA_SMALL_NUMBER)
        {
            MinR = FMath::Min(RSqr, MinR);
        }
    }

    MaxR = FMath::Sqrt(MaxR);
    MinR = FMath::Sqrt(MinR);

    if((MaxR-MinR)/Radius > 0.05f)
    {
        UE_LOG(LogStaticMeshEdit, Log, TEXT("AddSphereGeomFromVerts (%s): Vertices not at constant radius."), ObjName );
        return;
    }

    // Allocate sphere in array
    FKSphereElem SphereElem;
    SphereElem.Center = Center;
    SphereElem.Radius = Radius;
    AggGeom->SphereElems.Add(SphereElem);
}
开发者ID:kidaa,项目名称:UnrealEngineVR,代码行数:67,代码来源:StaticMeshEdit.cpp

示例7: CheckVector

	void CheckVector( FVector ResultVector, FVector ExpectedVector, FString TestName, FString ParameterName, int32 TestIndex, float Tolerance = KINDA_SMALL_NUMBER )
	{
		const FVector Delta = ExpectedVector - ResultVector;
		if (Delta.SizeSquared() > FMath::Square(Tolerance))
		{
			//UE_LOG(CollisionAutomationTestLog, Log, TEXT("%d:HitResult=(%s)"), iTest+1, *OutHits[iHits].ToString());
			TestBase->AddError(FString::Printf(TEXT("Test %d:%s %s mismatch. Should be %s but is actually %s."), TestIndex, *TestName, *ParameterName, *ExpectedVector.ToString(), *ResultVector.ToString()));
		}
	}
开发者ID:zhaoyizheng0930,项目名称:UnrealEngine,代码行数:9,代码来源:CollisionAutomationTests.cpp

示例8: GetNetPriority

float AActor::GetNetPriority(const FVector& ViewPos, const FVector& ViewDir, AActor* Viewer, AActor* ViewTarget, UActorChannel* InChannel, float Time, bool bLowBandwidth)
{
	PRAGMA_DISABLE_DEPRECATION_WARNINGS
	// Call the deprecated version so subclasses will still work for a version
	float DeprecatedValue = AActor::GetNetPriority(ViewPos, ViewDir, Cast<APlayerController>(Viewer), InChannel, Time, bLowBandwidth);
	PRAGMA_ENABLE_DEPRECATION_WARNINGS
	if (DeprecatedValue != DEPRECATED_NET_PRIORITY)
	{
		return DeprecatedValue;
	}

	if (bNetUseOwnerRelevancy && Owner)
	{
		// If we should use our owner's priority, pass it through
		return Owner->GetNetPriority(ViewPos, ViewDir, Viewer, ViewTarget, InChannel, Time, bLowBandwidth);
	}

	if (ViewTarget && (this == ViewTarget || Instigator == ViewTarget))
	{
		// If we're the view target or owned by the view target, use a high priority
		Time *= 4.f;
	}
	else if (!bHidden && GetRootComponent() != NULL)
	{
		// If this actor has a location, adjust priority based on location
		FVector Dir = GetActorLocation() - ViewPos;
		float DistSq = Dir.SizeSquared();

		// Adjust priority based on distance and whether actor is in front of viewer
		if ((ViewDir | Dir) < 0.f)
		{
			if (DistSq > NEARSIGHTTHRESHOLDSQUARED)
			{
				Time *= 0.2f;
			}
			else if (DistSq > CLOSEPROXIMITYSQUARED)
			{
				Time *= 0.4f;
			}
		}
		else if ((DistSq < FARSIGHTTHRESHOLDSQUARED) && (FMath::Square(ViewDir | Dir) > 0.5f * DistSq))
		{
			// Compute the amount of distance along the ViewDir vector. Dir is not normalized
			// Increase priority if we're being looked directly at
			Time *= 2.f;
		}
		else if (DistSq > MEDSIGHTTHRESHOLDSQUARED)
		{
			Time *= 0.4f;
		}
	}

	return NetPriority * Time;
}
开发者ID:johndpope,项目名称:UE4,代码行数:54,代码来源:ActorReplication.cpp

示例9: SelectTargetToDebug

void AGameplayDebuggerReplicator::SelectTargetToDebug()
{
#if ENABLED_GAMEPLAY_DEBUGGER
	APlayerController* MyPC = DebugCameraController.IsValid() ? DebugCameraController.Get() : GetLocalPlayerOwner();

	if (MyPC)
	{
		float bestAim = 0;
		FVector CamLocation;
		FRotator CamRotation;
		check(MyPC->PlayerCameraManager != nullptr);
		MyPC->PlayerCameraManager->GetCameraViewPoint(CamLocation, CamRotation);
		FVector FireDir = CamRotation.Vector();
		UWorld* World = MyPC->GetWorld();
		check(World);

		APawn* PossibleTarget = nullptr;
		for (FConstPawnIterator Iterator = World->GetPawnIterator(); Iterator; ++Iterator)
		{
			APawn* NewTarget = *Iterator;
			if (NewTarget == nullptr || NewTarget == MyPC->GetPawn()
				|| (NewTarget->PlayerState != nullptr && NewTarget->PlayerState->bIsABot == false)
				|| NewTarget->GetActorEnableCollision() == false)
			{
				continue;
			}

			if (NewTarget != MyPC->GetPawn())
			{
				// look for best controlled pawn target
				const FVector AimDir = NewTarget->GetActorLocation() - CamLocation;
				float FireDist = AimDir.SizeSquared();
				// only find targets which are < 25000 units away
				if (FireDist < 625000000.f)
				{
					FireDist = FMath::Sqrt(FireDist);
					float newAim = FVector::DotProduct(FireDir, AimDir);
					newAim = newAim / FireDist;
					if (newAim > bestAim)
					{
						PossibleTarget = NewTarget;
						bestAim = newAim;
					}
				}
			}
		}

		if (PossibleTarget != nullptr && PossibleTarget != LastSelectedActorToDebug)
		{
			ServerSetActorToDebug(Cast<AActor>(PossibleTarget));
		}
	}
#endif //ENABLED_GAMEPLAY_DEBUGGER
}
开发者ID:RandomDeveloperM,项目名称:UE4_Hairworks,代码行数:54,代码来源:GameplayDebuggerReplicator.cpp

示例10: GetAngularVelocityToAlignAxis

FVector UFlareSpacecraftNavigationSystem::GetAngularVelocityToAlignAxis(FVector LocalShipAxis, FVector TargetAxis, FVector TargetAngularVelocity, float DeltaSeconds) const
{
	TArray<UActorComponent*> Engines = Spacecraft->GetComponentsByClass(UFlareEngine::StaticClass());

	FVector AngularVelocity = Spacecraft->Airframe->GetPhysicsAngularVelocity();
	FVector WorldShipAxis = Spacecraft->Airframe->GetComponentToWorld().GetRotation().RotateVector(LocalShipAxis);

	WorldShipAxis.Normalize();
	TargetAxis.Normalize();

	FVector RotationDirection = FVector::CrossProduct(WorldShipAxis, TargetAxis);
	RotationDirection.Normalize();
	float Dot = FVector::DotProduct(WorldShipAxis, TargetAxis);
	float angle = FMath::RadiansToDegrees(FMath::Acos(Dot));

	FVector DeltaVelocity = TargetAngularVelocity - AngularVelocity;
	FVector DeltaVelocityAxis = DeltaVelocity;
	DeltaVelocityAxis.Normalize();

	float TimeToFinalVelocity;

	if (FMath::IsNearlyZero(DeltaVelocity.SizeSquared()))
	{
		TimeToFinalVelocity = 0;
	}
	else {
		FVector SimpleAcceleration = DeltaVelocityAxis * GetAngularAccelerationRate();
		// Scale with damages
		float DamageRatio = GetTotalMaxTorqueInAxis(Engines, DeltaVelocityAxis, true) / GetTotalMaxTorqueInAxis(Engines, DeltaVelocityAxis, false);
		FVector DamagedSimpleAcceleration = SimpleAcceleration * DamageRatio;

		FVector Acceleration = DamagedSimpleAcceleration;
		float AccelerationInAngleAxis =  FMath::Abs(FVector::DotProduct(DamagedSimpleAcceleration, RotationDirection));

		TimeToFinalVelocity = (DeltaVelocity.Size() / AccelerationInAngleAxis);
	}

	float AngleToStop = (DeltaVelocity.Size() / 2) * (FMath::Max(TimeToFinalVelocity,DeltaSeconds));

	FVector RelativeResultSpeed;

	if (AngleToStop > angle) {
		RelativeResultSpeed = TargetAngularVelocity;
	}
	else
	{
		float MaxPreciseSpeed = FMath::Min((angle - AngleToStop) / (DeltaSeconds * 0.75f), GetAngularMaxVelocity());

		RelativeResultSpeed = RotationDirection;
		RelativeResultSpeed *= MaxPreciseSpeed;
	}

	return RelativeResultSpeed;
}
开发者ID:Helical-Games,项目名称:HeliumRain,代码行数:54,代码来源:FlareSpacecraftNavigationSystem.cpp

示例11: UpdateAnimation

void AGameJamGameCharacter::UpdateAnimation()
{
	const FVector PlayerVelocity = GetVelocity();
	const float PlayerSpeedSqr = PlayerVelocity.SizeSquared();

	// Are we moving or standing still?
	UPaperFlipbook* DesiredAnimation = (PlayerSpeedSqr > 0.0f) ? RunningAnimation : IdleAnimation;
	if( GetSprite()->GetFlipbook() != DesiredAnimation 	)
	{
		GetSprite()->SetFlipbook(DesiredAnimation);
	}
}
开发者ID:TimGates1239,项目名称:GameJam2016SummerQ,代码行数:12,代码来源:GameJamGameCharacter.cpp

示例12: ProjectVectorOnToVector

FVector UKismetMathLibrary::ProjectVectorOnToVector(FVector V, FVector Target)
{
	if (Target.SizeSquared() > SMALL_NUMBER)
	{
		return V.ProjectOnTo(Target);
	}
	else
	{
		FFrame::KismetExecutionMessage(TEXT("Divide by zero: ProjectVectorOnToVector with zero Target vector"), ELogVerbosity::Warning);
		return FVector::ZeroVector;
	}
}
开发者ID:didixp,项目名称:Ark-Dev-Kit,代码行数:12,代码来源:KismetMathLibrary.cpp

示例13: polyTexPan

void UEditorEngine::polyTexPan(UModel *Model,int32 PanU,int32 PanV,int32 Absolute)
{
	for(int32 SurfaceIndex = 0;SurfaceIndex < Model->Surfs.Num();SurfaceIndex++)
	{
		const FBspSurf&	Surf = Model->Surfs[SurfaceIndex];

		if(Surf.PolyFlags & PF_Selected)
		{
			if(Absolute)
			{
				Model->Points[Surf.pBase] = FVector::ZeroVector;
			}

			const FVector TextureU = Model->Vectors[Surf.vTextureU];
			const FVector TextureV = Model->Vectors[Surf.vTextureV];

			Model->Points[Surf.pBase] += PanU * (TextureU / TextureU.SizeSquared());
			Model->Points[Surf.pBase] += PanV * (TextureV / TextureV.SizeSquared());

			polyUpdateMaster(Model,SurfaceIndex,1);
		}
	}
}
开发者ID:PickUpSU,项目名称:UnrealEngine4,代码行数:23,代码来源:EditorCsg.cpp

示例14: EvaluateWorldOriginLocation

void UWorldComposition::EvaluateWorldOriginLocation(const FVector& ViewLocation)
{
	UWorld* OwningWorld = GetWorld();
	
	FVector Location = ViewLocation;

	if (!bRebaseOriginIn3DSpace)
	{
		// Consider only XY plane
		Location.Z = 0.f;
	}
		
	// Request to shift world in case current view is quite far from current origin
	if (Location.SizeSquared() > FMath::Square(RebaseOriginDistance))
	{
		OwningWorld->RequestNewWorldOrigin(FIntVector(Location.X, Location.Y, Location.Z) + OwningWorld->OriginLocation);
	}
}
开发者ID:RandomDeveloperM,项目名称:UE4_Hairworks,代码行数:18,代码来源:WorldComposition.cpp

示例15: ClipCameraRayToAbilityRange

bool AGameplayAbilityTargetActor_Trace::ClipCameraRayToAbilityRange(FVector CameraLocation, FVector CameraDirection, FVector AbilityCenter, float AbilityRange, FVector& ClippedPosition)
{
	FVector CameraToCenter = AbilityCenter - CameraLocation;
	float DotToCenter = FVector::DotProduct(CameraToCenter, CameraDirection);
	if (DotToCenter >= 0)		//If this fails, we're pointed away from the center, but we might be inside the sphere and able to find a good exit point.
	{
		float DistanceSquared = CameraToCenter.SizeSquared() - (DotToCenter * DotToCenter);
		float RadiusSquared = (AbilityRange * AbilityRange);
		if (DistanceSquared <= RadiusSquared)
		{
			float DistanceFromCamera = FMath::Sqrt(RadiusSquared - DistanceSquared);
			float DistanceAlongRay = DotToCenter + DistanceFromCamera;						//Subtracting instead of adding will get the other intersection point
			ClippedPosition = CameraLocation + (DistanceAlongRay * CameraDirection);		//Cam aim point clipped to range sphere
			return true;
		}
	}
	return false;
}
开发者ID:amyvmiwei,项目名称:UnrealEngine4,代码行数:18,代码来源:GameplayAbilityTargetActor_Trace.cpp


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