Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified Content/VirtualRealityCPP/Blueprints/MotionControllerHand.uasset
Binary file not shown.
10 changes: 9 additions & 1 deletion Source/VRCode/VRCode.Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,15 @@ public class VRCode : ModuleRules
{
public VRCode(ReadOnlyTargetRules ROTargetRules) : base(ROTargetRules)
{
PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore", "HeadMountedDisplay" });
PublicDependencyModuleNames.AddRange(new string[]
{
"Core",
"CoreUObject",
"Engine",
"InputCore",
"HeadMountedDisplay",
"SteamVR"
});

PrivateDependencyModuleNames.AddRange(new string[] { });

Expand Down
65 changes: 61 additions & 4 deletions Source/VRCode/VRHand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "Runtime/Engine/Classes/Kismet/KismetMathLibrary.h"
#include "Runtime/Engine/Classes/Kismet/HeadMountedDisplayFunctionLibrary.h"
#include "Runtime/Engine/Classes/Components/SplineMeshComponent.h"
#include "SteamVRChaperoneComponent.h"

// Sets default values
AVRHand::AVRHand() :
Expand Down Expand Up @@ -64,7 +65,12 @@ AVRHand::AVRHand() :

TeleportArrow = CreateDefaultSubobject<UStaticMeshComponent>( TEXT( "TeleportArrow" ) );
TeleportArrow->SetupAttachment( TeleportCylinder );


RoomScaleMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("RoomScaleMesh"));
RoomScaleMesh->SetupAttachment( TeleportArrow );

SteamVRChaperone = CreateDefaultSubobject<USteamVRChaperoneComponent>(TEXT("SteamVRChaperone"));

}

void AVRHand::OnConstruction(const FTransform & Transform)
Expand Down Expand Up @@ -105,6 +111,8 @@ void AVRHand::BeginPlay()
{
Super::BeginPlay();

SetupRoomScaleOutline();

MotionController->Hand = Hand;
if ( Hand == EControllerHand::Left )
{
Expand Down Expand Up @@ -229,7 +237,7 @@ void AVRHand::Tick( float DeltaTime )
FVector HitLocation;
bool IsValidTeleportDestination = TraceTeleportDestination( TracePoints, NavLocation, HitLocation );

TeleportCylinder->SetVisibility( IsValidTeleportDestination, true );
UpdateRoomScaleOutline();

if ( IsValidTeleportDestination )
{
Expand Down Expand Up @@ -331,7 +339,11 @@ void AVRHand::ActivateTeleporter()
// if ( GEngine ) GEngine->AddOnScreenDebugMessage( -1, 0.16f, FColor::White, FString::Printf( TEXT( "Activating Teleporter " ) ) );
IsTeleporterActive = true;

if ( MotionController )
TeleportCylinder->SetVisibility(true, true);

TeleportCylinder->SetVisibility(IsRoomScale, false);

if (MotionController)
InitialControllerRotation = MotionController->GetComponentRotation();
}

Expand Down Expand Up @@ -413,4 +425,49 @@ FRotator AVRHand::GetControllerRelativeRotation()
const FTransform RelativeTransform = CurrentTransform.GetRelativeTransform( InitialTransform );

return RelativeTransform.GetRotation().Rotator();
}
}

void AVRHand::SetupRoomScaleOutline()
{
auto Vertices = SteamVRChaperone->GetBounds();
auto Normal = FVector(0.0f, 0.0f, 1.0f);

FVector RectCenter;
FRotator RectRotation;
float SideLengthX, SideLengthY;

UKismetMathLibrary::MinimumAreaRectangle(GetWorld(), Vertices, Normal, RectCenter, RectRotation, SideLengthX, SideLengthY);

if (FMath::IsNearlyEqual(SideLengthX, 100.0f, 0.01f) || FMath::IsNearlyEqual(SideLengthY, 100.0f, 0.01f))
{
IsRoomScale = false;
return; // Measure Chaperone (Defaults to 100x100 if roomscale isn't used)
}

IsRoomScale = true;

// Setup Room-scale mesh (1x1x1 units in size by default) to the size of the room-scale dimensions
RoomScaleMesh->SetWorldScale3D(FVector(SideLengthX, SideLengthY, ChaperoneMeshHeight));
RoomScaleMesh->SetRelativeRotation(RectRotation);
}

void AVRHand::UpdateRoomScaleOutline()
{
if (RoomScaleMesh->IsVisible())
{
FRotator DeviceRotation;
FVector DevicePosition;
UHeadMountedDisplayFunctionLibrary::GetOrientationAndPosition(DeviceRotation, DevicePosition);

DeviceRotation.Pitch = 0;
DeviceRotation.Roll = 0;

DevicePosition.X = -DevicePosition.X;
DevicePosition.Y = -DevicePosition.Y;
DevicePosition.Z = 0;

FVector NewLocation = DeviceRotation.UnrotateVector(DevicePosition);

RoomScaleMesh->SetRelativeLocation(NewLocation, false, nullptr, ETeleportType::None);
}
}
16 changes: 16 additions & 0 deletions Source/VRCode/VRHand.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

#include "VRHand.generated.h"

class USteamVRChaperoneComponent;

UENUM(BlueprintType)
enum class EGripState : uint8
{
Expand Down Expand Up @@ -54,6 +56,12 @@ class VRCODE_API AVRHand : public AActor
class UStaticMeshComponent *TeleportArrow;


UPROPERTY( VisibleAnywhere, BlueprintReadOnly, Category = "Code Components", meta = ( AllowPrivateAccess = "true" ) )
class UStaticMeshComponent *RoomScaleMesh;

UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Code Components", meta = (AllowPrivateAccess = "true"))
class USteamVRChaperoneComponent *SteamVRChaperone;

FRotator InitialControllerRotation;
TArray<class USplineMeshComponent*> SplineMeshes;
public:
Expand Down Expand Up @@ -83,6 +91,12 @@ class VRCODE_API AVRHand : public AActor
UPROPERTY( EditAnywhere, BlueprintReadWrite, Category = "Code Variables" )
bool IsTeleporterActive;

UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Code Variables")
bool IsRoomScale = false;

UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Code Variables")
float ChaperoneMeshHeight = 70;

UPROPERTY( EditAnywhere, BlueprintReadWrite, Category = "Code Variables" )
EGripState Grip;

Expand Down Expand Up @@ -127,4 +141,6 @@ class VRCODE_API AVRHand : public AActor

FRotator GetControllerRelativeRotation();

void SetupRoomScaleOutline();
void UpdateRoomScaleOutline();
};