Files
UnrealEngineUWP/Engine/Source/Editor/ViewportInteraction/MouseCursorInteractor.cpp

91 lines
3.1 KiB
C++
Raw Normal View History

// Copyright 1998-2017 Epic Games, Inc. All Rights Reserved.
#include "MouseCursorInteractor.h"
Copying //UE4/Dev-Build to //UE4/Dev-Main (Source: //UE4/Dev-Build @ 3209340) #lockdown Nick.Penwarden #rb none ========================== MAJOR FEATURES + CHANGES ========================== Change 3209340 on 2016/11/23 by Ben.Marsh Convert UE4 codebase to an "include what you use" model - where every header just includes the dependencies it needs, rather than every source file including large monolithic headers like Engine.h and UnrealEd.h. Measured full rebuild times around 2x faster using XGE on Windows, and improvements of 25% or more for incremental builds and full rebuilds on most other platforms. * Every header now includes everything it needs to compile. * There's a CoreMinimal.h header that gets you a set of ubiquitous types from Core (eg. FString, FName, TArray, FVector, etc...). Most headers now include this first. * There's a CoreTypes.h header that sets up primitive UE4 types and build macros (int32, PLATFORM_WIN64, etc...). All headers in Core include this first, as does CoreMinimal.h. * Every .cpp file includes its matching .h file first. * This helps validate that each header is including everything it needs to compile. * No engine code includes a monolithic header such as Engine.h or UnrealEd.h any more. * You will get a warning if you try to include one of these from the engine. They still exist for compatibility with game projects and do not produce warnings when included there. * There have only been minor changes to our internal games down to accommodate these changes. The intent is for this to be as seamless as possible. * No engine code explicitly includes a precompiled header any more. * We still use PCHs, but they're force-included on the compiler command line by UnrealBuildTool instead. This lets us tune what they contain without breaking any existing include dependencies. * PCHs are generated by a tool to get a statistical amount of coverage for the source files using it, and I've seeded the new shared PCHs to contain any header included by > 15% of source files. Tool used to generate this transform is at Engine\Source\Programs\IncludeTool. [CL 3209342 by Ben Marsh in Main branch]
2016-11-23 15:48:37 -05:00
#include "SceneView.h"
#include "EditorViewportClient.h"
#include "ViewportWorldInteraction.h"
#include "Editor.h"
UMouseCursorInteractor::UMouseCursorInteractor( const FObjectInitializer& Initializer )
: UViewportInteractor( Initializer )
{
ViewportInteraction refactoring; miscellaneous VREditor improvements - This merge contains various changes to ViewportInteraction and VR Editor to make things more extensible - Some changes are from Yannick's recent shelved refactoring work, that I've modified and improved upon - EditorWorldManager is gone and replaced by EditorWorldExtensionManager - EditorWorldExtensions are sort of like a more modern version of 'FEdMode', but still a work in progress - Cleaned up access to VREditorMode from other modules, forcing systems to go through EditorWorldExtensions - Overhauled how transforming objects works with world interaction - Viewport interactors can now be used to move objects other than actors around (by implementing an UViewportTransformer, and a FViewportTransformable) - Undo/Redo now works better with inertial transformation! The transaction only ends when objects finally come to rest. - Some initial support for 'grabber sphere' interactor methods has been implemented (not used yet) - Viewport interaction input events now receive the viewport being interacted through - Viewport interaction hover events no longer get a viewport client (because they must be designed to work any number of viewports.) NOTE: This introduces UBT warnings about cyclic module dependencies. We'll have to address this in a different changelist. Other changes: - The active Viewport Interaction 'gizmo mode' is now tied directly to the editor's normal gizmo mode. They share the same state. - New console variable 'VI.UseTransientActors' can be turned off to force editor actors to be created non-transient to make it easier to debug - New console variable 'VI.DragTranslationVelocityStopEpsilon' sets the speed at which transformables will stop have inertia applied to them - Fixed cyclic dependencies with ViewportInteraction and VREditor modules not being tagged properly for UBT - Fixed some issues with transform gizmos not getting release events - Various methods that should have been const were made const - Eliminated duplicate implementation of SpawnTransientSceneActor and DestroyTransientActor; made it static - UnrealEd no longer directly depends on VREditor and ViewportInteraction modules - Engine: AActor::SetIsTemporarilyHiddenInEditor no longer does any work if the object's hidden state didn't change - Slate: Input preprocessor (if bound) now also gets a chance at mouse button down and up events #codereview yannick.lange,lauren.ridge #rb various [CL 3245240 by Mike Fricker in Dev-VREditor branch]
2017-01-03 14:38:17 -05:00
// Grabber spheres don't really work well with mouse cursor interactors, because the origin of the
// interactor is right on the near view plane.
bAllowGrabberSphere = false;
}
void UMouseCursorInteractor::Init()
{
KeyToActionMap.Reset();
// Setup keys
{
AddKeyAction( EKeys::LeftMouseButton, FViewportActionKeyInput( ViewportWorldActionTypes::SelectAndMove ) );
}
}
void UMouseCursorInteractor::PollInput()
{
InteractorData.LastTransform = InteractorData.Transform;
InteractorData.LastRoomSpaceTransform = InteractorData.RoomSpaceTransform;
ViewportInteraction refactoring; miscellaneous VREditor improvements - This merge contains various changes to ViewportInteraction and VR Editor to make things more extensible - Some changes are from Yannick's recent shelved refactoring work, that I've modified and improved upon - EditorWorldManager is gone and replaced by EditorWorldExtensionManager - EditorWorldExtensions are sort of like a more modern version of 'FEdMode', but still a work in progress - Cleaned up access to VREditorMode from other modules, forcing systems to go through EditorWorldExtensions - Overhauled how transforming objects works with world interaction - Viewport interactors can now be used to move objects other than actors around (by implementing an UViewportTransformer, and a FViewportTransformable) - Undo/Redo now works better with inertial transformation! The transaction only ends when objects finally come to rest. - Some initial support for 'grabber sphere' interactor methods has been implemented (not used yet) - Viewport interaction input events now receive the viewport being interacted through - Viewport interaction hover events no longer get a viewport client (because they must be designed to work any number of viewports.) NOTE: This introduces UBT warnings about cyclic module dependencies. We'll have to address this in a different changelist. Other changes: - The active Viewport Interaction 'gizmo mode' is now tied directly to the editor's normal gizmo mode. They share the same state. - New console variable 'VI.UseTransientActors' can be turned off to force editor actors to be created non-transient to make it easier to debug - New console variable 'VI.DragTranslationVelocityStopEpsilon' sets the speed at which transformables will stop have inertia applied to them - Fixed cyclic dependencies with ViewportInteraction and VREditor modules not being tagged properly for UBT - Fixed some issues with transform gizmos not getting release events - Various methods that should have been const were made const - Eliminated duplicate implementation of SpawnTransientSceneActor and DestroyTransientActor; made it static - UnrealEd no longer directly depends on VREditor and ViewportInteraction modules - Engine: AActor::SetIsTemporarilyHiddenInEditor no longer does any work if the object's hidden state didn't change - Slate: Input preprocessor (if bound) now also gets a chance at mouse button down and up events #codereview yannick.lange,lauren.ridge #rb various [CL 3245240 by Mike Fricker in Dev-VREditor branch]
2017-01-03 14:38:17 -05:00
// Make sure we have a valid viewport with a cursor over it, and that the viewport's world is the same as ours
FEditorViewportClient* ViewportClientPtr = GCurrentLevelEditingViewportClient;
if( ViewportClientPtr != nullptr && ViewportClientPtr->GetWorld() == WorldInteraction->GetWorld() )
{
ViewportInteraction refactoring; miscellaneous VREditor improvements - This merge contains various changes to ViewportInteraction and VR Editor to make things more extensible - Some changes are from Yannick's recent shelved refactoring work, that I've modified and improved upon - EditorWorldManager is gone and replaced by EditorWorldExtensionManager - EditorWorldExtensions are sort of like a more modern version of 'FEdMode', but still a work in progress - Cleaned up access to VREditorMode from other modules, forcing systems to go through EditorWorldExtensions - Overhauled how transforming objects works with world interaction - Viewport interactors can now be used to move objects other than actors around (by implementing an UViewportTransformer, and a FViewportTransformable) - Undo/Redo now works better with inertial transformation! The transaction only ends when objects finally come to rest. - Some initial support for 'grabber sphere' interactor methods has been implemented (not used yet) - Viewport interaction input events now receive the viewport being interacted through - Viewport interaction hover events no longer get a viewport client (because they must be designed to work any number of viewports.) NOTE: This introduces UBT warnings about cyclic module dependencies. We'll have to address this in a different changelist. Other changes: - The active Viewport Interaction 'gizmo mode' is now tied directly to the editor's normal gizmo mode. They share the same state. - New console variable 'VI.UseTransientActors' can be turned off to force editor actors to be created non-transient to make it easier to debug - New console variable 'VI.DragTranslationVelocityStopEpsilon' sets the speed at which transformables will stop have inertia applied to them - Fixed cyclic dependencies with ViewportInteraction and VREditor modules not being tagged properly for UBT - Fixed some issues with transform gizmos not getting release events - Various methods that should have been const were made const - Eliminated duplicate implementation of SpawnTransientSceneActor and DestroyTransientActor; made it static - UnrealEd no longer directly depends on VREditor and ViewportInteraction modules - Engine: AActor::SetIsTemporarilyHiddenInEditor no longer does any work if the object's hidden state didn't change - Slate: Input preprocessor (if bound) now also gets a chance at mouse button down and up events #codereview yannick.lange,lauren.ridge #rb various [CL 3245240 by Mike Fricker in Dev-VREditor branch]
2017-01-03 14:38:17 -05:00
FEditorViewportClient& ViewportClient = *ViewportClientPtr;
bIsControlKeyPressed = ViewportClient.Viewport->KeyState( EKeys::LeftControl ) || ViewportClient.Viewport->KeyState( EKeys::RightControl );
ViewportInteraction refactoring; miscellaneous VREditor improvements - This merge contains various changes to ViewportInteraction and VR Editor to make things more extensible - Some changes are from Yannick's recent shelved refactoring work, that I've modified and improved upon - EditorWorldManager is gone and replaced by EditorWorldExtensionManager - EditorWorldExtensions are sort of like a more modern version of 'FEdMode', but still a work in progress - Cleaned up access to VREditorMode from other modules, forcing systems to go through EditorWorldExtensions - Overhauled how transforming objects works with world interaction - Viewport interactors can now be used to move objects other than actors around (by implementing an UViewportTransformer, and a FViewportTransformable) - Undo/Redo now works better with inertial transformation! The transaction only ends when objects finally come to rest. - Some initial support for 'grabber sphere' interactor methods has been implemented (not used yet) - Viewport interaction input events now receive the viewport being interacted through - Viewport interaction hover events no longer get a viewport client (because they must be designed to work any number of viewports.) NOTE: This introduces UBT warnings about cyclic module dependencies. We'll have to address this in a different changelist. Other changes: - The active Viewport Interaction 'gizmo mode' is now tied directly to the editor's normal gizmo mode. They share the same state. - New console variable 'VI.UseTransientActors' can be turned off to force editor actors to be created non-transient to make it easier to debug - New console variable 'VI.DragTranslationVelocityStopEpsilon' sets the speed at which transformables will stop have inertia applied to them - Fixed cyclic dependencies with ViewportInteraction and VREditor modules not being tagged properly for UBT - Fixed some issues with transform gizmos not getting release events - Various methods that should have been const were made const - Eliminated duplicate implementation of SpawnTransientSceneActor and DestroyTransientActor; made it static - UnrealEd no longer directly depends on VREditor and ViewportInteraction modules - Engine: AActor::SetIsTemporarilyHiddenInEditor no longer does any work if the object's hidden state didn't change - Slate: Input preprocessor (if bound) now also gets a chance at mouse button down and up events #codereview yannick.lange,lauren.ridge #rb various [CL 3245240 by Mike Fricker in Dev-VREditor branch]
2017-01-03 14:38:17 -05:00
// Only if we're not tracking (RMB looking)
if( !ViewportClient.IsTracking() )
{
ViewportInteraction refactoring; miscellaneous VREditor improvements - This merge contains various changes to ViewportInteraction and VR Editor to make things more extensible - Some changes are from Yannick's recent shelved refactoring work, that I've modified and improved upon - EditorWorldManager is gone and replaced by EditorWorldExtensionManager - EditorWorldExtensions are sort of like a more modern version of 'FEdMode', but still a work in progress - Cleaned up access to VREditorMode from other modules, forcing systems to go through EditorWorldExtensions - Overhauled how transforming objects works with world interaction - Viewport interactors can now be used to move objects other than actors around (by implementing an UViewportTransformer, and a FViewportTransformable) - Undo/Redo now works better with inertial transformation! The transaction only ends when objects finally come to rest. - Some initial support for 'grabber sphere' interactor methods has been implemented (not used yet) - Viewport interaction input events now receive the viewport being interacted through - Viewport interaction hover events no longer get a viewport client (because they must be designed to work any number of viewports.) NOTE: This introduces UBT warnings about cyclic module dependencies. We'll have to address this in a different changelist. Other changes: - The active Viewport Interaction 'gizmo mode' is now tied directly to the editor's normal gizmo mode. They share the same state. - New console variable 'VI.UseTransientActors' can be turned off to force editor actors to be created non-transient to make it easier to debug - New console variable 'VI.DragTranslationVelocityStopEpsilon' sets the speed at which transformables will stop have inertia applied to them - Fixed cyclic dependencies with ViewportInteraction and VREditor modules not being tagged properly for UBT - Fixed some issues with transform gizmos not getting release events - Various methods that should have been const were made const - Eliminated duplicate implementation of SpawnTransientSceneActor and DestroyTransientActor; made it static - UnrealEd no longer directly depends on VREditor and ViewportInteraction modules - Engine: AActor::SetIsTemporarilyHiddenInEditor no longer does any work if the object's hidden state didn't change - Slate: Input preprocessor (if bound) now also gets a chance at mouse button down and up events #codereview yannick.lange,lauren.ridge #rb various [CL 3245240 by Mike Fricker in Dev-VREditor branch]
2017-01-03 14:38:17 -05:00
FViewport* Viewport = ViewportClient.Viewport;
ViewportInteraction refactoring; miscellaneous VREditor improvements - This merge contains various changes to ViewportInteraction and VR Editor to make things more extensible - Some changes are from Yannick's recent shelved refactoring work, that I've modified and improved upon - EditorWorldManager is gone and replaced by EditorWorldExtensionManager - EditorWorldExtensions are sort of like a more modern version of 'FEdMode', but still a work in progress - Cleaned up access to VREditorMode from other modules, forcing systems to go through EditorWorldExtensions - Overhauled how transforming objects works with world interaction - Viewport interactors can now be used to move objects other than actors around (by implementing an UViewportTransformer, and a FViewportTransformable) - Undo/Redo now works better with inertial transformation! The transaction only ends when objects finally come to rest. - Some initial support for 'grabber sphere' interactor methods has been implemented (not used yet) - Viewport interaction input events now receive the viewport being interacted through - Viewport interaction hover events no longer get a viewport client (because they must be designed to work any number of viewports.) NOTE: This introduces UBT warnings about cyclic module dependencies. We'll have to address this in a different changelist. Other changes: - The active Viewport Interaction 'gizmo mode' is now tied directly to the editor's normal gizmo mode. They share the same state. - New console variable 'VI.UseTransientActors' can be turned off to force editor actors to be created non-transient to make it easier to debug - New console variable 'VI.DragTranslationVelocityStopEpsilon' sets the speed at which transformables will stop have inertia applied to them - Fixed cyclic dependencies with ViewportInteraction and VREditor modules not being tagged properly for UBT - Fixed some issues with transform gizmos not getting release events - Various methods that should have been const were made const - Eliminated duplicate implementation of SpawnTransientSceneActor and DestroyTransientActor; made it static - UnrealEd no longer directly depends on VREditor and ViewportInteraction modules - Engine: AActor::SetIsTemporarilyHiddenInEditor no longer does any work if the object's hidden state didn't change - Slate: Input preprocessor (if bound) now also gets a chance at mouse button down and up events #codereview yannick.lange,lauren.ridge #rb various [CL 3245240 by Mike Fricker in Dev-VREditor branch]
2017-01-03 14:38:17 -05:00
// Make sure we have a valid viewport, otherwise we won't be able to construct an FSceneView. The first time we're ticked we might not be properly setup. (@todo viewportinteraction)
if( Viewport != nullptr && Viewport->GetSizeXY().GetMin() > 0 )
{
const int32 ViewportInteractX = Viewport->GetMouseX();
const int32 ViewportInteractY = Viewport->GetMouseY();
ViewportInteraction refactoring; miscellaneous VREditor improvements - This merge contains various changes to ViewportInteraction and VR Editor to make things more extensible - Some changes are from Yannick's recent shelved refactoring work, that I've modified and improved upon - EditorWorldManager is gone and replaced by EditorWorldExtensionManager - EditorWorldExtensions are sort of like a more modern version of 'FEdMode', but still a work in progress - Cleaned up access to VREditorMode from other modules, forcing systems to go through EditorWorldExtensions - Overhauled how transforming objects works with world interaction - Viewport interactors can now be used to move objects other than actors around (by implementing an UViewportTransformer, and a FViewportTransformable) - Undo/Redo now works better with inertial transformation! The transaction only ends when objects finally come to rest. - Some initial support for 'grabber sphere' interactor methods has been implemented (not used yet) - Viewport interaction input events now receive the viewport being interacted through - Viewport interaction hover events no longer get a viewport client (because they must be designed to work any number of viewports.) NOTE: This introduces UBT warnings about cyclic module dependencies. We'll have to address this in a different changelist. Other changes: - The active Viewport Interaction 'gizmo mode' is now tied directly to the editor's normal gizmo mode. They share the same state. - New console variable 'VI.UseTransientActors' can be turned off to force editor actors to be created non-transient to make it easier to debug - New console variable 'VI.DragTranslationVelocityStopEpsilon' sets the speed at which transformables will stop have inertia applied to them - Fixed cyclic dependencies with ViewportInteraction and VREditor modules not being tagged properly for UBT - Fixed some issues with transform gizmos not getting release events - Various methods that should have been const were made const - Eliminated duplicate implementation of SpawnTransientSceneActor and DestroyTransientActor; made it static - UnrealEd no longer directly depends on VREditor and ViewportInteraction modules - Engine: AActor::SetIsTemporarilyHiddenInEditor no longer does any work if the object's hidden state didn't change - Slate: Input preprocessor (if bound) now also gets a chance at mouse button down and up events #codereview yannick.lange,lauren.ridge #rb various [CL 3245240 by Mike Fricker in Dev-VREditor branch]
2017-01-03 14:38:17 -05:00
FSceneViewFamilyContext ViewFamily( FSceneViewFamily::ConstructionValues(
Viewport,
ViewportClient.GetScene(),
ViewportClient.EngineShowFlags )
.SetRealtimeUpdate( ViewportClient.IsRealtime() ) );
FSceneView* SceneView = ViewportClient.CalcSceneView( &ViewFamily );
ViewportInteraction refactoring; miscellaneous VREditor improvements - This merge contains various changes to ViewportInteraction and VR Editor to make things more extensible - Some changes are from Yannick's recent shelved refactoring work, that I've modified and improved upon - EditorWorldManager is gone and replaced by EditorWorldExtensionManager - EditorWorldExtensions are sort of like a more modern version of 'FEdMode', but still a work in progress - Cleaned up access to VREditorMode from other modules, forcing systems to go through EditorWorldExtensions - Overhauled how transforming objects works with world interaction - Viewport interactors can now be used to move objects other than actors around (by implementing an UViewportTransformer, and a FViewportTransformable) - Undo/Redo now works better with inertial transformation! The transaction only ends when objects finally come to rest. - Some initial support for 'grabber sphere' interactor methods has been implemented (not used yet) - Viewport interaction input events now receive the viewport being interacted through - Viewport interaction hover events no longer get a viewport client (because they must be designed to work any number of viewports.) NOTE: This introduces UBT warnings about cyclic module dependencies. We'll have to address this in a different changelist. Other changes: - The active Viewport Interaction 'gizmo mode' is now tied directly to the editor's normal gizmo mode. They share the same state. - New console variable 'VI.UseTransientActors' can be turned off to force editor actors to be created non-transient to make it easier to debug - New console variable 'VI.DragTranslationVelocityStopEpsilon' sets the speed at which transformables will stop have inertia applied to them - Fixed cyclic dependencies with ViewportInteraction and VREditor modules not being tagged properly for UBT - Fixed some issues with transform gizmos not getting release events - Various methods that should have been const were made const - Eliminated duplicate implementation of SpawnTransientSceneActor and DestroyTransientActor; made it static - UnrealEd no longer directly depends on VREditor and ViewportInteraction modules - Engine: AActor::SetIsTemporarilyHiddenInEditor no longer does any work if the object's hidden state didn't change - Slate: Input preprocessor (if bound) now also gets a chance at mouse button down and up events #codereview yannick.lange,lauren.ridge #rb various [CL 3245240 by Mike Fricker in Dev-VREditor branch]
2017-01-03 14:38:17 -05:00
const FViewportCursorLocation MouseViewportRay( SceneView, &ViewportClient, ViewportInteractX, ViewportInteractY );
FVector RayOrigin = MouseViewportRay.GetOrigin();
// If we're dealing with an orthographic view, push the origin of the ray backward along the viewport forward axis
// to make sure that we can select objects that are behind the origin!
if( !ViewportClient.IsPerspective() )
{
const float HalfLaserPointerLength = this->GetLaserPointerMaxLength() * 0.5f;
RayOrigin -= MouseViewportRay.GetDirection() * HalfLaserPointerLength;
}
InteractorData.Transform = FTransform( MouseViewportRay.GetDirection().ToOrientationQuat(), RayOrigin, FVector( 1.0f ) );
}
}
}
InteractorData.RoomSpaceTransform = InteractorData.Transform * WorldInteraction->GetRoomTransform().Inverse();
}
bool UMouseCursorInteractor::IsModifierPressed() const
{
return bIsControlKeyPressed;
}
bool UMouseCursorInteractor::AllowLaserSmoothing() const
{
return false;
}