Files
UnrealEngineUWP/Engine/Source/Editor/VREditor/VREditorBaseActor.cpp

216 lines
6.2 KiB
C++
Raw Normal View History

// Copyright 1998-2017 Epic Games, Inc. All Rights Reserved.
#include "VREditorBaseActor.h"
#include "VREditorMode.h"
#include "VREditorInteractor.h"
namespace VREd
{
static FAutoConsoleVariable UIOnHandRotationOffset( TEXT( "VREd.UIOnHandRotationOffset" ), 45.0f, TEXT( "Rotation offset for UI that's docked to your hand, to make it more comfortable to hold" ) );
static FAutoConsoleVariable UIOnArmRotationOffset( TEXT( "VREd.UIOnArmRotationOffset" ), 0.0f, TEXT( "Rotation offset for UI that's docked to your arm, so it aligns with the controllers" ) );
static FAutoConsoleVariable DockUISmoothingAmount( TEXT( "VREd.DockUISmoothingAmount" ), 0.75f, TEXT( "How much to smooth out UI transforms (frame rate sensitive)" ) );
}
AVREditorBaseActor::AVREditorBaseActor()
: Super(),
Scale( 1.0f ),
LocalRotation( FRotator( 90.0f, 180.0f, 0.0f ) ),
RelativeOffset( FVector::ZeroVector ),
DockedTo( EDockedTo::Nothing ),
PreviousDockedTo( EDockedTo::Nothing ),
bIsMoving( false ),
MoveToTransform( FTransform() ),
StartMoveToTransform( FTransform() ),
MoveToAlpha( 0.0f ),
MoveToTime( 0.0f ),
MoveToResultDock( EDockedTo::Nothing ),
LastDockedUIToWorld()
{
}
void AVREditorBaseActor::SetVRMode( UVREditorMode* InVRMode )
{
VRMode = InVRMode;
}
void AVREditorBaseActor::TickManually( float DeltaTime )
{
Super::Tick( DeltaTime );
// Update fading state
UpdateFadingState( DeltaTime );
if ( bIsMoving )
{
TickMoveTo( DeltaTime );
}
else
{
// Update transform
UpdateTransformIfDocked();
}
}
void AVREditorBaseActor::SetRelativeOffset( const FVector& InRelativeOffset )
{
RelativeOffset = InRelativeOffset;
}
void AVREditorBaseActor::SetLocalRotation( const FRotator& InLocalRotation )
{
LocalRotation = InLocalRotation;
}
void AVREditorBaseActor::SetDockedTo( const EDockedTo NewDockedTo )
{
PreviousDockedTo = DockedTo;
DockedTo = NewDockedTo;
UpdateTransformIfDocked();
}
void AVREditorBaseActor::MoveTo( const FTransform& ResultTransform, const float TotalMoveToTime, const EDockedTo ResultDock )
{
MoveToTime = TotalMoveToTime;
bIsMoving = true;
StartMoveToTransform = GetActorTransform();
MoveToTransform = ResultTransform;
MoveToAlpha = 0.0f;
MoveToResultDock = ResultDock;
}
void AVREditorBaseActor::StopMoveTo()
{
bIsMoving = false;
SetTransform( MoveToTransform );
MoveToTransform = FTransform();
}
FTransform AVREditorBaseActor::MakeUITransformLockedToHand( UViewportInteractor* Interactor, const bool bOnArm, const FVector& InRelativeOffset, const FRotator& InLocalRotation )
{
const float WorldScaleFactor = VRMode->GetWorldScaleFactor();
FTransform UIToHandTransform( InLocalRotation, InRelativeOffset * WorldScaleFactor );
// If the UI is on the hand
if ( !bOnArm )
{
UIToHandTransform *= FTransform( FRotator( VREd::UIOnHandRotationOffset->GetFloat(), 0.0f, 0.0f ).Quaternion(), FVector::ZeroVector );
}
// If the UI is on the arm
else
{
UIToHandTransform *= FTransform( FRotator( VREd::UIOnArmRotationOffset->GetFloat(), 0.0f, 0.0f ).Quaternion(), FVector::ZeroVector );
}
const FTransform HandToWorldTransform = Interactor->GetTransform();
FTransform UIToWorldTransform = UIToHandTransform * HandToWorldTransform;
UIToWorldTransform.SetScale3D( FVector( Scale * WorldScaleFactor ) );
return UIToWorldTransform;
}
void AVREditorBaseActor::UpdateTransformIfDocked()
{
if ( DockedTo != EDockedTo::Nothing && DockedTo != EDockedTo::Dragging )
{
FTransform NewTransform;
if ( DockedTo == EDockedTo::LeftHand )
{
const bool bOnArm = false;
NewTransform = MakeUITransformLockedToHand( VRMode->GetHandInteractor( EControllerHand::Left ), bOnArm );
}
else if ( DockedTo == EDockedTo::RightHand )
{
const bool bOnArm = false;
NewTransform = MakeUITransformLockedToHand( VRMode->GetHandInteractor( EControllerHand::Right ), bOnArm );
}
else if ( DockedTo == EDockedTo::LeftArm )
{
const bool bOnArm = true;
NewTransform = MakeUITransformLockedToHand( VRMode->GetHandInteractor( EControllerHand::Left ), bOnArm );
}
else if ( DockedTo == EDockedTo::RightArm )
{
const bool bOnArm = true;
NewTransform = MakeUITransformLockedToHand( VRMode->GetHandInteractor( EControllerHand::Right ), bOnArm );
}
else if ( DockedTo == EDockedTo::Room )
{
NewTransform = MakeUITransformLockedToRoom();
}
else if ( DockedTo == EDockedTo::Custom )
{
NewTransform = MakeCustomUITransform();
}
else
{
check( 0 );
}
// Smooth out the transform
if( DockedTo != EDockedTo::Custom && DockedTo != EDockedTo::Room )
{
if( LastDockedUIToWorld.IsSet() )
{
FTransform SmoothedDockedUIToWorld;
SmoothedDockedUIToWorld.Blend( NewTransform, LastDockedUIToWorld.GetValue(), VREd::DockUISmoothingAmount->GetFloat() );
NewTransform = SmoothedDockedUIToWorld;
}
LastDockedUIToWorld = NewTransform;
}
else
{
LastDockedUIToWorld.Reset();
}
SetTransform( NewTransform );
}
else
{
LastDockedUIToWorld.Reset();
}
}
FTransform AVREditorBaseActor::MakeUITransformLockedToHand( UViewportInteractor* Interactor, const bool bOnArm )
{
return MakeUITransformLockedToHand( Interactor, bOnArm, RelativeOffset, LocalRotation );
}
FTransform AVREditorBaseActor::MakeUITransformLockedToRoom()
{
const float WorldScaleFactor = VRMode->GetWorldScaleFactor();
const FTransform UIToRoomTransform( LocalRotation, RelativeOffset * WorldScaleFactor );
const FTransform RoomToWorldTransform = VRMode->GetRoomTransform();
FTransform UIToWorldTransform = UIToRoomTransform * RoomToWorldTransform;
UIToWorldTransform.SetScale3D( FVector( Scale * WorldScaleFactor ) );
return UIToWorldTransform;
}
void AVREditorBaseActor::TickMoveTo( const float DeltaTime )
{
const float WorldScaleFactor = VRMode->GetWorldScaleFactor();
MoveToAlpha += DeltaTime;
const float LerpTime = MoveToTime;
if ( MoveToAlpha > MoveToTime )
{
MoveToAlpha = MoveToTime;
bIsMoving = false;
SetDockedTo( MoveToResultDock );
}
const float CurrentALpha = MoveToAlpha / LerpTime;
const FVector NewLocation = FMath::Lerp( StartMoveToTransform.GetLocation(), MoveToTransform.GetLocation(), CurrentALpha );
const FQuat NewRotation = FMath::Lerp( StartMoveToTransform.GetRotation(), MoveToTransform.GetRotation(), CurrentALpha );
FTransform NewTransform( NewRotation, NewLocation, FVector( Scale * WorldScaleFactor ) );
SetTransform( NewTransform );
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
}