gpt4 book ai didi

c++ - 如何将 vector 行(点)对齐到中心?

转载 作者:行者123 更新时间:2023-11-30 05:01:15 28 4
gpt4 key购买 nike

我几天前发布了这个问题,从评论中我没有像我认为的那样详细地阐述这个问题。

这是我的更新版本,包含更多信息。

我有以下内容。

enter image description here

与中心左侧对齐的点行。

通过以下方式实现:

// Loop for basically CurrentWaveCount + 1
for (int32 Index = CurrentWaveCount; Index >= 0; Index--)
{
FHitResult HitResult(ForceInit);
FCollisionQueryParams TraceParams = FCollisionQueryParams();
TraceParams.AddIgnoredActor(GetOwner());
TraceParams.AddIgnoredActor(this);

//////////////////////////////////////////////////////////////////////////

FVector CastLocation = (GetActorForwardVector() * (CurrentWaveCount * WaveSpawnDistanceIncrement) + GetActorLocation());
CastLocation += (-GetActorRightVector() * (Index * ChildWaveActorSeperationIncrement));

//////////////////////////////////////////////////////////////////////////

CastLocation.Z += FixedCastTraceHeightOffset;

FVector TraceStart = CastLocation;
FVector TraceEnd = TraceStart + (-FVector::UpVector * MaxFallbackTraceDistance);

GetWorld()->LineTraceSingleByChannel(HitResult, TraceStart, TraceEnd, ECC_FixedCastableTraceChannel, TraceParams);

CastLocation 变量控制每个点的位置。

但是我想将它们对齐到中心而不是偏移到一侧,我无法计算出执行此操作的数学。

答案不必使用 C++,可以只是数学,因为如果有帮助,我可以从那里算出来。

谢谢。

enter image description here

当前:

enter image description here

预期:

enter image description here

更新的解决方案代码:

// Loop for basically CurrentWaveCount + 1
for (int32 Index = CurrentWaveCount; Index >= 0; Index--)
{
FHitResult HitResult(ForceInit);
FCollisionQueryParams TraceParams = FCollisionQueryParams();
TraceParams.AddIgnoredActor(GetOwner());
TraceParams.AddIgnoredActor(this);

//////////////////////////////////////////////////////////////////////////

float HalfWidth = CurrentWaveCount * ChildWaveActorSeperationIncrement / 2;

FVector CastLocation = (GetActorForwardVector() * (CurrentWaveCount * WaveSpawnDistanceIncrement) + GetActorLocation());
CastLocation += -GetActorRightVector() * (Index * ChildWaveActorSeperationIncrement);
CastLocation += GetActorRightVector() * HalfWidth;

//////////////////////////////////////////////////////////////////////////

CastLocation.Z += FixedCastTraceHeightOffset;

FVector TraceStart = CastLocation;
FVector TraceEnd = TraceStart + (-FVector::UpVector * MaxFallbackTraceDistance);

GetWorld()->LineTraceSingleByChannel(HitResult, TraceStart, TraceEnd, ECC_FixedCastableTraceChannel, TraceParams);

最佳答案

我做出以下假设:

  • GetActorLocation() 返回金发角色的位置。
  • GetActorForwardVector() 返回指向金发女郎所面对方向的单位 vector 。
  • GetActorRightVector() 返回与 ForwardVector 正交(垂直)且与地面水平的单位 vector 。

那么问题就出现在这里:

CastLocation += (-GetActorRightVector() * (Index * ChildWaveActorSeperationIncrement));

如果 ChildWaveActorSeperationIncrement 始终为非负数(并且 Index 为非负数),则此行始终将施法位置移到 blondie 左侧的某处。

最大向左位移是在 Index 最大时,因此它是 CurrentWaveCount * ChildWaveActorSeperationIncrement。这也是以 RightVector 为单位的行的宽度。要按要求将行居中,我们只需将每行向右移动此宽度的一半,方法是添加(伪代码):

half_width = CurrentWaveCount * ChildWaveActorSeperationIncrement / 2
CastLocation = ExistingCastLocation + GetActorRightVector() * half_width

关于c++ - 如何将 vector 行(点)对齐到中心?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50402380/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com