15class [[nodiscard]] alignas(JPH_VECTOR_ALIGNMENT)
Vec3
21#if defined(JPH_USE_SSE)
23#elif defined(JPH_USE_NEON)
24 using Type = float32x4_t;
36 JPH_INLINE
Vec3(
Type inRHS) : mValue(inRHS) { CheckW(); }
42 JPH_INLINE
Vec3(
float inX,
float inY,
float inZ);
45 static JPH_INLINE
Vec3 sZero();
48 static JPH_INLINE
Vec3 sNaN();
56 static JPH_INLINE
Vec3 sReplicate(
float inV);
59 static JPH_INLINE
Vec3 sLoadFloat3Unsafe(
const Float3 &inV);
103 static JPH_INLINE
Vec3 sUnitSpherical(
float inTheta,
float inPhi);
106 static const std::vector<Vec3> sUnitSphere;
109 template <
class Random>
110 static inline Vec3 sRandom(Random &inRandom);
113#if defined(JPH_USE_SSE)
114 JPH_INLINE
float GetX()
const {
return _mm_cvtss_f32(mValue); }
115 JPH_INLINE
float GetY()
const {
return mF32[1]; }
116 JPH_INLINE
float GetZ()
const {
return mF32[2]; }
117#elif defined(JPH_USE_NEON)
118 JPH_INLINE
float GetX()
const {
return vgetq_lane_f32(mValue, 0); }
119 JPH_INLINE
float GetY()
const {
return vgetq_lane_f32(mValue, 1); }
120 JPH_INLINE
float GetZ()
const {
return vgetq_lane_f32(mValue, 2); }
122 JPH_INLINE
float GetX()
const {
return mF32[0]; }
123 JPH_INLINE
float GetY()
const {
return mF32[1]; }
124 JPH_INLINE
float GetZ()
const {
return mF32[2]; }
128 JPH_INLINE
void SetX(
float inX) { mF32[0] = inX; }
129 JPH_INLINE
void SetY(
float inY) { mF32[1] = inY; }
130 JPH_INLINE
void SetZ(
float inZ) { mF32[2] = mF32[3] = inZ; }
133 JPH_INLINE
float operator [] (
uint inCoordinate)
const {
JPH_ASSERT(inCoordinate < 3);
return mF32[inCoordinate]; }
136 JPH_INLINE
void SetComponent(
uint inCoordinate,
float inValue) {
JPH_ASSERT(inCoordinate < 3); mF32[inCoordinate] = inValue; mValue = sFixW(mValue); }
139 JPH_INLINE
bool operator == (
Vec3Arg inV2)
const;
140 JPH_INLINE
bool operator != (
Vec3Arg inV2)
const {
return !(*
this == inV2); }
143 JPH_INLINE
bool IsClose(
Vec3Arg inV2,
float inMaxDistSq = 1.0e-12f)
const;
146 JPH_INLINE
bool IsNearZero(
float inMaxDistSq = 1.0e-12f)
const;
149 JPH_INLINE
bool IsNormalized(
float inTolerance = 1.0e-6f)
const;
152 JPH_INLINE
bool IsNaN()
const;
164 JPH_INLINE
Vec3 operator / (
float inV2)
const;
167 JPH_INLINE
Vec3 & operator *= (
float inV2);
173 JPH_INLINE
Vec3 & operator /= (
float inV2);
182 JPH_INLINE
Vec3 operator - ()
const;
194 template<u
int32 SwizzleX, u
int32 SwizzleY, u
int32 SwizzleZ>
198 JPH_INLINE
Vec4 SplatX()
const;
201 JPH_INLINE
Vec4 SplatY()
const;
204 JPH_INLINE
Vec4 SplatZ()
const;
207 JPH_INLINE
int GetLowestComponentIndex()
const;
210 JPH_INLINE
int GetHighestComponentIndex()
const;
213 JPH_INLINE
Vec3 Abs()
const;
216 JPH_INLINE
Vec3 Reciprocal()
const;
228 JPH_INLINE
float Dot(
Vec3Arg inV2)
const;
231 JPH_INLINE
float LengthSq()
const;
234 JPH_INLINE
float Length()
const;
237 JPH_INLINE
Vec3 Normalized()
const;
240 JPH_INLINE
Vec3 NormalizedOr(
Vec3Arg inZeroValue)
const;
243 JPH_INLINE
void StoreFloat3(
Float3 *outV)
const;
246 JPH_INLINE
UVec4 ToInt()
const;
249 JPH_INLINE
UVec4 ReinterpretAsInt()
const;
252 JPH_INLINE
float ReduceMin()
const;
255 JPH_INLINE
float ReduceMax()
const;
258 JPH_INLINE
Vec3 Sqrt()
const;
261 JPH_INLINE
Vec3 GetNormalizedPerpendicular()
const;
264 JPH_INLINE
Vec3 GetSign()
const;
267 friend ostream & operator << (ostream &inStream,
Vec3Arg inV)
269 inStream << inV.
mF32[0] <<
", " << inV.
mF32[1] <<
", " << inV.
mF32[2];
286static_assert(is_trivial<Vec3>(),
"Is supposed to be a trivial type!");
unsigned int uint
Definition Core.h:309
#define JPH_NAMESPACE_END
Definition Core.h:240
#define JPH_NAMESPACE_BEGIN
Definition Core.h:234
DVec3 operator*(double inV1, DVec3Arg inV2)
Definition DVec3.inl:447
#define JPH_ASSERT(...)
Definition IssueReporting.h:33
Vec3 Vec3Arg
Definition MathTypes.h:20
#define JPH_OVERRIDE_NEW_DELETE
Macro to override the new and delete functions.
Definition Memory.h:29
Class that holds 3 floats. Used as a storage class. Convert to Vec3 for calculations.
Definition Float3.h:13
static JPH_INLINE Type sFixW(Type inValue)
Internal helper function that ensures that the Z component is replicated to the W component to preven...
Vec4::Type Type
Definition Vec3.h:26
static JPH_INLINE Vec3 sAxisX()
Vectors with the principal axis.
Definition Vec3.h:51
JPH_INLINE void SetComponent(uint inCoordinate, float inValue)
Set float component by index.
Definition Vec3.h:136
Vec3(const Vec3 &inRHS)=default
static JPH_INLINE Vec3 sAxisY()
Definition Vec3.h:52
JPH_INLINE float GetX() const
Get individual components.
Definition Vec3.h:122
JPH_INLINE void SetY(float inY)
Definition Vec3.h:129
JPH_INLINE Vec3(Type inRHS)
Definition Vec3.h:36
JPH_INLINE void SetZ(float inZ)
Definition Vec3.h:130
JPH_INLINE void CheckW() const
Internal helper function that checks that W is equal to Z, so e.g. dividing by it should not generate...
static JPH_INLINE Vec3 sAxisZ()
Definition Vec3.h:53
JPH_INLINE void SetX(float inX)
Set individual components.
Definition Vec3.h:128
Type mValue
Definition Vec3.h:281
JPH_INLINE float GetY() const
Definition Vec3.h:123
float mF32[4]
Definition Vec3.h:282
JPH_INLINE float GetZ() const
Definition Vec3.h:124
Vec3()=default
Constructor.
JPH_INLINE Vec3 Swizzle() const
Swizzle the elements in inV.
struct { float mData[4];} Type
Definition Vec4.h:24