Ark Server API (ASA) - Wiki
Loading...
Searching...
No Matches
OrientedBox.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/Vector.h"
7#include "Math/Interval.h"
8
9/**
10 * Structure for arbitrarily oriented boxes (not necessarily axis-aligned).
11 */
12struct FOrientedBox
13{
14 /** Holds the center of the box. */
15 FVector Center;
16
17 /** Holds the x-axis vector of the box. Must be a unit vector. */
18 FVector AxisX;
19
20 /** Holds the y-axis vector of the box. Must be a unit vector. */
21 FVector AxisY;
22
23 /** Holds the z-axis vector of the box. Must be a unit vector. */
24 FVector AxisZ;
25
26 /** Holds the extent of the box along its x-axis. */
27 FVector::FReal ExtentX;
28
29 /** Holds the extent of the box along its y-axis. */
30 FVector::FReal ExtentY;
31
32 /** Holds the extent of the box along its z-axis. */
33 FVector::FReal ExtentZ;
34
35public:
36
37 /**
38 * Default constructor.
39 *
40 * Constructs a unit-sized, origin-centered box with axes aligned to the coordinate system.
41 */
42 FOrientedBox()
43 : Center(0.0f)
44 , AxisX(1.0f, 0.0f, 0.0f)
45 , AxisY(0.0f, 1.0f, 0.0f)
46 , AxisZ(0.0f, 0.0f, 1.0f)
47 , ExtentX(1.0f)
48 , ExtentY(1.0f)
49 , ExtentZ(1.0f)
50 { }
51
52public:
53
54 /**
55 * Fills in the Verts array with the eight vertices of the box.
56 *
57 * @param Verts The array to fill in with the vertices.
58 */
59 FORCEINLINE void CalcVertices(FVector* Verts) const;
60
61 /**
62 * Finds the projection interval of the box when projected onto Axis.
63 *
64 * @param Axis The unit vector defining the axis to project the box onto.
65 */
66 FORCEINLINE FFloatInterval Project(const FVector& Axis) const;
67};
68
69
70/* FOrientedBox inline functions
71 *****************************************************************************/
72
73FORCEINLINE void FOrientedBox::CalcVertices( FVector* Verts ) const
74{
75 const float Signs[] = { -1.0f, 1.0f };
76
77 for (int32 i = 0; i < 2; i++)
78 {
79 for (int32 j = 0; j < 2; j++)
80 {
81 for (int32 k = 0; k < 2; k++)
82 {
83 *Verts++ = Center + Signs[i] * AxisX * ExtentX + Signs[j] * AxisY * ExtentY + Signs[k] * AxisZ * ExtentZ;
84 }
85 }
86 }
87}
88
89
90FORCEINLINE FFloatInterval FOrientedBox::Project( const FVector& Axis ) const
91{
92 const FVector::FReal Signs[] = {-1.0f, 1.0f};
93
94 // calculate the projections of the box center and the extent-scaled axes.
95 FVector::FReal ProjectedCenter = Axis | Center;
96 FVector::FReal ProjectedAxisX = Axis | (ExtentX * AxisX);
97 FVector::FReal ProjectedAxisY = Axis | (ExtentY * AxisY);
98 FVector::FReal ProjectedAxisZ = Axis | (ExtentZ * AxisZ);
99
100 FFloatInterval ProjectionInterval;
101
102 for (int32 i = 0; i < 2; i++)
103 {
104 for (int32 j = 0; j < 2; j++)
105 {
106 for (int32 k = 0; k < 2; k++)
107 {
108 // project the box vertex onto the axis.
109 float ProjectedVertex = float(ProjectedCenter + Signs[i] * ProjectedAxisX + Signs[j] * ProjectedAxisY + Signs[k] * ProjectedAxisZ); // LWC_TODO: Precision loss
110
111 // if necessary, expand the projection interval to include the box vertex projection.
112 ProjectionInterval.Include(ProjectedVertex);
113 }
114 }
115 }
116
117 return ProjectionInterval;
118}
119
120template <> struct TIsPODType<FOrientedBox> { enum { Value = true }; };
#define FORCEINLINE
Definition Platform.h:644