【问题标题】:How to use Draw Circle In Unreal如何在虚幻中使用画圆
【发布时间】:2020-03-24 21:10:20
【问题描述】:

我可以用这样的东西画一个圆圈。

DrawCircle(GetWorld(), GetOwner()->GetActorLocation(),XVector, YVector, DebugLineColor, GetPolarGridElement(i, j, k).X, 100, false, -1.0f, LineDepthInt8, LineThickness);

问题是,我似乎无法使用XVectorYVector 值正确旋转它。这里 Unreal 要求提供 X 轴矢量和 Y 轴矢量。这是如何工作的,它背后的数学原理是什么?比如说我有

FRotator DesiredAngle = FRotator(0,90,45);

如何将其转换为 XVectorYVector 以便正确绘制我的圆圈?

【问题讨论】:

  • 我不知道 ue4,但是可以使用 2D 中的一个向量定义一个圆(该向量是半径或直径,具体取决于您的约定)在 3D 中您将需要两个向量,因为存在无穷大可以用一个向量定义的圆。

标签: c++ math unreal-engine4


【解决方案1】:

把圆圈想象成是在一张纸上画的。 DrawCircle 要求提供与纸张边缘相对应的 3d 矢量,以便它可以在 3D 空间中正确渲染。

作为一个简单的示例,您可以尝试使用以下内容:

FVector XVector = DesiredAngle.rotateVector(0,1,0);
FVector YVector = DesiredAngle.rotateVector(0,0,1);

我查看了UE4的轴系,发现Y轴是“侧身”,Z轴是“上”,所以我们按照DesiredAngle旋转。

【讨论】:

    【解决方案2】:

    感谢下面其他人的帮助,嘿,终于弄明白了。添加到Botje的答案。如果我想画一个跟随演员旋转的圆圈。我这样做

    FRotator DesiredAngleZ = GetOwner()->GetActorRotation();

    FVector XVector = DesiredAngleZ.RotateVector(FVector(0, 1, 0));

    FVector YVector = DesiredAngleZ.RotateVector(FVector(0, 0, 1));

    在我的例子中,虽然我想跟随演员的旋转,但偏移了 90 度。我以为我可以做这样的事情

    FRotator DesiredAngleZ = GetOwner()->GetActorRotation();

    DesiredAngleZ += FRotator(0,0,90);

    FVector XVector = DesiredAngleZ.RotateVector(FVector(0, 1, 0));

    FVector YVector = DesiredAngleZ.RotateVector(FVector(0, 0, 1));

    这虽然非常失败。为什么?因为你不能像那样旋转旋转器。我对这个问题的解决方案是将两个 FRotator 转换为四元数,然后将它们相乘,然后再转换回来。最终解决方案如下所示...

    FQuat tempQuat = GetOwner()->GetActorRotation().Quaternion() * FRotator(0, 90, 0).Quaternion();

    FRotator DesiredAngleZ = tempQuat.Rotator();

    FVector XVector = DesiredAngleZ.RotateVector(FVector(0, 1, 0));

    FVector YVector = DesiredAngleZ.RotateVector(FVector(0, 0, 1));

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-09-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多