13class [[nodiscard]] alignas(JPH_VECTOR_ALIGNMENT)
Vec4
19#if defined(JPH_USE_SSE)
21#elif defined(JPH_USE_NEON)
22 using Type = float32x4_t;
24 using Type =
struct {
float mData[4]; };
30 Vec4 & operator = (
const Vec4 &inRHS) =
default;
36 JPH_INLINE
Vec4(
float inX,
float inY,
float inZ,
float inW);
39 static JPH_INLINE
Vec4 sZero();
42 static JPH_INLINE
Vec4 sOne();
45 static JPH_INLINE
Vec4 sNaN();
48 static JPH_INLINE
Vec4 sReplicate(
float inV);
51 static JPH_INLINE
Vec4 sLoadFloat4(
const Float4 *inV);
54 static JPH_INLINE
Vec4 sLoadFloat4Aligned(
const Float4 *inV);
57 template <const
int Scale>
108#if defined(JPH_USE_SSE)
109 JPH_INLINE
float GetX()
const {
return _mm_cvtss_f32(
mValue); }
110 JPH_INLINE
float GetY()
const {
return mF32[1]; }
111 JPH_INLINE
float GetZ()
const {
return mF32[2]; }
112 JPH_INLINE
float GetW()
const {
return mF32[3]; }
113#elif defined(JPH_USE_NEON)
114 JPH_INLINE
float GetX()
const {
return vgetq_lane_f32(mValue, 0); }
115 JPH_INLINE
float GetY()
const {
return vgetq_lane_f32(mValue, 1); }
116 JPH_INLINE
float GetZ()
const {
return vgetq_lane_f32(mValue, 2); }
117 JPH_INLINE
float GetW()
const {
return vgetq_lane_f32(mValue, 3); }
132 JPH_INLINE
void Set(
float inX,
float inY,
float inZ,
float inW) { *
this =
Vec4(inX, inY, inZ, inW); }
135 JPH_INLINE
float operator [] (
uint inCoordinate)
const {
JPH_ASSERT(inCoordinate < 4);
return mF32[inCoordinate]; }
136 JPH_INLINE
float & operator [] (
uint inCoordinate) {
JPH_ASSERT(inCoordinate < 4);
return mF32[inCoordinate]; }
139 JPH_INLINE
bool operator == (
Vec4Arg inV2)
const;
140 JPH_INLINE
bool operator != (
Vec4Arg inV2)
const {
return !(*
this == inV2); }
143 JPH_INLINE
bool IsClose(
Vec4Arg 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
Vec4 operator / (
float inV2)
const;
167 JPH_INLINE
Vec4 & operator *= (
float inV2);
173 JPH_INLINE
Vec4 & operator /= (
float inV2);
182 JPH_INLINE
Vec4 operator - ()
const;
194 template<u
int32 SwizzleX, u
int32 SwizzleY, u
int32 SwizzleZ, u
int32 SwizzleW>
243 JPH_INLINE
float Length()
const;
273 template <
int X,
int Y,
int Z,
int W>
303 friend ostream & operator << (ostream &inStream,
Vec4Arg inV)
305 inStream << inV.
mF32[0] <<
", " << inV.
mF32[1] <<
", " << inV.
mF32[2] <<
", " << inV.
mF32[3];
316static_assert(std::is_trivial<Vec4>(),
"Is supposed to be a trivial type!");
unsigned int uint
Definition Core.h:500
#define JPH_NAMESPACE_END
Definition Core.h:425
std::uint32_t uint32
Definition Core.h:503
#define JPH_NAMESPACE_BEGIN
Definition Core.h:419
DVec3 operator*(double inV1, DVec3Arg inV2)
Definition DVec3.inl:456
#define JPH_ASSERT(...)
Definition IssueReporting.h:33
const Vec4 Vec4Arg
Definition MathTypes.h:25
const Vec3 Vec3Arg
Definition MathTypes.h:19
const UVec4 UVec4Arg
Definition MathTypes.h:26
#define JPH_OVERRIDE_NEW_DELETE
Macro to override the new and delete functions.
Definition Memory.h:50
JPH_INLINE float Tan(float inX)
Tangent of x (input in radians).
Definition Trigonometry.h:28
JPH_INLINE float ACos(float inX)
Definition Trigonometry.h:42
JPH_INLINE float ASin(float inX)
Definition Trigonometry.h:35
JPH_INLINE float ATan(float inX)
Arc tangent of x (returns value in the range [-PI / 2, PI / 2]).
Definition Trigonometry.h:68
Class that holds 4 float values. Convert to Vec4 to perform calculations.
Definition Float4.h:11
JPH_INLINE Vec4 SplatX() const
Replicate the X component to all components.
Definition Vec4.inl:573
static JPH_INLINE void sSort4(Vec4 &ioValue, UVec4 &ioIndex)
Definition Vec4.inl:314
static JPH_INLINE UVec4 sGreater(Vec4Arg inV1, Vec4Arg inV2)
Greater than (component wise).
Definition Vec4.inl:218
float mF32[4]
Definition Vec4.h:312
JPH_INLINE Vec3 SplatW3() const
Replicate the W component to all components.
Definition Vec4.inl:650
Vec4()=default
Constructor.
static JPH_INLINE Vec4 sAnd(Vec4Arg inV1, Vec4Arg inV2)
Logical and (component wise).
Definition Vec4.inl:303
static Vec4 sATan2(Vec4Arg inY, Vec4Arg inX)
Calculate the arc tangent of y / x using the signs of the arguments to determine the correct quadrant...
Definition Vec4.inl:1037
JPH_INLINE void SetW(float inW)
Definition Vec4.h:129
JPH_INLINE Vec4 GetSign() const
Get vector that contains the sign of each element (returns 1.0f if positive, -1.0f if negative).
Definition Vec4.inl:764
JPH_INLINE Vec4 FlipSign() const
Flips the signs of the components, e.g. FlipSign<-1, 1, -1, 1>() will flip the signs of the X and Z c...
Definition Vec4.inl:785
static JPH_INLINE Vec4 sXor(Vec4Arg inV1, Vec4Arg inV2)
Logical xor (component wise).
Definition Vec4.inl:292
JPH_INLINE Vec4 Abs() const
Return the absolute value of each of the components.
Definition Vec4.inl:681
JPH_INLINE float GetW() const
Definition Vec4.h:122
JPH_INLINE UVec4 ToInt() const
Convert each component from a float to an int.
Definition Vec4.inl:819
static JPH_INLINE UVec4 sLessOrEqual(Vec4Arg inV1, Vec4Arg inV2)
Less than or equal (component wise).
Definition Vec4.inl:204
static JPH_INLINE UVec4 sLess(Vec4Arg inV1, Vec4Arg inV2)
Less than (component wise).
Definition Vec4.inl:190
JPH_INLINE int GetLowestComponentIndex() const
Get index of component with lowest value.
Definition Vec4.inl:661
JPH_INLINE float Length() const
Length of vector.
Definition Vec4.inl:738
static JPH_INLINE void sSort4Reverse(Vec4 &ioValue, UVec4 &ioIndex)
Definition Vec4.inl:338
static JPH_INLINE Vec4 sFusedMultiplyAdd(Vec4Arg inMul1, Vec4Arg inMul2, Vec4Arg inAdd)
Calculates inMul1 * inMul2 + inAdd.
Definition Vec4.inl:246
JPH_INLINE Vec4 Normalized() const
Normalize vector.
Definition Vec4.inl:794
JPH_INLINE Vec4(Type inRHS)
Definition Vec4.h:33
static JPH_INLINE UVec4 sEquals(Vec4Arg inV1, Vec4Arg inV2)
Equals (component wise).
Definition Vec4.inl:176
JPH_INLINE float ReduceMax() const
Get the maximum of X, Y, Z and W.
Definition Vec4.inl:860
JPH_INLINE void SetZ(float inZ)
Definition Vec4.h:128
JPH_INLINE Vec4 Reciprocal() const
Reciprocal vector (1 / value) for each of the components.
Definition Vec4.inl:694
JPH_INLINE Vec4 SplatY() const
Replicate the Y component to all components.
Definition Vec4.inl:584
JPH_INLINE UVec4 ReinterpretAsInt() const
Reinterpret Vec4 as a UVec4 (doesn't change the bits).
Definition Vec4.inl:830
static JPH_INLINE UVec4 sGreaterOrEqual(Vec4Arg inV1, Vec4Arg inV2)
Greater than or equal (component wise).
Definition Vec4.inl:232
static JPH_INLINE Vec4 sMin(Vec4Arg inV1, Vec4Arg inV2)
Return the minimum value of each of the components.
Definition Vec4.inl:143
Vec4(const Vec4 &inRHS)=default
JPH_INLINE Vec4 SplatZ() const
Replicate the Z component to all components.
Definition Vec4.inl:595
JPH_INLINE Vec4 Sqrt() const
Component wise square root.
Definition Vec4.inl:752
static JPH_INLINE Vec4 sGatherFloat4(const float *inBase, UVec4Arg inOffsets)
Gather 4 floats from memory at inBase + inOffsets[i] * Scale.
JPH_INLINE void SetY(float inY)
Definition Vec4.h:127
JPH_INLINE Vec4 SplatW() const
Replicate the W component to all components.
Definition Vec4.inl:606
JPH_INLINE void SetX(float inX)
Set individual components.
Definition Vec4.h:126
JPH_INLINE Vec4 DotV(Vec4Arg inV2) const
Dot product, returns the dot product in X, Y, Z and W components.
Definition Vec4.inl:699
JPH_INLINE float GetX() const
Get individual components.
Definition Vec4.h:119
JPH_INLINE Vec4 Swizzle() const
Swizzle the elements in inV.
struct { float mData[4];} Type
Definition Vec4.h:24
static JPH_INLINE Vec4 sOr(Vec4Arg inV1, Vec4Arg inV2)
Logical or (component wise).
Definition Vec4.inl:281
JPH_INLINE float ReduceMin() const
Get the minimum of X, Y, Z and W.
Definition Vec4.inl:853
Type mValue
Definition Vec4.h:311
static JPH_INLINE Vec4 sDecompressUnitVector(uint32 inValue)
Decompress a unit vector from a 32 bit value.
Definition Vec4.inl:1114
JPH_INLINE uint32 CompressUnitVector() const
Compress a unit vector to a 32 bit value, precision is around 0.5 * 10^-3.
Definition Vec4.inl:1070
JPH_INLINE float LengthSq() const
Squared length of vector.
Definition Vec4.inl:725
static JPH_INLINE Vec4 sMax(Vec4Arg inV1, Vec4Arg inV2)
Return the maximum of each of the components.
Definition Vec4.inl:157
JPH_INLINE float Dot(Vec4Arg inV2) const
Dot product.
Definition Vec4.inl:712
JPH_INLINE Vec3 SplatZ3() const
Replicate the Z component to all components.
Definition Vec4.inl:639
JPH_INLINE Vec3 SplatX3() const
Replicate the X component to all components.
Definition Vec4.inl:617
JPH_INLINE float GetZ() const
Definition Vec4.h:121
static JPH_INLINE Vec4 sSelect(Vec4Arg inNotSet, Vec4Arg inSet, UVec4Arg inControl)
Component wise select, returns inNotSet when highest bit of inControl = 0 and inSet when highest bit ...
Definition Vec4.inl:264
JPH_INLINE void Set(float inX, float inY, float inZ, float inW)
Set all components.
Definition Vec4.h:132
JPH_INLINE int GetSignBits() const
Store if X is negative in bit 0, Y in bit 1, Z in bit 2 and W in bit 3.
Definition Vec4.inl:841
JPH_INLINE int GetHighestComponentIndex() const
Get index of component with highest value.
Definition Vec4.inl:671
JPH_INLINE float GetY() const
Definition Vec4.h:120
JPH_INLINE Vec3 SplatY3() const
Replicate the Y component to all components.
Definition Vec4.inl:628
void SinCos(Vec4 &outSin, Vec4 &outCos) const
Calculate the sine and cosine for each element of this vector (input in radians).
Definition Vec4.inl:867
JPH_INLINE void StoreFloat4(Float4 *outV) const
Store 4 floats to memory.
Definition Vec4.inl:807
static JPH_INLINE Vec4 sClamp(Vec4Arg inV, Vec4Arg inMin, Vec4Arg inMax)
Clamp a vector between min and max (component wise).
Definition Vec4.inl:171