Ark Server API (ASA) - Wiki
Loading...
Searching...
No Matches
PerspectiveMatrix.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "CoreTypes.h"
6#include "Math/UnrealMathUtility.h"
7#include "Math/Plane.h"
8#include "Math/Matrix.h"
9
10namespace UE {
11namespace Math {
12
13template<typename T>
14struct TPerspectiveMatrix
15 : public TMatrix<T>
16{
17public:
18
19// Note: the value of this must match the mirror in Common.usf!
20#define Z_PRECISION 0.0f
21
22 /**
23 * Constructor
24 *
25 * @param HalfFOVX Half FOV in the X axis
26 * @param HalfFOVY Half FOV in the Y axis
27 * @param MultFOVX multiplier on the X axis
28 * @param MultFOVY multiplier on the y axis
29 * @param MinZ distance to the near Z plane
30 * @param MaxZ distance to the far Z plane
31 */
32 TPerspectiveMatrix(T HalfFOVX, T HalfFOVY, T MultFOVX, T MultFOVY, T MinZ, T MaxZ);
33
34 /**
35 * Constructor
36 *
37 * @param HalfFOV half Field of View in the Y direction
38 * @param Width view space width
39 * @param Height view space height
40 * @param MinZ distance to the near Z plane
41 * @param MaxZ distance to the far Z plane
42 * @note that the FOV you pass in is actually half the FOV, unlike most perspective matrix functions (D3DXMatrixPerspectiveFovLH).
43 */
44 TPerspectiveMatrix(T HalfFOV, T Width, T Height, T MinZ, T MaxZ);
45
46 /**
47 * Constructor
48 *
49 * @param HalfFOV half Field of View in the Y direction
50 * @param Width view space width
51 * @param Height view space height
52 * @param MinZ distance to the near Z plane
53 * @note that the FOV you pass in is actually half the FOV, unlike most perspective matrix functions (D3DXMatrixPerspectiveFovLH).
54 */
55 TPerspectiveMatrix(T HalfFOV, T Width, T Height, T MinZ);
56
57 // Conversion to other type.
58 template<typename FArg, TEMPLATE_REQUIRES(!std::is_same_v<T, FArg>)>
59 explicit TPerspectiveMatrix(const TPerspectiveMatrix<FArg>& From) : TMatrix<T>(From) {}
60};
61
62
63template<typename T>
64struct TReversedZPerspectiveMatrix : public TMatrix<T>
65{
66public:
67 TReversedZPerspectiveMatrix(T HalfFOVX, T HalfFOVY, T MultFOVX, T MultFOVY, T MinZ, T MaxZ);
68 TReversedZPerspectiveMatrix(T HalfFOV, T Width, T Height, T MinZ, T MaxZ);
69 TReversedZPerspectiveMatrix(T HalfFOV, T Width, T Height, T MinZ);
70
71 // Conversion to other type.
72 template<typename FArg, TEMPLATE_REQUIRES(!std::is_same_v<T, FArg>)>
73 explicit TReversedZPerspectiveMatrix(const TReversedZPerspectiveMatrix<FArg>& From) : TMatrix<T>(From) {}
74};
75
76
77#ifdef _MSC_VER
78#pragma warning (push)
79// Disable possible division by 0 warning
80#pragma warning (disable : 4723)
81#endif
82
83
84template<typename T>
85FORCEINLINE TPerspectiveMatrix<T>::TPerspectiveMatrix(T HalfFOVX, T HalfFOVY, T MultFOVX, T MultFOVY, T MinZ, T MaxZ)
86 : TMatrix<T>(
87 TPlane<T>(MultFOVX / FMath::Tan(HalfFOVX), 0.0f, 0.0f, 0.0f),
88 TPlane<T>(0.0f, MultFOVY / FMath::Tan(HalfFOVY), 0.0f, 0.0f),
89 TPlane<T>(0.0f, 0.0f, ((MinZ == MaxZ) ? (1.0f - Z_PRECISION) : MaxZ / (MaxZ - MinZ)), 1.0f),
90 TPlane<T>(0.0f, 0.0f, -MinZ * ((MinZ == MaxZ) ? (1.0f - Z_PRECISION) : MaxZ / (MaxZ - MinZ)), 0.0f)
91 )
92{ }
93
94
95template<typename T>
96FORCEINLINE TPerspectiveMatrix<T>::TPerspectiveMatrix(T HalfFOV, T Width, T Height, T MinZ, T MaxZ)
97 : TMatrix<T>(
98 TPlane<T>(1.0f / FMath::Tan(HalfFOV), 0.0f, 0.0f, 0.0f),
99 TPlane<T>(0.0f, Width / FMath::Tan(HalfFOV) / Height, 0.0f, 0.0f),
100 TPlane<T>(0.0f, 0.0f, ((MinZ == MaxZ) ? (1.0f - Z_PRECISION) : MaxZ / (MaxZ - MinZ)), 1.0f),
101 TPlane<T>(0.0f, 0.0f, -MinZ * ((MinZ == MaxZ) ? (1.0f - Z_PRECISION) : MaxZ / (MaxZ - MinZ)), 0.0f)
102 )
103{ }
104
105
106template<typename T>
107FORCEINLINE TPerspectiveMatrix<T>::TPerspectiveMatrix(T HalfFOV, T Width, T Height, T MinZ)
108 : TMatrix<T>(
109 TPlane<T>(1.0f / FMath::Tan(HalfFOV), 0.0f, 0.0f, 0.0f),
110 TPlane<T>(0.0f, Width / FMath::Tan(HalfFOV) / Height, 0.0f, 0.0f),
111 TPlane<T>(0.0f, 0.0f, (1.0f - Z_PRECISION), 1.0f),
112 TPlane<T>(0.0f, 0.0f, -MinZ * (1.0f - Z_PRECISION), 0.0f)
113 )
114{ }
115
116
117template<typename T>
118FORCEINLINE TReversedZPerspectiveMatrix<T>::TReversedZPerspectiveMatrix(T HalfFOVX, T HalfFOVY, T MultFOVX, T MultFOVY, T MinZ, T MaxZ)
119 : TMatrix<T>(
120 TPlane<T>(MultFOVX / FMath::Tan(HalfFOVX), 0.0f, 0.0f, 0.0f),
121 TPlane<T>(0.0f, MultFOVY / FMath::Tan(HalfFOVY), 0.0f, 0.0f),
122 TPlane<T>(0.0f, 0.0f, ((MinZ == MaxZ) ? 0.0f : MinZ / (MinZ - MaxZ)), 1.0f),
123 TPlane<T>(0.0f, 0.0f, ((MinZ == MaxZ) ? MinZ : -MaxZ * MinZ / (MinZ - MaxZ)), 0.0f)
124 )
125{ }
126
127
128template<typename T>
129FORCEINLINE TReversedZPerspectiveMatrix<T>::TReversedZPerspectiveMatrix(T HalfFOV, T Width, T Height, T MinZ, T MaxZ)
130 : TMatrix<T>(
131 TPlane<T>(1.0f / FMath::Tan(HalfFOV), 0.0f, 0.0f, 0.0f),
132 TPlane<T>(0.0f, Width / FMath::Tan(HalfFOV) / Height, 0.0f, 0.0f),
133 TPlane<T>(0.0f, 0.0f, ((MinZ == MaxZ) ? 0.0f : MinZ / (MinZ - MaxZ)), 1.0f),
134 TPlane<T>(0.0f, 0.0f, ((MinZ == MaxZ) ? MinZ : -MaxZ * MinZ / (MinZ - MaxZ)), 0.0f)
135 )
136{ }
137
138
139template<typename T>
140FORCEINLINE TReversedZPerspectiveMatrix<T>::TReversedZPerspectiveMatrix(T HalfFOV, T Width, T Height, T MinZ)
141 : TMatrix<T>(
142 TPlane<T>(1.0f / FMath::Tan(HalfFOV), 0.0f, 0.0f, 0.0f),
143 TPlane<T>(0.0f, Width / FMath::Tan(HalfFOV) / Height, 0.0f, 0.0f),
144 TPlane<T>(0.0f, 0.0f, 0.0f, 1.0f),
145 TPlane<T>(0.0f, 0.0f, MinZ, 0.0f)
146 )
147{ }
148
149#ifdef _MSC_VER
150#pragma warning (pop)
151#endif
152
153
154} // namespace Math
155} // namespace UE
156
157UE_DECLARE_LWC_TYPE(PerspectiveMatrix, 44);
158UE_DECLARE_LWC_TYPE(ReversedZPerspectiveMatrix, 44);
159
160template<> struct TIsUECoreVariant<FPerspectiveMatrix44f> { enum { Value = true }; };
161template<> struct TIsUECoreVariant<FPerspectiveMatrix44d> { enum { Value = true }; };
162template<> struct TIsUECoreVariant<FReversedZPerspectiveMatrix44f> { enum { Value = true }; };
163template<> struct TIsUECoreVariant<FReversedZPerspectiveMatrix44d> { enum { Value = true }; };
#define UE_DECLARE_LWC_TYPE(...)
#define Z_PRECISION
#define FORCEINLINE
Definition Platform.h:644
#define TEMPLATE_REQUIRES(...)