void FLevelEditorViewportClient::MouseMove(FViewport* InViewport, int32 x, int32 y)
{
if (bUserIsControllingAtmosphericLight0 || bUserIsControllingAtmosphericLight1)
{
UWorld* ViewportWorld = GetWorld();
const uint8 DesiredLightIndex = bUserIsControllingAtmosphericLight0 ? 0 : 1;
UDirectionalLightComponent* SelectedAtmosphericLight = GetAtmosphericLight(DesiredLightIndex, ViewportWorld);
if (SelectedAtmosphericLight)
{
int32 mouseDeltaX = x - CachedLastMouseX;
int32 mouseDeltaY = y - CachedLastMouseY;
FTransform ComponentTransform = SelectedAtmosphericLight->GetComponentTransform();
FQuat LightRotation = ComponentTransform.GetRotation();
// Rotate around up axis (yaw)
FVector UpVector = FVector(0, 0, 1);
LightRotation = FQuat(UpVector, float(mouseDeltaX)*0.01f) * LightRotation;
// Light Zenith rotation (pitch)
FVector PitchRotationAxis = FVector::CrossProduct(LightRotation.GetForwardVector(), UpVector);
if (FMath::Abs(FVector::DotProduct(LightRotation.GetForwardVector(), UpVector)) > (1.0f - KINDA_SMALL_NUMBER))
{
PitchRotationAxis = FVector::CrossProduct(LightRotation.GetForwardVector(), FVector(1, 0, 0));
}
PitchRotationAxis.Normalize();
LightRotation = FQuat(PitchRotationAxis, float(mouseDeltaY)*0.01f) * LightRotation;
ComponentTransform.SetRotation(LightRotation);
SelectedAtmosphericLight->SetWorldTransform(ComponentTransform);
NotifyAtmosphericLightHasMoved(*SelectedAtmosphericLight, false);
UserControlledAtmosphericLightMatrix = ComponentTransform;
UserControlledAtmosphericLightMatrix.NormalizeRotation();
}
}
FEditorViewportClient::MouseMove(InViewport, x, y);
}