Skip to content
Snippets Groups Projects
Commit 8209a767 authored by Sebastian Pape's avatar Sebastian Pape
Browse files

Constant reference updating

parent 8999b74d
No related branches found
No related tags found
1 merge request!4Develop
......@@ -55,8 +55,8 @@ ACAVEOverlayController::ACAVEOverlayController()
loadAsset(TEXT("/CAVEOverlay/StopMaterial"), sign_material_);
loadAsset(TEXT("/CAVEOverlay/Plane"), plane_mesh_);
tape_material_dynamic_ = UMaterialInstanceDynamic::Create(tape_material_, tape_material_);
sign_material_dynamic_ = UMaterialInstanceDynamic::Create(sign_material_, sign_material_);
tape_material_dynamic_ = UMaterialInstanceDynamic::Create(tape_material_, NULL);
sign_material_dynamic_ = UMaterialInstanceDynamic::Create(sign_material_, NULL);
tape_negative_y = createMeshComponent(FName("TapeNegY"), tape_material_dynamic_, plane_mesh_, tape_root);
tape_negative_x = createMeshComponent(FName("TapeNegX"), tape_material_dynamic_, plane_mesh_, tape_root);
......@@ -102,24 +102,27 @@ void ACAVEOverlayController::SetDoorMode(DOOR_MODE m)
switch (door_current_mode_) {
case DOOR_MODE::DOOR_PARTIAL_OPEN:
door_current_opening_width_absolute_ = door_opening_width_absolute_;
if (screen_type_ == SCREEN_DOOR) overlay_->BlackBox->SetRenderScale(FVector2D(0, 1));
if (screen_type_ == SCREEN_DOOR_PARTIAL) overlay_->BlackBox->SetRenderScale(FVector2D(door_opening_width_relative_, 1));
if (screen_type_ == SCREEN_MASTER) overlay_->BlackBox->SetRenderScale(FVector2D(door_opening_width_relative_, 1));
if (screen_type_ == SCREEN_MASTER) overlay_->BlackBox->SetRenderScale(FVector2D(0, 1));
overlay_->BlackBox->SetVisibility(ESlateVisibility::Visible);
break;
case DOOR_MODE::DOOR_OPEN:
door_current_opening_width_absolute_ = wall_distance_ * 2;
if (screen_type_ == SCREEN_DOOR) overlay_->BlackBox->SetRenderScale(FVector2D(1, 1));
if (screen_type_ == SCREEN_DOOR_PARTIAL) overlay_->BlackBox->SetRenderScale(FVector2D(1, 1));
if (screen_type_ == SCREEN_MASTER) overlay_->BlackBox->SetRenderScale(FVector2D(1, 1));
overlay_->BlackBox->SetVisibility(ESlateVisibility::Visible);
break;
case DOOR_MODE::DOOR_CLOSED:
door_current_opening_width_absolute_ = 0;
if (screen_type_ == SCREEN_DOOR) overlay_->BlackBox->SetRenderScale(FVector2D(0, 1));
if (screen_type_ == SCREEN_DOOR_PARTIAL) overlay_->BlackBox->SetRenderScale(FVector2D(0, 1));
if (screen_type_ == SCREEN_MASTER) overlay_->BlackBox->SetRenderScale(FVector2D(0, 1));
overlay_->BlackBox->SetVisibility(ESlateVisibility::Hidden);
break;
}
if (screen_type_ == SCREEN_DOOR_PARTIAL) overlay_->BlackBox->SetRenderScale(FVector2D(0, 1)); //No black overlay
if (screen_type_ == SCREEN_NORMAL) overlay_->BlackBox->SetRenderScale(FVector2D(0, 1)); //no overlay
UE_LOG(CAVEOverlayLog, Log, TEXT("Switched door state to '%s'. New opening width is %f."), *door_mode_names_[door_current_mode_], door_current_opening_width_absolute_);
overlay_->CornerText->SetText(FText::FromString(door_mode_names_[door_current_mode_]));
......@@ -141,7 +144,6 @@ void ACAVEOverlayController::BeginPlay()
display_cluster_mode_ = IDisplayCluster::Get().GetOperationMode() == EDisplayClusterOperationMode::Cluster;
//Determine the screentype for later usage
screen_type_ = SCREEN_NORMAL;
if (IDisplayCluster::Get().GetClusterMgr()->GetNodeId().Equals(screen_main, ESearchCase::IgnoreCase)) {
screen_type_ = SCREEN_MASTER;
}
......@@ -151,6 +153,9 @@ void ACAVEOverlayController::BeginPlay()
else if (containsFString(screens_door_partial_, IDisplayCluster::Get().GetClusterMgr()->GetNodeId())) {
screen_type_ = SCREEN_DOOR_PARTIAL;
}
else {
screen_type_ = SCREEN_NORMAL;
}
overlay_ = CreateWidget<UDoorOverlayData>(GetWorld()->GetFirstPlayerController(), overlay_class_);
overlay_->AddToViewport(0);
......@@ -158,12 +163,7 @@ void ACAVEOverlayController::BeginPlay()
overlay_->CornerText->SetText(FText::FromString("")); //Set Text to "" until someone presses the key for the first time
player_pawn_ = Cast<AVirtualRealityPawn>(GetWorld()->GetFirstPlayerController()->GetPawn());
TArray<UDisplayClusterSceneComponent*> pawn_components;
player_pawn_->GetComponents<UDisplayClusterSceneComponent>(pawn_components);
for (UDisplayClusterSceneComponent* c : pawn_components) {
if (c->GetName().Equals("cave_origin", ESearchCase::IgnoreCase)) cave_origin_ = c;
if (c->GetName().Equals("shutter_glasses", ESearchCase::IgnoreCase)) cave_origin_ = c;
}
refreshPawnComponents();
}
float ACAVEOverlayController::calculateOpacityFromPosition(FVector position) {
......@@ -175,6 +175,15 @@ bool ACAVEOverlayController::positionInDoorOpening(FVector position) {
&& FMath::IsWithinInclusive(position.Y, wall_distance_ + 10 - door_current_opening_width_absolute_, wall_distance_ + 10); //Overlap one side 10cm
}
void ACAVEOverlayController::refreshPawnComponents(){
static TArray<UDisplayClusterSceneComponent*> pawn_components;
player_pawn_->GetComponents<UDisplayClusterSceneComponent>(pawn_components);
for (UDisplayClusterSceneComponent* c : pawn_components) {
if (c->GetName().Equals("cave_origin", ESearchCase::IgnoreCase)) cave_origin_ = c;
if (c->GetName().Equals("shutter_glasses", ESearchCase::IgnoreCase)) shutter_glasses_ = c;
}
}
// Called every frame
void ACAVEOverlayController::Tick(float DeltaTime)
{
......@@ -182,6 +191,9 @@ void ACAVEOverlayController::Tick(float DeltaTime)
if (hmd_mode_ || !display_cluster_mode_) return; // Not our business
refreshPawnComponents();
if (!cave_origin_ || !shutter_glasses_) return; //Display Cluster not initialized
//Move complete actor around
SetActorLocationAndRotation(cave_origin_->GetComponentLocation(), cave_origin_->GetComponentQuat());
......@@ -208,7 +220,7 @@ void ACAVEOverlayController::Tick(float DeltaTime)
//Sign Logic
UDisplayClusterSceneComponent* flystick = IDisplayCluster::Get().GetGameMgr()->GetNodeById(TEXT("flystick"));
if (flystick) {
if (flystick != nullptr) {
FVector flystick_position = flystick->GetRelativeTransform().GetLocation();
bool flystick_in_door = positionInDoorOpening(flystick_position);
float sign_opacity = calculateOpacityFromPosition(flystick_position);
......
......@@ -71,6 +71,7 @@ private:
bool positionInDoorOpening(FVector position);
//Pawn Components
void refreshPawnComponents();
AVirtualRealityPawn* player_pawn_;
UDisplayClusterSceneComponent* cave_origin_;
UDisplayClusterSceneComponent* shutter_glasses_;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment