| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
#pragma once |
| 6 |
|
| 7 |
#include <Jolt/Math/Float4.h> |
| 8 |
#include <Jolt/Math/Swizzle.h> |
| 9 |
#include <Jolt/Math/MathTypes.h> |
| 10 |
|
| 11 |
JPH_NAMESPACE_BEGIN |
| 12 |
|
| 13 |
class [[nodiscard]] alignas(JPH_VECTOR_ALIGNMENT) Vec4 |
| 14 |
{ |
| 15 |
public: |
| 16 |
JPH_OVERRIDE_NEW_DELETE |
| 17 |
|
| 18 |
|
| 19 |
#if defined(JPH_USE_SSE) |
| 20 |
using Type = __m128; |
| 21 |
#elif defined(JPH_USE_NEON) |
| 22 |
using Type = float32x4_t; |
| 23 |
#else |
| 24 |
using Type = struct { float mData[4]; }; |
| 25 |
#endif |
| 26 |
|
| 27 |
|
| 28 |
Vec4() = default; |
| 29 |
Vec4(const Vec4 &inRHS) = default; |
| 30 |
Vec4 & operator = (const Vec4 &inRHS) = default; |
| 31 |
explicit JPH_INLINE Vec4(Vec3Arg inRHS); |
| 32 |
JPH_INLINE Vec4(Vec3Arg inRHS, float inW); |
| 33 |
JPH_INLINE Vec4(Type inRHS) : mValue(inRHS) { } |
| 34 |
|
| 35 |
|
| 36 |
JPH_INLINE Vec4(float inX, float inY, float inZ, float inW); |
| 37 |
|
| 38 |
|
| 39 |
static JPH_INLINE Vec4 sZero(); |
| 40 |
|
| 41 |
|
| 42 |
static JPH_INLINE Vec4 sOne(); |
| 43 |
|
| 44 |
|
| 45 |
static JPH_INLINE Vec4 sNaN(); |
| 46 |
|
| 47 |
|
| 48 |
static JPH_INLINE Vec4 sReplicate(float inV); |
| 49 |
|
| 50 |
|
| 51 |
static JPH_INLINE Vec4 sLoadFloat4(const Float4 *inV); |
| 52 |
|
| 53 |
|
| 54 |
static JPH_INLINE Vec4 sLoadFloat4Aligned(const Float4 *inV); |
| 55 |
|
| 56 |
|
| 57 |
template <const int Scale> |
| 58 |
static JPH_INLINE Vec4 sGatherFloat4(const float *inBase, UVec4Arg inOffsets); |
| 59 |
|
| 60 |
|
| 61 |
static JPH_INLINE Vec4 sMin(Vec4Arg inV1, Vec4Arg inV2); |
| 62 |
|
| 63 |
|
| 64 |
static JPH_INLINE Vec4 sMax(Vec4Arg inV1, Vec4Arg inV2); |
| 65 |
|
| 66 |
|
| 67 |
static JPH_INLINE Vec4 sClamp(Vec4Arg inV, Vec4Arg inMin, Vec4Arg inMax); |
| 68 |
|
| 69 |
|
| 70 |
static JPH_INLINE UVec4 sEquals(Vec4Arg inV1, Vec4Arg inV2); |
| 71 |
|
| 72 |
|
| 73 |
static JPH_INLINE UVec4 sLess(Vec4Arg inV1, Vec4Arg inV2); |
| 74 |
|
| 75 |
|
| 76 |
static JPH_INLINE UVec4 sLessOrEqual(Vec4Arg inV1, Vec4Arg inV2); |
| 77 |
|
| 78 |
|
| 79 |
static JPH_INLINE UVec4 sGreater(Vec4Arg inV1, Vec4Arg inV2); |
| 80 |
|
| 81 |
|
| 82 |
static JPH_INLINE UVec4 sGreaterOrEqual(Vec4Arg inV1, Vec4Arg inV2); |
| 83 |
|
| 84 |
|
| 85 |
static JPH_INLINE Vec4 sFusedMultiplyAdd(Vec4Arg inMul1, Vec4Arg inMul2, Vec4Arg inAdd); |
| 86 |
|
| 87 |
|
| 88 |
static JPH_INLINE Vec4 sSelect(Vec4Arg inNotSet, Vec4Arg inSet, UVec4Arg inControl); |
| 89 |
|
| 90 |
|
| 91 |
static JPH_INLINE Vec4 sOr(Vec4Arg inV1, Vec4Arg inV2); |
| 92 |
|
| 93 |
|
| 94 |
static JPH_INLINE Vec4 sXor(Vec4Arg inV1, Vec4Arg inV2); |
| 95 |
|
| 96 |
|
| 97 |
static JPH_INLINE Vec4 sAnd(Vec4Arg inV1, Vec4Arg inV2); |
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
static JPH_INLINE void sSort4(Vec4 &ioValue, UVec4 &ioIndex); |
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
static JPH_INLINE void sSort4Reverse(Vec4 &ioValue, UVec4 &ioIndex); |
| 106 |
|
| 107 |
|
| 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); } |
| 118 |
#else |
| 119 |
JPH_INLINE float GetX() const { return mF32[0]; } |
| 120 |
JPH_INLINE float GetY() const { return mF32[1]; } |
| 121 |
JPH_INLINE float GetZ() const { return mF32[2]; } |
| 122 |
JPH_INLINE float GetW() const { return mF32[3]; } |
| 123 |
#endif |
| 124 |
|
| 125 |
|
| 126 |
JPH_INLINE void SetX(float inX) { mF32[0] = inX; } |
| 127 |
JPH_INLINE void SetY(float inY) { mF32[1] = inY; } |
| 128 |
JPH_INLINE void SetZ(float inZ) { mF32[2] = inZ; } |
| 129 |
JPH_INLINE void SetW(float inW) { mF32[3] = inW; } |
| 130 |
|
| 131 |
|
| 132 |
JPH_INLINE void Set(float inX, float inY, float inZ, float inW) { *this = Vec4(inX, inY, inZ, inW); } |
| 133 |
|
| 134 |
|
| 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]; } |
| 137 |
|
| 138 |
|
| 139 |
JPH_INLINE bool operator == (Vec4Arg inV2) const; |
| 140 |
JPH_INLINE bool operator != (Vec4Arg inV2) const { return !(*this == inV2); } |
| 141 |
|
| 142 |
|
| 143 |
JPH_INLINE bool IsClose(Vec4Arg inV2, float inMaxDistSq = 1.0e-12f) const; |
| 144 |
|
| 145 |
|
| 146 |
JPH_INLINE bool IsNearZero(float inMaxDistSq = 1.0e-12f) const; |
| 147 |
|
| 148 |
|
| 149 |
JPH_INLINE bool IsNormalized(float inTolerance = 1.0e-6f) const; |
| 150 |
|
| 151 |
|
| 152 |
JPH_INLINE bool IsNaN() const; |
| 153 |
|
| 154 |
|
| 155 |
JPH_INLINE Vec4 operator * (Vec4Arg inV2) const; |
| 156 |
|
| 157 |
|
| 158 |
JPH_INLINE Vec4 operator * (float inV2) const; |
| 159 |
|
| 160 |
|
| 161 |
friend JPH_INLINE Vec4 operator * (float inV1, Vec4Arg inV2); |
| 162 |
|
| 163 |
|
| 164 |
JPH_INLINE Vec4 operator / (float inV2) const; |
| 165 |
|
| 166 |
|
| 167 |
JPH_INLINE Vec4 & operator *= (float inV2); |
| 168 |
|
| 169 |
|
| 170 |
JPH_INLINE Vec4 & operator *= (Vec4Arg inV2); |
| 171 |
|
| 172 |
|
| 173 |
JPH_INLINE Vec4 & operator /= (float inV2); |
| 174 |
|
| 175 |
|
| 176 |
JPH_INLINE Vec4 operator + (Vec4Arg inV2) const; |
| 177 |
|
| 178 |
|
| 179 |
JPH_INLINE Vec4 & operator += (Vec4Arg inV2); |
| 180 |
|
| 181 |
|
| 182 |
JPH_INLINE Vec4 operator - () const; |
| 183 |
|
| 184 |
|
| 185 |
JPH_INLINE Vec4 operator - (Vec4Arg inV2) const; |
| 186 |
|
| 187 |
|
| 188 |
JPH_INLINE Vec4 & operator -= (Vec4Arg inV2); |
| 189 |
|
| 190 |
|
| 191 |
JPH_INLINE Vec4 operator / (Vec4Arg inV2) const; |
| 192 |
|
| 193 |
|
| 194 |
template<uint32 SwizzleX, uint32 SwizzleY, uint32 SwizzleZ, uint32 SwizzleW> |
| 195 |
JPH_INLINE Vec4 Swizzle() const; |
| 196 |
|
| 197 |
|
| 198 |
JPH_INLINE Vec4 SplatX() const; |
| 199 |
|
| 200 |
|
| 201 |
JPH_INLINE Vec4 SplatY() const; |
| 202 |
|
| 203 |
|
| 204 |
JPH_INLINE Vec4 SplatZ() const; |
| 205 |
|
| 206 |
|
| 207 |
JPH_INLINE Vec4 SplatW() const; |
| 208 |
|
| 209 |
|
| 210 |
JPH_INLINE Vec3 SplatX3() const; |
| 211 |
|
| 212 |
|
| 213 |
JPH_INLINE Vec3 SplatY3() const; |
| 214 |
|
| 215 |
|
| 216 |
JPH_INLINE Vec3 SplatZ3() const; |
| 217 |
|
| 218 |
|
| 219 |
JPH_INLINE Vec3 SplatW3() const; |
| 220 |
|
| 221 |
|
| 222 |
JPH_INLINE int GetLowestComponentIndex() const; |
| 223 |
|
| 224 |
|
| 225 |
JPH_INLINE int GetHighestComponentIndex() const; |
| 226 |
|
| 227 |
|
| 228 |
JPH_INLINE Vec4 Abs() const; |
| 229 |
|
| 230 |
|
| 231 |
JPH_INLINE Vec4 Reciprocal() const; |
| 232 |
|
| 233 |
|
| 234 |
JPH_INLINE Vec4 DotV(Vec4Arg inV2) const; |
| 235 |
|
| 236 |
|
| 237 |
JPH_INLINE float Dot(Vec4Arg inV2) const; |
| 238 |
|
| 239 |
|
| 240 |
JPH_INLINE float LengthSq() const; |
| 241 |
|
| 242 |
|
| 243 |
JPH_INLINE float Length() const; |
| 244 |
|
| 245 |
|
| 246 |
JPH_INLINE Vec4 Normalized() const; |
| 247 |
|
| 248 |
|
| 249 |
JPH_INLINE void StoreFloat4(Float4 *outV) const; |
| 250 |
|
| 251 |
|
| 252 |
JPH_INLINE UVec4 ToInt() const; |
| 253 |
|
| 254 |
|
| 255 |
JPH_INLINE UVec4 ReinterpretAsInt() const; |
| 256 |
|
| 257 |
|
| 258 |
JPH_INLINE int GetSignBits() const; |
| 259 |
|
| 260 |
|
| 261 |
JPH_INLINE float ReduceMin() const; |
| 262 |
|
| 263 |
|
| 264 |
JPH_INLINE float ReduceMax() const; |
| 265 |
|
| 266 |
|
| 267 |
JPH_INLINE Vec4 Sqrt() const; |
| 268 |
|
| 269 |
|
| 270 |
JPH_INLINE Vec4 GetSign() const; |
| 271 |
|
| 272 |
|
| 273 |
template <int X, int Y, int Z, int W> |
| 274 |
JPH_INLINE Vec4 FlipSign() const; |
| 275 |
|
| 276 |
|
| 277 |
inline void SinCos(Vec4 &outSin, Vec4 &outCos) const; |
| 278 |
|
| 279 |
|
| 280 |
inline Vec4 Tan() const; |
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
inline Vec4 ASin() const; |
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
inline Vec4 ACos() const; |
| 289 |
|
| 290 |
|
| 291 |
inline Vec4 ATan() const; |
| 292 |
|
| 293 |
|
| 294 |
inline static Vec4 sATan2(Vec4Arg inY, Vec4Arg inX); |
| 295 |
|
| 296 |
|
| 297 |
JPH_INLINE uint32 CompressUnitVector() const; |
| 298 |
|
| 299 |
|
| 300 |
JPH_INLINE static Vec4 sDecompressUnitVector(uint32 inValue); |
| 301 |
|
| 302 |
|
| 303 |
friend ostream & operator << (ostream &inStream, Vec4Arg inV) |
| 304 |
{ |
| 305 |
inStream << inV.mF32[0] << ", " << inV.mF32[1] << ", " << inV.mF32[2] << ", " << inV.mF32[3]; |
| 306 |
return inStream; |
| 307 |
} |
| 308 |
|
| 309 |
union |
| 310 |
{ |
| 311 |
Type mValue; |
| 312 |
float mF32[4]; |
| 313 |
}; |
| 314 |
}; |
| 315 |
|
| 316 |
static_assert(std::is_trivial<Vec4>(), "Is supposed to be a trivial type!"); |
| 317 |
|
| 318 |
JPH_NAMESPACE_END |
| 319 |
|
| 320 |
#include "Vec4.inl" |