UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
GizmoViewContext.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "CoreMinimal.h"
6
8#include "SceneView.h"
9
10#include "GizmoViewContext.generated.h"
11
18UCLASS(MinimalAPI)
20{
22public:
23
24 // Wrapping class for the matrices so that they can be accessed in the same way
25 // that they are accessed in FSceneView.
27 {
28 public:
29 void ResetFromSceneView(const FSceneView& SceneView)
30 {
31 ProjectionMatrix = SceneView.ViewMatrices.GetProjectionMatrix();
32 ViewMatrix = SceneView.ViewMatrices.GetViewMatrix();
33 InvViewMatrix = SceneView.ViewMatrices.GetInvViewMatrix();
34 ViewProjectionMatrix = SceneView.ViewMatrices.GetViewProjectionMatrix();
35 InvViewProjectionMatrix = SceneView.ViewMatrices.GetInvViewProjectionMatrix();
36 }
37
38 const FMatrix& GetProjectionMatrix() const { return ProjectionMatrix; }
39 const FMatrix& GetViewMatrix() const { return ViewMatrix; }
40 const FMatrix& GetInvViewMatrix() const { return InvViewMatrix; }
41 const FMatrix& GetViewProjectionMatrix() const { return ViewProjectionMatrix; }
42 const FMatrix& GetInvViewProjectionMatrix() const { return InvViewProjectionMatrix; }
43
44 protected:
45 FMatrix ProjectionMatrix = FMatrix::Identity;
47 FMatrix InvViewMatrix = FMatrix::Identity;
48 FMatrix ViewProjectionMatrix = FMatrix::Identity;
49 FMatrix InvViewProjectionMatrix = FMatrix::Identity;
50 };
51
52 // Use this to reinitialize the object each frame for the hovered viewport.
53 void ResetFromSceneView(const FSceneView& SceneView)
54 {
55 UnscaledViewRect = SceneView.UnscaledViewRect;
56 ViewMatrices.ResetFromSceneView(SceneView);
57 bIsPerspectiveProjection = SceneView.IsPerspectiveProjection();
58 ViewLocation = SceneView.ViewLocation;
59 }
60
61 // ISceneViewInterface
62 const FIntRect& GetUnscaledViewRect() const override { return UnscaledViewRect; }
63 FVector GetViewLocation() const override { return ViewLocation; }
64 FVector GetViewRight() const override { return ViewMatrices.GetViewMatrix().GetColumn(0); }
65 FVector GetViewUp() const override { return ViewMatrices.GetViewMatrix().GetColumn(1); }
66 FVector GetViewDirection() const override { return ViewMatrices.GetViewMatrix().GetColumn(2); }
67 const FMatrix& GetProjectionMatrix() const override { return ViewMatrices.GetProjectionMatrix(); }
68 const FMatrix& GetViewMatrix() const override { return ViewMatrices.GetViewMatrix(); }
69 bool IsPerspectiveProjection() const override { return bIsPerspectiveProjection; }
70 virtual double GetDPIScale() const override { return DPIScale; }
71 void SetDPIScale(const double InDPIScale) { DPIScale = InDPIScale; }
72
74 {
75 return ViewMatrices.GetViewProjectionMatrix().TransformFVector4(FVector4(WorldPoint, 1));
76 }
77
78 // WorldToScreen -> ScreenToPixel. A result of (-1, -1) indicates invalid W.
80 {
82 if (ScreenToPixel(WorldToScreen(WorldPoint), ScreenPos))
83 {
84 return ScreenPos;
85 }
86
87 return -FVector2D::One();
88 }
89
91 {
92 // implementation copied from FSceneView::ScreenToPixel()
93
94 if (ScreenPoint.W != 0.0f)
95 {
96 //Reverse the W in the case it is negative, this allow to manipulate a manipulator in the same direction when the camera is really close to the manipulator.
97 double InvW = (ScreenPoint.W > 0.0 ? 1.0 : -1.0) / ScreenPoint.W;
98 double Y = (GProjectionSignY > 0.0) ? ScreenPoint.Y : 1.0 - ScreenPoint.Y;
100 UnscaledViewRect.Min.X + (0.5 + ScreenPoint.X * 0.5 * InvW) * UnscaledViewRect.Width(),
101 UnscaledViewRect.Min.Y + (0.5 - Y * 0.5 * InvW) * UnscaledViewRect.Height()
102 );
103 return true;
104 }
105 else
106 {
107 return false;
108 }
109 }
110
114
115protected:
117 double DPIScale = 1.0; // Usually set from ViewportClient
118};
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
UE::Math::TVector4< double > FVector4
Definition MathFwd.h:49
UE::Math::TVector2< double > FVector2D
Definition MathFwd.h:48
#define GENERATED_BODY(...)
Definition ObjectMacros.h:765
#define UCLASS(...)
Definition ObjectMacros.h:776
constexpr float GProjectionSignY
Definition RHIGlobals.h:21
Definition SceneView.h:1425
FVector ViewLocation
Definition SceneView.h:1467
FViewMatrices ViewMatrices
Definition SceneView.h:1464
bool IsPerspectiveProjection() const
Definition SceneView.h:1943
const FIntRect UnscaledViewRect
Definition SceneView.h:1456
Definition GizmoViewContext.h:27
const FMatrix & GetInvViewProjectionMatrix() const
Definition GizmoViewContext.h:42
void ResetFromSceneView(const FSceneView &SceneView)
Definition GizmoViewContext.h:29
const FMatrix & GetViewMatrix() const
Definition GizmoViewContext.h:39
const FMatrix & GetInvViewMatrix() const
Definition GizmoViewContext.h:40
const FMatrix & GetViewProjectionMatrix() const
Definition GizmoViewContext.h:41
const FMatrix & GetProjectionMatrix() const
Definition GizmoViewContext.h:38
Definition GizmoViewContext.h:20
FMatrices ViewMatrices
Definition GizmoViewContext.h:111
void SetDPIScale(const double InDPIScale)
Definition GizmoViewContext.h:71
bool bIsPerspectiveProjection
Definition GizmoViewContext.h:116
virtual double GetDPIScale() const override
Definition GizmoViewContext.h:70
FVector GetViewUp() const override
Definition GizmoViewContext.h:65
FVector ViewLocation
Definition GizmoViewContext.h:113
const FIntRect & GetUnscaledViewRect() const override
Definition GizmoViewContext.h:62
FVector GetViewRight() const override
Definition GizmoViewContext.h:64
const FMatrix & GetProjectionMatrix() const override
Definition GizmoViewContext.h:67
bool IsPerspectiveProjection() const override
Definition GizmoViewContext.h:69
FVector GetViewDirection() const override
Definition GizmoViewContext.h:66
bool ScreenToPixel(const FVector4 &ScreenPoint, FVector2D &OutPixelLocation) const
Definition GizmoViewContext.h:90
void ResetFromSceneView(const FSceneView &SceneView)
Definition GizmoViewContext.h:53
FVector GetViewLocation() const override
Definition GizmoViewContext.h:63
FVector4 WorldToScreen(const FVector &WorldPoint) const override
Definition GizmoViewContext.h:73
const FMatrix & GetViewMatrix() const override
Definition GizmoViewContext.h:68
FIntRect UnscaledViewRect
Definition GizmoViewContext.h:112
FVector2D WorldToPixel(const FVector &WorldPoint) const
Definition GizmoViewContext.h:79
Definition Object.h:95
Definition GizmoRenderingUtil.h:143
Definition AdvancedWidgetsModule.cpp:13
const FMatrix & GetProjectionMatrix() const
Definition SceneView.h:433
const FMatrix & GetViewProjectionMatrix() const
Definition SceneView.h:458
const FMatrix & GetInvViewProjectionMatrix() const
Definition SceneView.h:463
const FMatrix & GetViewMatrix() const
Definition SceneView.h:448
const FMatrix & GetInvViewMatrix() const
Definition SceneView.h:453
static CORE_API const TMatrix Identity
Definition Matrix.h:52
static TVector2< double > One()
Definition Vector2D.h:80