-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #33 from microdee/hotfix/1.1.3
1.1.3
- Loading branch information
Showing
14 changed files
with
446 additions
and
217 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
// Fill out your copyright notice in the Description page of Project Settings. | ||
|
||
|
||
#include "SmViewportOverlay.h" | ||
#include "Editor.h" | ||
#include "SEditorViewport.h" | ||
#include "EditorViewportClient.h" | ||
#include "Kismet/GameplayStatics.h" | ||
|
||
|
||
FSmViewportOverlay::FSmViewportOverlay(FEditorViewportClient* VpClient) | ||
: ViewportClient(VpClient) | ||
{ | ||
auto VpRootWidget = VpClient->GetEditorViewportWidget(); | ||
Viewport = StaticCastSharedPtr<SViewport>(GetChildWidgetOfType(VpRootWidget, TEXT("SViewport"))); | ||
if(!Viewport) return; | ||
Overlay = StaticCastSharedRef<SOverlay>(Viewport->GetChildren()->GetChildAt(0)); | ||
|
||
Overlay->AddSlot() | ||
. HAlign(HAlign_Left) | ||
. VAlign(VAlign_Top) | ||
[ | ||
SAssignNew(DistanceText, STextBlock) | ||
. SimpleTextMode(true) | ||
. ColorAndOpacity(FLinearColor::Yellow) | ||
. ShadowOffset(FVector2D(2, 2)) | ||
. ShadowColorAndOpacity(FLinearColor::Black) | ||
//. RenderTransformPivot(FVector2D(0.5, 0.5)) | ||
]; | ||
} | ||
|
||
FSmViewportOverlay::~FSmViewportOverlay() | ||
{ | ||
if(Overlay) | ||
Overlay->RemoveSlot(DistanceText.ToSharedRef()); | ||
} | ||
|
||
void FSmViewportOverlay::Draw(FVector Pivot, float PivotDistance) | ||
{ | ||
FSceneViewFamilyContext ViewFam({ | ||
ViewportClient->Viewport, | ||
ViewportClient->GetScene(), | ||
ViewportClient->EngineShowFlags | ||
}); | ||
auto DpiScale = ViewportClient->ShouldDPIScaleSceneCanvas() ? ViewportClient->GetDPIScale() : 1.0f; | ||
auto SceneView = ViewportClient->CalcSceneView(&ViewFam); | ||
FVector2D Pos2; | ||
auto VpSize = ViewportClient->Viewport->GetSizeXY(); | ||
SceneView->ProjectWorldToScreen( | ||
Pivot, | ||
FIntRect({0, 0}, VpSize), | ||
SceneView->ViewMatrices.GetViewProjectionMatrix(), | ||
Pos2 | ||
); | ||
|
||
|
||
DistanceText->SetText( | ||
FText::FromString(FString::Printf(TEXT("%.2f cm"), PivotDistance)) | ||
); | ||
|
||
Pos2 /= DpiScale; | ||
Pos2 -= DistanceText->GetDesiredSize() / 2.0f; | ||
DistanceText->SetRenderTransform(FSlateRenderTransform(Pos2)); | ||
} | ||
|
||
TSharedPtr<SWidget> FSmViewportOverlay::GetChildWidgetOfType(TSharedPtr<SWidget> InWidget, FName InType) | ||
{ | ||
if(InWidget->GetType() == InType) return InWidget; | ||
auto Children = InWidget->GetChildren(); | ||
|
||
for(int i=0; i<Children->Num(); i++) | ||
{ | ||
auto CurrChild = GetChildWidgetOfType( | ||
Children->GetChildAt(i), | ||
InType | ||
); | ||
if(CurrChild.IsValid()) return CurrChild; | ||
} | ||
return {}; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Fill out your copyright notice in the Description page of Project Settings. | ||
|
||
#pragma once | ||
|
||
#include "CoreMinimal.h" | ||
|
||
/** | ||
* Object managing the lifespan of orbiting information over the active viewport | ||
*/ | ||
class SPACEMOUSE_API FSmViewportOverlay | ||
{ | ||
public: | ||
FSmViewportOverlay(FEditorViewportClient* VpClient); | ||
~FSmViewportOverlay(); | ||
|
||
void Draw(FVector Pivot, float PivotDistance); | ||
|
||
private: | ||
FEditorViewportClient* ViewportClient = nullptr; | ||
TSharedPtr<STextBlock> DistanceText; | ||
TSharedPtr<SViewport> Viewport; | ||
TSharedPtr<SOverlay> Overlay; | ||
|
||
static TSharedPtr<SWidget> GetChildWidgetOfType(TSharedPtr<SWidget> InWidget, FName InType); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// Fill out your copyright notice in the Description page of Project Settings. | ||
|
||
|
||
#include "SpaceMouseReader/Public/CommonBehaviors.h" | ||
|
||
FVector UCommonBehaviors::GetOrbitingTranslationDelta( | ||
FVector Pivot, | ||
FRotator CurrentRotation, | ||
FRotator RotationDelta, | ||
float Distance, | ||
bool bWithRoll | ||
) { | ||
if (!bWithRoll) | ||
{ | ||
const float YawCorr = FMath::Abs(FMath::Cos(FMath::DegreesToRadians(CurrentRotation.Pitch))); | ||
RotationDelta.Yaw *= YawCorr; | ||
} | ||
|
||
const FMatrix OrbitTr = FTransform(Pivot).ToMatrixWithScale() | ||
* FTransform(RotationDelta).ToMatrixWithScale() | ||
* FTransform(FVector(-Distance, 0, 0)).ToMatrixWithScale(); | ||
|
||
FVector Ret = OrbitTr.TransformPosition(FVector::ZeroVector); | ||
Ret.X = 0; | ||
return Ret; | ||
} |
Oops, something went wrong.