Ark Server API (ASA) - Wiki
Loading...
Searching...
No Matches
LargeWorldRenderPosition.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#include "Math/MathFwd.h"
7#include "Math/Matrix.h"
8#include "Math/UnrealMathUtility.h"
9#include "Math/Vector.h"
10#include "Math/Vector4.h"
11#include "Misc/LargeWorldCoordinates.h"
12
13template <typename TScalar>
14struct TLargeWorldRenderScalar
15{
16private:
17 using VectorType = UE::Math::TVector<TScalar>;
18
19public:
20 // This should become inline at some point, but keeping it in cpp file for now to make iteration faster when experimenting with tile size
21 static TScalar GetTileSize();
22 static FVector3f GetTileFor(FVector InPosition);
23
24 static TScalar MakeTile(double InValue)
25 {
26 return static_cast<TScalar>(FMath::FloorToDouble(InValue / GetTileSize() + 0.5));
27 }
28
29 static TScalar MakeQuantizedTile(double InValue, double InQuantization)
30 {
31 return static_cast<TScalar>(FMath::FloorToDouble((InValue / GetTileSize()) * InQuantization + 0.5) / InQuantization);
32 }
33
34 static VectorType MakeTile(const FVector& InValue)
35 {
36 return VectorType(MakeTile(InValue.X), MakeTile(InValue.Y), MakeTile(InValue.Z));
37 }
38
39 static VectorType MakeQuantizedTile(const FVector& InValue, double InQuantization)
40 {
41 return VectorType(MakeQuantizedTile(InValue.X, InQuantization), MakeQuantizedTile(InValue.Y, InQuantization), MakeQuantizedTile(InValue.Z, InQuantization));
42 }
43
44 static FMatrix44f SafeCastMatrix(const FMatrix& Matrix);
45 static FMatrix44f MakeToRelativeWorldMatrix(const FVector Origin, const FMatrix& ToWorld);
46 static FMatrix MakeToRelativeWorldMatrixDouble(const FVector Origin, const FMatrix& ToWorld);
47 static FMatrix44f MakeFromRelativeWorldMatrix(const FVector Origin, const FMatrix& FromWorld);
48 static FMatrix MakeFromRelativeWorldMatrixDouble(const FVector Origin, const FMatrix& FromWorld);
49 static FMatrix44f MakeClampedToRelativeWorldMatrix(const FVector Origin, const FMatrix& ToWorld);
50 static FMatrix MakeClampedToRelativeWorldMatrixDouble(const FVector Origin, const FMatrix& ToWorld);
51
52 template <typename TResult = float>
53 TResult GetTile() const { return static_cast<TResult>(Tile); }
54 template <typename TResult = float>
55 TResult GetOffset() const { return static_cast<TResult>(Offset); }
56 UE_DEPRECATED(5.2, "GetTileAsDouble is deprecated, please use GetTile<double>() instead.")
57 double GetTileAsDouble() const { return GetTile<double>(); }
58 UE_DEPRECATED(5.2, "GetOffsetAsDouble is deprecated, please use GetOffset<double>() instead.")
59 double GetOffsetAsDouble() const { return GetOffset<double>(); }
60 double GetTileOffset() const { return static_cast<double>(Tile) * GetTileSize(); }
61 double GetAbsolute() const { return GetTileOffset() + Offset; }
62
63 TLargeWorldRenderScalar() : Tile(static_cast<TScalar>(0.0)), Offset(static_cast<TScalar>(0.0)) {}
64 TLargeWorldRenderScalar(TScalar InTile, TScalar InOffset) : Tile(static_cast<TScalar>(InTile)), Offset(static_cast<TScalar>(InOffset)) {}
65
66 template<typename TInputScalar = double>
67 explicit TLargeWorldRenderScalar(const TLargeWorldRenderScalar<TInputScalar>& In)
68 : TLargeWorldRenderScalar(In.Tile, In.Offset)
69 { }
70
71 TLargeWorldRenderScalar(double InAbsolute)
72 {
73 // Tiles are centered on the origin
74 Tile = MakeTile(InAbsolute);
75 Offset = static_cast<TScalar>(InAbsolute - GetTileOffset());
76 Validate(InAbsolute);
77 }
78
79private:
80 void Validate(double InAbsolute);
81
82 TScalar Tile;
83 TScalar Offset;
84};
85using FLargeWorldRenderScalar = TLargeWorldRenderScalar<double>;
86
87template<typename TScalar>
89{
90private:
92 using VectorType = UE::Math::TVector<TScalar>;
93
94public:
95 template<typename TResult = float>
96 UE::Math::TVector<TResult> GetTile() const { return UE::Math::TVector<TResult>(static_cast<TResult>(Tile.X), static_cast<TResult>(Tile.Y), static_cast<TResult>(Tile.Z)); }
97
98 FVector GetTileOffset() const
99 {
104 }
105
106 template<typename TResult = float>
107 UE::Math::TVector<TResult> GetOffset() const { return UE::Math::TVector<TResult>(static_cast<TResult>(Offset.X), static_cast<TResult>(Offset.Y), static_cast<TResult>(Offset.Z)); }
108
109 FVector GetAbsolute() const
110 {
115 }
116
117 template<typename TInputScalar = double>
118 explicit TLargeWorldRenderPosition(const UE::Math::TVector<TInputScalar>& InWorldPosition)
119 {
123 Tile = VectorType(X.template GetTile<TScalar>(), Y.template GetTile<TScalar>(), Z.template GetTile<TScalar>());
124 Offset = VectorType(X.template GetOffset<TScalar>(), Y.template GetOffset<TScalar>(), Z.template GetOffset<TScalar>());
125 }
126
127 template<typename TInputScalar = double>
128 explicit TLargeWorldRenderPosition(const UE::Math::TVector4<TInputScalar>& InWorldPosition)
130 { }
131
132 template<typename TInputScalar = double>
133 explicit TLargeWorldRenderPosition(const UE::Math::TVector<TInputScalar>& InTilePosition, const UE::Math::TVector<TInputScalar>& InRelativePosition)
134 {
137 }
138
139 template<typename TInputScalar>
140 explicit TLargeWorldRenderPosition(const TLargeWorldRenderPosition<TInputScalar>& In)
142 { }
143
145 : Tile(0, 0, 0), Offset(0, 0, 0)
146 { }
147
148private:
149 VectorType Tile;
150 VectorType Offset;
151};
152using FLargeWorldRenderPosition = TLargeWorldRenderPosition<double>;
#define UE_DEPRECATED(Version, Message)
Definition Vector.h:40
TLargeWorldRenderPosition(const UE::Math::TVector4< TInputScalar > &InWorldPosition)
TLargeWorldRenderPosition(const UE::Math::TVector< TInputScalar > &InWorldPosition)
TLargeWorldRenderPosition(const UE::Math::TVector< TInputScalar > &InTilePosition, const UE::Math::TVector< TInputScalar > &InRelativePosition)
UE::Math::TVector< TResult > GetTile() const
TLargeWorldRenderPosition(const TLargeWorldRenderPosition< TInputScalar > &In)
UE::Math::TVector< TResult > GetOffset() const