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>
246 JPH_INLINE
float Length()
const;
279 template <
int X,
int Y,
int Z,
int W>
309 friend ostream & operator << (ostream &inStream,
Vec4Arg inV)
311 inStream << inV.
mF32[0] <<
", " << inV.
mF32[1] <<
", " << inV.
mF32[2] <<
", " << inV.
mF32[3];
322static_assert(std::is_trivially_default_constructible<Vec4>() && std::is_trivially_copyable<Vec4>(),
"Is supposed to be a trivial type!");
unsigned int uint
Definition Core.h:546
#define JPH_NAMESPACE_END
Definition Core.h:469
std::uint32_t uint32
Definition Core.h:549
#define JPH_NAMESPACE_BEGIN
Definition Core.h:463
DVec3 operator*(double inV1, DVec3Arg inV2)
Definition DVec3.inl:623
#define JPH_ASSERT(...)
Definition IssueReporting.h:33
JPH_INLINE float Sqrt(float inV)
Take the square root of a float value.
Definition Math.h:76
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:804
static JPH_INLINE void sSort4(Vec4 &ioValue, UVec4 &ioIndex)
Definition Vec4.inl:456
static JPH_INLINE UVec4 sGreater(Vec4Arg inV1, Vec4Arg inV2)
Greater than (component wise).
Definition Vec4.inl:304
float mF32[4]
Definition Vec4.h:318
JPH_INLINE Vec3 SplatW3() const
Replicate the W component to all components.
Definition Vec4.inl:916
Vec4()=default
Constructor.
static JPH_INLINE Vec4 sAnd(Vec4Arg inV1, Vec4Arg inV2)
Logical and (component wise).
Definition Vec4.inl:438
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:1341
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:1049
static JPH_INLINE Vec4 sDifferenceOfProducts(Vec4Arg inA, Vec4Arg inB, Vec4Arg inC, Vec4Arg inD)
Calculates inA * inB - inC * inD with more precision when FMA instructions are available....
Definition Vec4.inl:976
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:1078
static JPH_INLINE Vec4 sXor(Vec4Arg inV1, Vec4Arg inV2)
Logical xor (component wise).
Definition Vec4.inl:420
JPH_INLINE Vec4 Abs() const
Return the absolute value of each of the components.
Definition Vec4.inl:952
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:1102
static JPH_INLINE UVec4 sLessOrEqual(Vec4Arg inV1, Vec4Arg inV2)
Less than or equal (component wise).
Definition Vec4.inl:281
static JPH_INLINE UVec4 sLess(Vec4Arg inV1, Vec4Arg inV2)
Less than (component wise).
Definition Vec4.inl:258
JPH_INLINE int GetLowestComponentIndex() const
Get index of component with lowest value.
Definition Vec4.inl:932
JPH_INLINE float Length() const
Length of vector.
Definition Vec4.inl:1022
static JPH_INLINE void sSort4Reverse(Vec4 &ioValue, UVec4 &ioIndex)
Definition Vec4.inl:480
static JPH_INLINE Vec4 sFusedMultiplyAdd(Vec4Arg inMul1, Vec4Arg inMul2, Vec4Arg inAdd)
Calculates inMul1 * inMul2 + inAdd.
Definition Vec4.inl:350
JPH_INLINE Vec4 Normalized() const
Normalize vector.
Definition Vec4.inl:1027
JPH_INLINE Vec4(Type inRHS)
Definition Vec4.h:33
static JPH_INLINE UVec4 sEquals(Vec4Arg inV1, Vec4Arg inV2)
Equals (component wise).
Definition Vec4.inl:235
JPH_INLINE float ReduceMax() const
Get the maximum of X, Y, Z and W.
Definition Vec4.inl:1160
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:971
JPH_INLINE Vec4 SplatY() const
Replicate the Y component to all components.
Definition Vec4.inl:820
JPH_INLINE UVec4 ReinterpretAsInt() const
Reinterpret Vec4 as a UVec4 (doesn't change the bits).
Definition Vec4.inl:1119
static JPH_INLINE UVec4 sGreaterOrEqual(Vec4Arg inV1, Vec4Arg inV2)
Greater than or equal (component wise).
Definition Vec4.inl:327
JPH_INLINE float ReduceSum() const
Sum X, Y, Z and W.
Definition Vec4.inl:988
static JPH_INLINE Vec4 sMin(Vec4Arg inV1, Vec4Arg inV2)
Return the minimum value of each of the components.
Definition Vec4.inl:188
Vec4(const Vec4 &inRHS)=default
JPH_INLINE Vec4 SplatZ() const
Replicate the Z component to all components.
Definition Vec4.inl:836
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:852
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:1012
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:402
JPH_INLINE float ReduceMin() const
Get the minimum of X, Y, Z and W.
Definition Vec4.inl:1149
Type mValue
Definition Vec4.h:317
static JPH_INLINE Vec4 sDecompressUnitVector(uint32 inValue)
Decompress a unit vector from a 32 bit value.
Definition Vec4.inl:1418
JPH_INLINE uint32 CompressUnitVector() const
Compress a unit vector to a 32 bit value, precision is around 0.5 * 10^-3.
Definition Vec4.inl:1374
JPH_INLINE float LengthSq() const
Squared length of vector.
Definition Vec4.inl:1017
static JPH_INLINE Vec4 sMax(Vec4Arg inV1, Vec4Arg inV2)
Return the maximum of each of the components.
Definition Vec4.inl:209
JPH_INLINE float Dot(Vec4Arg inV2) const
Dot product.
Definition Vec4.inl:1007
JPH_INLINE Vec3 SplatZ3() const
Replicate the Z component to all components.
Definition Vec4.inl:900
JPH_INLINE Vec3 SplatX3() const
Replicate the X component to all components.
Definition Vec4.inl:868
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:373
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:1130
JPH_INLINE int GetHighestComponentIndex() const
Get index of component with highest value.
Definition Vec4.inl:942
JPH_INLINE float GetY() const
Definition Vec4.h:120
JPH_INLINE Vec3 SplatY3() const
Replicate the Y component to all components.
Definition Vec4.inl:884
void SinCos(Vec4 &outSin, Vec4 &outCos) const
Calculate the sine and cosine for each element of this vector (input in radians).
Definition Vec4.inl:1171
JPH_INLINE void StoreFloat4(Float4 *outV) const
Store 4 floats to memory.
Definition Vec4.inl:1087
static JPH_INLINE Vec4 sClamp(Vec4Arg inV, Vec4Arg inMin, Vec4Arg inMax)
Clamp a vector between min and max (component wise).
Definition Vec4.inl:230