要在Cesium for Unreal中实现鼠标左键拖动效果,可以按照以下步骤使用蓝图:

  1. 创建一个Actor,并将Cesium地球作为其子对象添加到场景中。

  2. 在该Actor的构造函数中,添加以下代码以启用鼠标输入:

PrimaryActorTick.bCanEverTick = true;
AutoReceiveInput = EAutoReceiveInput::Player0;
  1. 在蓝图编辑器中,添加以下事件处理程序:
  • OnInputTouchBegin:当用户开始触摸屏幕时,记录初始鼠标位置。
  • OnInputTouchEnd:当用户停止触摸屏幕时,重置初始鼠标位置。
  • OnInputTouchMove:当用户移动手指时,计算鼠标移动的距离,并根据距离旋转地球。
  1. 在OnInputTouchBegin事件处理程序中,添加以下代码以记录初始鼠标位置:
FVector2D LastTouchLocation;
LastTouchLocation = FVector2D(InputTouchLocation);
  1. 在OnInputTouchEnd事件处理程序中,添加以下代码以重置初始鼠标位置:
LastTouchLocation = FVector2D::ZeroVector;
  1. 在OnInputTouchMove事件处理程序中,添加以下代码以计算鼠标移动的距离并旋转地球:
if (LastTouchLocation != FVector2D::ZeroVector)
{
    FVector2D Delta = InputTouchLocation - LastTouchLocation;
    float RotationRate = 0.1f;
    FVector WorldRotationAxis = FVector::CrossProduct(FVector(0, 0, 1), GetActorLocation());
    AddActorLocalRotation(FQuat(WorldRotationAxis, -Delta.X * RotationRate));
    AddActorLocalRotation(FQuat(GetActorRightVector(), Delta.Y * RotationRate));
}

这将使地球绕其垂直轴(Z轴)和水平轴(X轴)旋转,从而实现鼠标左键拖动效果。您可以根据需要调整RotationRate的值以更改旋转速度

如何用蓝图实现cesium for unreal的鼠标左键拖动效果

原文地址: https://www.cveoy.top/t/topic/fG1I 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录