A Demo Project for the UnrealEngineSDK
Loading...
Searching...
No Matches
DynamicHieghtFloor.cpp
Go to the documentation of this file.
1// Copyright(c) Pixo Group. All Rights Reserved.
2
3
5#include "HeadMountedDisplayFunctionLibrary.h"
6#include "Engine/Engine.h"
7#include "IXRTrackingSystem.h"
8#include "PixoVRCharacter.h"
9#include "Components/BoxComponent.h"
10#include "Kismet/GameplayStatics.h"
11#include "Kismet/KismetMathLibrary.h"
12
14{
15 PrimaryActorTick.bCanEverTick = true;
16
17 BoxCollision = CreateDefaultSubobject<UBoxComponent>("BoxCollision");
18 BoxCollision->InitBoxExtent(FVector(100,100,24));
19}
20
22{
23 Super::BeginPlay();
24 if (UGameplayStatics::GetPlatformName() == "Android" && GEngine->XRSystem->IsHeadTrackingAllowed())
25 {
26 GetWorldTimerManager().SetTimerForNextTick(this, &ADynamicHieghtFloor::AdjustCameraHeight);
27 }
28}
29
31{
32 FRotator DeviceOrientation;
33 FVector DevicePosition;
34
35 //Get Device Camera position
36 UHeadMountedDisplayFunctionLibrary::GetOrientationAndPosition(DeviceOrientation, DevicePosition);
37
38 // Temporary decision, need investigation
39 if (UHeadMountedDisplayFunctionLibrary::GetHMDDeviceName() == "OculusHMD")
40 {
41 return;
42 }
43
44 //Get difference between floor and Device Camera Position
45 const float RelativeHeight = UKismetMathLibrary::TransformLocation(BoxCollision->GetComponentTransform(), DevicePosition).Z;
46
47 //Set floor to adjust Camera position
48 SetFloorHeight(DesiredCameraHeight - RelativeHeight);
49}
50
52{
53 if (Height > 100.0 || Height < -100.0)
54 {
55 GEngine->AddOnScreenDebugMessage(-1, 10.0, FColor::Red, TEXT("Error - Floor height is more/less than 100 units"));
56 UE_LOG(LogTemp, Error, TEXT("Error - Floor height is more/less than 100 units"));
57 return;
58 }
59 BoxCollision->SetRelativeLocation(FVector(.0, .0, Height));
60}
class UBoxComponent * BoxCollision
UPROPERTY(EditAnywhere, BlueprintReadWrite)
virtual void BeginPlay() override
void SetFloorHeight(float Height)
UFUNCTION(BlueprintCallable, Category = "Dynamic Floor")
float DesiredCameraHeight
UPROPERTY(EditAnywhere, BlueprintReadWrite)
void AdjustCameraHeight()
UFUNCTION(BlueprintCallable, Category = "Dynamic Floor")