void FCameraCutTrackEditor::OnLockCameraClicked(ECheckBoxState CheckBoxState)
{
	if (CheckBoxState == ECheckBoxState::Checked)
	{
		for (int32 i = 0; i < GEditor->LevelViewportClients.Num(); ++i)
		{		
			FLevelEditorViewportClient* LevelVC = GEditor->LevelViewportClients[i];
			if (LevelVC && LevelVC->IsPerspective() && LevelVC->AllowsCinematicPreview() && LevelVC->GetViewMode() != VMI_Unknown)
			{
				LevelVC->SetActorLock(nullptr);
				LevelVC->bLockedCameraView = false;
				LevelVC->UpdateViewForLockedActor();
				LevelVC->Invalidate();
			}
		}
		GetSequencer()->SetPerspectiveViewportCameraCutEnabled(true);
	}
	else
	{
		GetSequencer()->UpdateCameraCut(nullptr, nullptr);
		GetSequencer()->SetPerspectiveViewportCameraCutEnabled(false);
	}

	GetSequencer()->SetGlobalTime(GetSequencer()->GetGlobalTime());
}
Exemple #2
0
void FVertexSnappingImpl::SnapDragDelta( FVertexSnappingArgs& InArgs, const FVector& StartLocation, const FBox& AllowedSnappingBox, TSet< TWeakObjectPtr<AActor> >& ActorsToIgnore, FVector& DragDelta )
{	
	const FSceneView* View = InArgs.SceneView;
	const FVector& DesiredUnsnappedLocation = InArgs.CurrentLocation;
	const FVector2D& MousePosition = InArgs.MousePosition;
	const EAxisList::Type CurrentAxis = InArgs.CurrentAxis;
	const FPlane ActorPlane = InArgs.ActorPlane;
	FLevelEditorViewportClient* ViewportClient = InArgs.ViewportClient;

	TArray<FSnapActor> PossibleSnapPointActors;
	GetPossibleSnapActors( AllowedSnappingBox, MousePosition.IntPoint(), ViewportClient, View, CurrentAxis, ActorsToIgnore, PossibleSnapPointActors );

	FVector Direction = FVector( ActorPlane.X, ActorPlane.Y, ActorPlane.Z );

	if( PossibleSnapPointActors.Num() > 0 )
	{
		// Get the closest vertex to the desired location (before snapping)
		FVector ClosestPoint = GetClosestVertex( PossibleSnapPointActors, InArgs ).Position;

		FVector PrevDragDelta = DragDelta;
		float Distance = 0;
		if( CurrentAxis != EAxisList::Screen )
		{
			// Compute a distance from the stat location to the snap point.  
			// When not using the screen space translation we snap to the plane along the movement axis that the nearest vertex is on and not the vertex itself
			FPlane RealPlane( StartLocation, Direction );
			Distance = RealPlane.PlaneDot( ClosestPoint );
						
			// Snap to the plane
			DragDelta = Distance*Direction;
		}
		else
		{
			// Snap to the nearest vertex
			DragDelta = ClosestPoint-StartLocation;
			Distance = DragDelta.Size();			
		}

		const FVector& PreSnapLocation = StartLocation;

		// Compute snapped location after computing the new drag delta
		FVector SnappedLocation = StartLocation+DragDelta;
				
		if( ViewportClient->IsPerspective() )
		{
			// Distance from start location to the location the actor would be in without snapping
			float DistFromPreSnapToDesiredUnsnapped = FVector::DistSquared( PreSnapLocation, DesiredUnsnappedLocation );

			// Distance from the new location of the actor without snapping to the location with snapping
			float DistFromDesiredUnsnappedToSnapped = FVector::DistSquared( DesiredUnsnappedLocation, SnappedLocation );

			// Only snap if the distance to the snapped location is less than the distance to the unsnapped location.  
			// This allows the user to control the speed of snapping based on how fast they move the mouse and also avoids jerkiness when the mouse is behind the snap location
			if( (CurrentAxis != EAxisList::Screen && DistFromDesiredUnsnappedToSnapped >= DistFromPreSnapToDesiredUnsnapped) || ClosestPoint == DesiredUnsnappedLocation )
			{
				DragDelta = FVector::ZeroVector;
			}
		}
		else
		{
			FVector2D PreSnapLocationPixel;
			View->WorldToPixel( PreSnapLocation, PreSnapLocationPixel );

			FVector2D SnappedLocationPixel;
			View->WorldToPixel( SnappedLocation, SnappedLocationPixel );

			FVector2D SLtoML = SnappedLocationPixel-MousePosition;
			FVector2D PStoML = MousePosition-PreSnapLocationPixel;

			// Only snap if the distance to the snapped location is less than the distance to the unsnapped location
			float Dist2 = PStoML.SizeSquared();
			float Dist1 = SLtoML.SizeSquared();
			if( Dist1 >= Dist2 || ClosestPoint == DesiredUnsnappedLocation )
			{
				DragDelta = FVector::ZeroVector;
			}
		}
	}
}