| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
#pragma once |
| 6 |
|
| 7 |
#include <Jolt/Math/Double3.h> |
| 8 |
|
| 9 |
JPH_NAMESPACE_BEGIN |
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
class [[nodiscard]] alignas(JPH_DVECTOR_ALIGNMENT) DVec3 |
| 14 |
{ |
| 15 |
public: |
| 16 |
JPH_OVERRIDE_NEW_DELETE |
| 17 |
|
| 18 |
|
| 19 |
#if defined(JPH_USE_AVX) |
| 20 |
using Type = __m256d; |
| 21 |
using TypeArg = __m256d; |
| 22 |
#elif defined(JPH_USE_SSE) |
| 23 |
using Type = struct { __m128d mLow, mHigh; }; |
| 24 |
using TypeArg = const Type &; |
| 25 |
#elif defined(JPH_USE_NEON) |
| 26 |
using Type = float64x2x2_t; |
| 27 |
using TypeArg = const Type &; |
| 28 |
#else |
| 29 |
using Type = struct { double mData[4]; }; |
| 30 |
using TypeArg = const Type &; |
| 31 |
#endif |
| 32 |
|
| 33 |
|
| 34 |
using ArgType = DVec3Arg; |
| 35 |
|
| 36 |
|
| 37 |
DVec3() = default; |
| 38 |
DVec3(const DVec3 &inRHS) = default; |
| 39 |
DVec3 & operator = (const DVec3 &inRHS) = default; |
| 40 |
JPH_INLINE explicit DVec3(Vec3Arg inRHS); |
| 41 |
JPH_INLINE explicit DVec3(Vec4Arg inRHS); |
| 42 |
JPH_INLINE DVec3(TypeArg inRHS) : mValue(inRHS) { CheckW(); } |
| 43 |
|
| 44 |
|
| 45 |
JPH_INLINE DVec3(double inX, double inY, double inZ); |
| 46 |
|
| 47 |
|
| 48 |
explicit JPH_INLINE DVec3(const Double3 &inV); |
| 49 |
|
| 50 |
|
| 51 |
static JPH_INLINE DVec3 sZero(); |
| 52 |
|
| 53 |
|
| 54 |
static JPH_INLINE DVec3 sOne(); |
| 55 |
|
| 56 |
|
| 57 |
static JPH_INLINE DVec3 sAxisX() { return DVec3(1, 0, 0); } |
| 58 |
static JPH_INLINE DVec3 sAxisY() { return DVec3(0, 1, 0); } |
| 59 |
static JPH_INLINE DVec3 sAxisZ() { return DVec3(0, 0, 1); } |
| 60 |
|
| 61 |
|
| 62 |
static JPH_INLINE DVec3 sReplicate(double inV); |
| 63 |
|
| 64 |
|
| 65 |
static JPH_INLINE DVec3 sNaN(); |
| 66 |
|
| 67 |
|
| 68 |
static JPH_INLINE DVec3 sLoadDouble3Unsafe(const Double3 &inV); |
| 69 |
|
| 70 |
|
| 71 |
JPH_INLINE void StoreDouble3(Double3 *outV) const; |
| 72 |
|
| 73 |
|
| 74 |
JPH_INLINE explicit operator Vec3() const; |
| 75 |
|
| 76 |
|
| 77 |
JPH_INLINE DVec3 PrepareRoundToZero() const; |
| 78 |
|
| 79 |
|
| 80 |
JPH_INLINE DVec3 PrepareRoundToInf() const; |
| 81 |
|
| 82 |
|
| 83 |
JPH_INLINE Vec3 ToVec3RoundDown() const; |
| 84 |
|
| 85 |
|
| 86 |
JPH_INLINE Vec3 ToVec3RoundUp() const; |
| 87 |
|
| 88 |
|
| 89 |
static JPH_INLINE DVec3 sMin(DVec3Arg inV1, DVec3Arg inV2); |
| 90 |
|
| 91 |
|
| 92 |
static JPH_INLINE DVec3 sMax(DVec3Arg inV1, DVec3Arg inV2); |
| 93 |
|
| 94 |
|
| 95 |
static JPH_INLINE DVec3 sClamp(DVec3Arg inV, DVec3Arg inMin, DVec3Arg inMax); |
| 96 |
|
| 97 |
|
| 98 |
static JPH_INLINE DVec3 sEquals(DVec3Arg inV1, DVec3Arg inV2); |
| 99 |
|
| 100 |
|
| 101 |
static JPH_INLINE DVec3 sLess(DVec3Arg inV1, DVec3Arg inV2); |
| 102 |
|
| 103 |
|
| 104 |
static JPH_INLINE DVec3 sLessOrEqual(DVec3Arg inV1, DVec3Arg inV2); |
| 105 |
|
| 106 |
|
| 107 |
static JPH_INLINE DVec3 sGreater(DVec3Arg inV1, DVec3Arg inV2); |
| 108 |
|
| 109 |
|
| 110 |
static JPH_INLINE DVec3 sGreaterOrEqual(DVec3Arg inV1, DVec3Arg inV2); |
| 111 |
|
| 112 |
|
| 113 |
static JPH_INLINE DVec3 sFusedMultiplyAdd(DVec3Arg inMul1, DVec3Arg inMul2, DVec3Arg inAdd); |
| 114 |
|
| 115 |
|
| 116 |
static JPH_INLINE DVec3 sSelect(DVec3Arg inNotSet, DVec3Arg inSet, DVec3Arg inControl); |
| 117 |
|
| 118 |
|
| 119 |
static JPH_INLINE DVec3 sOr(DVec3Arg inV1, DVec3Arg inV2); |
| 120 |
|
| 121 |
|
| 122 |
static JPH_INLINE DVec3 sXor(DVec3Arg inV1, DVec3Arg inV2); |
| 123 |
|
| 124 |
|
| 125 |
static JPH_INLINE DVec3 sAnd(DVec3Arg inV1, DVec3Arg inV2); |
| 126 |
|
| 127 |
|
| 128 |
JPH_INLINE int GetTrues() const; |
| 129 |
|
| 130 |
|
| 131 |
JPH_INLINE bool TestAnyTrue() const; |
| 132 |
|
| 133 |
|
| 134 |
JPH_INLINE bool TestAllTrue() const; |
| 135 |
|
| 136 |
|
| 137 |
#if defined(JPH_USE_AVX) |
| 138 |
JPH_INLINE double GetX() const { return _mm_cvtsd_f64(_mm256_castpd256_pd128(mValue)); } |
| 139 |
JPH_INLINE double GetY() const { return mF64[1]; } |
| 140 |
JPH_INLINE double GetZ() const { return mF64[2]; } |
| 141 |
#elif defined(JPH_USE_SSE) |
| 142 |
JPH_INLINE double GetX() const { return _mm_cvtsd_f64(mValue.mLow); } |
| 143 |
JPH_INLINE double GetY() const { return mF64[1]; } |
| 144 |
JPH_INLINE double GetZ() const { return _mm_cvtsd_f64(mValue.mHigh); } |
| 145 |
#elif defined(JPH_USE_NEON) |
| 146 |
JPH_INLINE double GetX() const { return vgetq_lane_f64(mValue.val[0], 0); } |
| 147 |
JPH_INLINE double GetY() const { return vgetq_lane_f64(mValue.val[0], 1); } |
| 148 |
JPH_INLINE double GetZ() const { return vgetq_lane_f64(mValue.val[1], 0); } |
| 149 |
#else |
| 150 |
JPH_INLINE double GetX() const { return mF64[0]; } |
| 151 |
JPH_INLINE double GetY() const { return mF64[1]; } |
| 152 |
JPH_INLINE double GetZ() const { return mF64[2]; } |
| 153 |
#endif |
| 154 |
|
| 155 |
|
| 156 |
JPH_INLINE void SetX(double inX) { mF64[0] = inX; } |
| 157 |
JPH_INLINE void SetY(double inY) { mF64[1] = inY; } |
| 158 |
JPH_INLINE void SetZ(double inZ) { mF64[2] = mF64[3] = inZ; } |
| 159 |
|
| 160 |
|
| 161 |
JPH_INLINE void Set(double inX, double inY, double inZ) { *this = DVec3(inX, inY, inZ); } |
| 162 |
|
| 163 |
|
| 164 |
JPH_INLINE double operator [] (uint inCoordinate) const { JPH_ASSERT(inCoordinate < 3); return mF64[inCoordinate]; } |
| 165 |
|
| 166 |
|
| 167 |
JPH_INLINE void SetComponent(uint inCoordinate, double inValue) { JPH_ASSERT(inCoordinate < 3); mF64[inCoordinate] = inValue; mValue = sFixW(mValue); } |
| 168 |
|
| 169 |
|
| 170 |
JPH_INLINE bool operator == (DVec3Arg inV2) const; |
| 171 |
JPH_INLINE bool operator != (DVec3Arg inV2) const { return !(*this == inV2); } |
| 172 |
|
| 173 |
|
| 174 |
JPH_INLINE bool IsClose(DVec3Arg inV2, double inMaxDistSq = 1.0e-24) const; |
| 175 |
|
| 176 |
|
| 177 |
JPH_INLINE bool IsNearZero(double inMaxDistSq = 1.0e-24) const; |
| 178 |
|
| 179 |
|
| 180 |
JPH_INLINE bool IsNormalized(double inTolerance = 1.0e-12) const; |
| 181 |
|
| 182 |
|
| 183 |
JPH_INLINE bool IsNaN() const; |
| 184 |
|
| 185 |
|
| 186 |
JPH_INLINE DVec3 operator * (DVec3Arg inV2) const; |
| 187 |
|
| 188 |
|
| 189 |
JPH_INLINE DVec3 operator * (double inV2) const; |
| 190 |
|
| 191 |
|
| 192 |
friend JPH_INLINE DVec3 operator * (double inV1, DVec3Arg inV2); |
| 193 |
|
| 194 |
|
| 195 |
JPH_INLINE DVec3 operator / (double inV2) const; |
| 196 |
|
| 197 |
|
| 198 |
JPH_INLINE DVec3 & operator *= (double inV2); |
| 199 |
|
| 200 |
|
| 201 |
JPH_INLINE DVec3 & operator *= (DVec3Arg inV2); |
| 202 |
|
| 203 |
|
| 204 |
JPH_INLINE DVec3 & operator /= (double inV2); |
| 205 |
|
| 206 |
|
| 207 |
JPH_INLINE DVec3 operator + (Vec3Arg inV2) const; |
| 208 |
|
| 209 |
|
| 210 |
JPH_INLINE DVec3 operator + (DVec3Arg inV2) const; |
| 211 |
|
| 212 |
|
| 213 |
JPH_INLINE DVec3 & operator += (Vec3Arg inV2); |
| 214 |
|
| 215 |
|
| 216 |
JPH_INLINE DVec3 & operator += (DVec3Arg inV2); |
| 217 |
|
| 218 |
|
| 219 |
JPH_INLINE DVec3 operator - () const; |
| 220 |
|
| 221 |
|
| 222 |
JPH_INLINE DVec3 operator - (Vec3Arg inV2) const; |
| 223 |
|
| 224 |
|
| 225 |
JPH_INLINE DVec3 operator - (DVec3Arg inV2) const; |
| 226 |
|
| 227 |
|
| 228 |
JPH_INLINE DVec3 & operator -= (Vec3Arg inV2); |
| 229 |
|
| 230 |
|
| 231 |
JPH_INLINE DVec3 & operator -= (DVec3Arg inV2); |
| 232 |
|
| 233 |
|
| 234 |
JPH_INLINE DVec3 operator / (DVec3Arg inV2) const; |
| 235 |
|
| 236 |
|
| 237 |
JPH_INLINE DVec3 Abs() const; |
| 238 |
|
| 239 |
|
| 240 |
JPH_INLINE DVec3 Reciprocal() const; |
| 241 |
|
| 242 |
|
| 243 |
JPH_INLINE DVec3 Cross(DVec3Arg inV2) const; |
| 244 |
|
| 245 |
|
| 246 |
JPH_INLINE double Dot(DVec3Arg inV2) const; |
| 247 |
|
| 248 |
|
| 249 |
JPH_INLINE double LengthSq() const; |
| 250 |
|
| 251 |
|
| 252 |
JPH_INLINE double Length() const; |
| 253 |
|
| 254 |
|
| 255 |
JPH_INLINE DVec3 Normalized() const; |
| 256 |
|
| 257 |
|
| 258 |
JPH_INLINE DVec3 Sqrt() const; |
| 259 |
|
| 260 |
|
| 261 |
JPH_INLINE DVec3 GetSign() const; |
| 262 |
|
| 263 |
|
| 264 |
friend ostream & operator << (ostream &inStream, DVec3Arg inV) |
| 265 |
{ |
| 266 |
inStream << inV.mF64[0] << ", " << inV.mF64[1] << ", " << inV.mF64[2]; |
| 267 |
return inStream; |
| 268 |
} |
| 269 |
|
| 270 |
|
| 271 |
JPH_INLINE void CheckW() const; |
| 272 |
|
| 273 |
|
| 274 |
static JPH_INLINE Type sFixW(TypeArg inValue); |
| 275 |
|
| 276 |
|
| 277 |
inline static const double cTrue = BitCast<double>(~uint64(0)); |
| 278 |
inline static const double cFalse = 0.0; |
| 279 |
|
| 280 |
union |
| 281 |
{ |
| 282 |
Type mValue; |
| 283 |
double mF64[4]; |
| 284 |
}; |
| 285 |
}; |
| 286 |
|
| 287 |
static_assert(std::is_trivial<DVec3>(), "Is supposed to be a trivial type!"); |
| 288 |
|
| 289 |
JPH_NAMESPACE_END |
| 290 |
|
| 291 |
#include "DVec3.inl" |