Jolt Physics
A multi core friendly Game Physics Engine
Loading...
Searching...
No Matches
Vec4.inl
Go to the documentation of this file.
1// Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)
2// SPDX-FileCopyrightText: 2021 Jorrit Rouwe
3// SPDX-License-Identifier: MIT
4
6#include <Jolt/Math/Vec3.h>
7#include <Jolt/Math/UVec4.h>
8
10
11// Constructor
13 mValue(inRHS.mValue)
14{
15}
16
17Vec4::Vec4(Vec3Arg inRHS, float inW)
18{
19#if defined(JPH_USE_SSE4_1)
20 mValue = _mm_blend_ps(inRHS.mValue, _mm_set1_ps(inW), 8);
21#elif defined(JPH_USE_NEON)
22 mValue = vsetq_lane_f32(inW, inRHS.mValue, 3);
23#else
24 for (int i = 0; i < 3; i++)
25 mF32[i] = inRHS.mF32[i];
26 mF32[3] = inW;
27#endif
28}
29
30Vec4::Vec4(float inX, float inY, float inZ, float inW)
31{
32#if defined(JPH_USE_SSE)
33 mValue = _mm_set_ps(inW, inZ, inY, inX);
34#elif defined(JPH_USE_NEON)
35 uint32x2_t xy = vcreate_f32(static_cast<uint64>(*reinterpret_cast<uint32 *>(&inX)) | (static_cast<uint64>(*reinterpret_cast<uint32 *>(&inY)) << 32));
36 uint32x2_t zw = vcreate_f32(static_cast<uint64>(*reinterpret_cast<uint32* >(&inZ)) | (static_cast<uint64>(*reinterpret_cast<uint32 *>(&inW)) << 32));
37 mValue = vcombine_f32(xy, zw);
38#else
39 mF32[0] = inX;
40 mF32[1] = inY;
41 mF32[2] = inZ;
42 mF32[3] = inW;
43#endif
44}
45
46template<uint32 SwizzleX, uint32 SwizzleY, uint32 SwizzleZ, uint32 SwizzleW>
48{
49 static_assert(SwizzleX <= 3, "SwizzleX template parameter out of range");
50 static_assert(SwizzleY <= 3, "SwizzleY template parameter out of range");
51 static_assert(SwizzleZ <= 3, "SwizzleZ template parameter out of range");
52 static_assert(SwizzleW <= 3, "SwizzleW template parameter out of range");
53
54#if defined(JPH_USE_SSE)
55 return _mm_shuffle_ps(mValue, mValue, _MM_SHUFFLE(SwizzleW, SwizzleZ, SwizzleY, SwizzleX));
56#elif defined(JPH_USE_NEON)
57 return JPH_NEON_SHUFFLE_F32x4(mValue, mValue, SwizzleX, SwizzleY, SwizzleZ, SwizzleW);
58#else
59 return Vec4(mF32[SwizzleX], mF32[SwizzleY], mF32[SwizzleZ], mF32[SwizzleW]);
60#endif
61}
62
64{
65#if defined(JPH_USE_SSE)
66 return _mm_setzero_ps();
67#elif defined(JPH_USE_NEON)
68 return vdupq_n_f32(0);
69#else
70 return Vec4(0, 0, 0, 0);
71#endif
72}
73
75{
76#if defined(JPH_USE_SSE)
77 return _mm_set1_ps(inV);
78#elif defined(JPH_USE_NEON)
79 return vdupq_n_f32(inV);
80#else
81 return Vec4(inV, inV, inV, inV);
82#endif
83}
84
86{
87 return sReplicate(numeric_limits<float>::quiet_NaN());
88}
89
91{
92#if defined(JPH_USE_SSE)
93 return _mm_loadu_ps(&inV->x);
94#elif defined(JPH_USE_NEON)
95 return vld1q_f32(&inV->x);
96#else
97 return Vec4(inV->x, inV->y, inV->z, inV->w);
98#endif
99}
100
102{
103#if defined(JPH_USE_SSE)
104 return _mm_load_ps(&inV->x);
105#elif defined(JPH_USE_NEON)
106 return vld1q_f32(&inV->x);
107#else
108 return Vec4(inV->x, inV->y, inV->z, inV->w);
109#endif
110}
111
112template <const int Scale>
113Vec4 Vec4::sGatherFloat4(const float *inBase, UVec4Arg inOffsets)
114{
115#if defined(JPH_USE_SSE)
116 #ifdef JPH_USE_AVX2
117 return _mm_i32gather_ps(inBase, inOffsets.mValue, Scale);
118 #else
119 const uint8 *base = reinterpret_cast<const uint8 *>(inBase);
120 Type x = _mm_load_ss(reinterpret_cast<const float *>(base + inOffsets.GetX() * Scale));
121 Type y = _mm_load_ss(reinterpret_cast<const float *>(base + inOffsets.GetY() * Scale));
122 Type xy = _mm_unpacklo_ps(x, y);
123 Type z = _mm_load_ss(reinterpret_cast<const float *>(base + inOffsets.GetZ() * Scale));
124 Type w = _mm_load_ss(reinterpret_cast<const float *>(base + inOffsets.GetW() * Scale));
125 Type zw = _mm_unpacklo_ps(z, w);
126 return _mm_movelh_ps(xy, zw);
127 #endif
128#else
129 const uint8 *base = reinterpret_cast<const uint8 *>(inBase);
130 float x = *reinterpret_cast<const float *>(base + inOffsets.GetX() * Scale);
131 float y = *reinterpret_cast<const float *>(base + inOffsets.GetY() * Scale);
132 float z = *reinterpret_cast<const float *>(base + inOffsets.GetZ() * Scale);
133 float w = *reinterpret_cast<const float *>(base + inOffsets.GetW() * Scale);
134 return Vec4(x, y, z, w);
135#endif
136}
137
139{
140#if defined(JPH_USE_SSE)
141 return _mm_min_ps(inV1.mValue, inV2.mValue);
142#elif defined(JPH_USE_NEON)
143 return vminq_f32(inV1.mValue, inV2.mValue);
144#else
145 return Vec4(min(inV1.mF32[0], inV2.mF32[0]),
146 min(inV1.mF32[1], inV2.mF32[1]),
147 min(inV1.mF32[2], inV2.mF32[2]),
148 min(inV1.mF32[3], inV2.mF32[3]));
149#endif
150}
151
153{
154#if defined(JPH_USE_SSE)
155 return _mm_max_ps(inV1.mValue, inV2.mValue);
156#elif defined(JPH_USE_NEON)
157 return vmaxq_f32(inV1.mValue, inV2.mValue);
158#else
159 return Vec4(max(inV1.mF32[0], inV2.mF32[0]),
160 max(inV1.mF32[1], inV2.mF32[1]),
161 max(inV1.mF32[2], inV2.mF32[2]),
162 max(inV1.mF32[3], inV2.mF32[3]));
163#endif
164}
165
167{
168#if defined(JPH_USE_SSE)
169 return _mm_castps_si128(_mm_cmpeq_ps(inV1.mValue, inV2.mValue));
170#elif defined(JPH_USE_NEON)
171 return vceqq_f32(inV1.mValue, inV2.mValue);
172#else
173 return UVec4(inV1.mF32[0] == inV2.mF32[0]? 0xffffffffu : 0,
174 inV1.mF32[1] == inV2.mF32[1]? 0xffffffffu : 0,
175 inV1.mF32[2] == inV2.mF32[2]? 0xffffffffu : 0,
176 inV1.mF32[3] == inV2.mF32[3]? 0xffffffffu : 0);
177#endif
178}
179
181{
182#if defined(JPH_USE_SSE)
183 return _mm_castps_si128(_mm_cmplt_ps(inV1.mValue, inV2.mValue));
184#elif defined(JPH_USE_NEON)
185 return vcltq_f32(inV1.mValue, inV2.mValue);
186#else
187 return UVec4(inV1.mF32[0] < inV2.mF32[0]? 0xffffffffu : 0,
188 inV1.mF32[1] < inV2.mF32[1]? 0xffffffffu : 0,
189 inV1.mF32[2] < inV2.mF32[2]? 0xffffffffu : 0,
190 inV1.mF32[3] < inV2.mF32[3]? 0xffffffffu : 0);
191#endif
192}
193
195{
196#if defined(JPH_USE_SSE)
197 return _mm_castps_si128(_mm_cmple_ps(inV1.mValue, inV2.mValue));
198#elif defined(JPH_USE_NEON)
199 return vcleq_f32(inV1.mValue, inV2.mValue);
200#else
201 return UVec4(inV1.mF32[0] <= inV2.mF32[0]? 0xffffffffu : 0,
202 inV1.mF32[1] <= inV2.mF32[1]? 0xffffffffu : 0,
203 inV1.mF32[2] <= inV2.mF32[2]? 0xffffffffu : 0,
204 inV1.mF32[3] <= inV2.mF32[3]? 0xffffffffu : 0);
205#endif
206}
207
209{
210#if defined(JPH_USE_SSE)
211 return _mm_castps_si128(_mm_cmpgt_ps(inV1.mValue, inV2.mValue));
212#elif defined(JPH_USE_NEON)
213 return vcgtq_f32(inV1.mValue, inV2.mValue);
214#else
215 return UVec4(inV1.mF32[0] > inV2.mF32[0]? 0xffffffffu : 0,
216 inV1.mF32[1] > inV2.mF32[1]? 0xffffffffu : 0,
217 inV1.mF32[2] > inV2.mF32[2]? 0xffffffffu : 0,
218 inV1.mF32[3] > inV2.mF32[3]? 0xffffffffu : 0);
219#endif
220}
221
223{
224#if defined(JPH_USE_SSE)
225 return _mm_castps_si128(_mm_cmpge_ps(inV1.mValue, inV2.mValue));
226#elif defined(JPH_USE_NEON)
227 return vcgeq_f32(inV1.mValue, inV2.mValue);
228#else
229 return UVec4(inV1.mF32[0] >= inV2.mF32[0]? 0xffffffffu : 0,
230 inV1.mF32[1] >= inV2.mF32[1]? 0xffffffffu : 0,
231 inV1.mF32[2] >= inV2.mF32[2]? 0xffffffffu : 0,
232 inV1.mF32[3] >= inV2.mF32[3]? 0xffffffffu : 0);
233#endif
234}
235
237{
238#if defined(JPH_USE_SSE)
239 #ifdef JPH_USE_FMADD
240 return _mm_fmadd_ps(inMul1.mValue, inMul2.mValue, inAdd.mValue);
241 #else
242 return _mm_add_ps(_mm_mul_ps(inMul1.mValue, inMul2.mValue), inAdd.mValue);
243 #endif
244#elif defined(JPH_USE_NEON)
245 return vmlaq_f32(inAdd.mValue, inMul1.mValue, inMul2.mValue);
246#else
247 return Vec4(inMul1.mF32[0] * inMul2.mF32[0] + inAdd.mF32[0],
248 inMul1.mF32[1] * inMul2.mF32[1] + inAdd.mF32[1],
249 inMul1.mF32[2] * inMul2.mF32[2] + inAdd.mF32[2],
250 inMul1.mF32[3] * inMul2.mF32[3] + inAdd.mF32[3]);
251#endif
252}
253
255{
256#if defined(JPH_USE_SSE4_1)
257 return _mm_blendv_ps(inV1.mValue, inV2.mValue, _mm_castsi128_ps(inControl.mValue));
258#elif defined(JPH_USE_NEON)
259 return vbslq_f32(vshrq_n_s32(inControl.mValue, 31), inV2.mValue, inV1.mValue);
260#else
261 Vec4 result;
262 for (int i = 0; i < 4; i++)
263 result.mF32[i] = inControl.mU32[i] ? inV2.mF32[i] : inV1.mF32[i];
264 return result;
265#endif
266}
267
269{
270#if defined(JPH_USE_SSE)
271 return _mm_or_ps(inV1.mValue, inV2.mValue);
272#elif defined(JPH_USE_NEON)
273 return vorrq_s32(inV1.mValue, inV2.mValue);
274#else
276#endif
277}
278
280{
281#if defined(JPH_USE_SSE)
282 return _mm_xor_ps(inV1.mValue, inV2.mValue);
283#elif defined(JPH_USE_NEON)
284 return veorq_s32(inV1.mValue, inV2.mValue);
285#else
287#endif
288}
289
291{
292#if defined(JPH_USE_SSE)
293 return _mm_and_ps(inV1.mValue, inV2.mValue);
294#elif defined(JPH_USE_NEON)
295 return vandq_s32(inV1.mValue, inV2.mValue);
296#else
298#endif
299}
300
301void Vec4::sSort4(Vec4 &ioValue, UVec4 &ioIndex)
302{
303 // Pass 1, test 1st vs 3rd, 2nd vs 4th
306 UVec4 c1 = sLess(ioValue, v1).Swizzle<SWIZZLE_Z, SWIZZLE_W, SWIZZLE_Z, SWIZZLE_W>();
307 ioValue = sSelect(ioValue, v1, c1);
308 ioIndex = UVec4::sSelect(ioIndex, i1, c1);
309
310 // Pass 2, test 1st vs 2nd, 3rd vs 4th
313 UVec4 c2 = sLess(ioValue, v2).Swizzle<SWIZZLE_Y, SWIZZLE_Y, SWIZZLE_W, SWIZZLE_W>();
314 ioValue = sSelect(ioValue, v2, c2);
315 ioIndex = UVec4::sSelect(ioIndex, i2, c2);
316
317 // Pass 3, test 2nd vs 3rd component
320 UVec4 c3 = sLess(ioValue, v3).Swizzle<SWIZZLE_X, SWIZZLE_Z, SWIZZLE_Z, SWIZZLE_W>();
321 ioValue = sSelect(ioValue, v3, c3);
322 ioIndex = UVec4::sSelect(ioIndex, i3, c3);
323}
324
325void Vec4::sSort4Reverse(Vec4 &ioValue, UVec4 &ioIndex)
326{
327 // Pass 1, test 1st vs 3rd, 2nd vs 4th
331 ioValue = sSelect(ioValue, v1, c1);
332 ioIndex = UVec4::sSelect(ioIndex, i1, c1);
333
334 // Pass 2, test 1st vs 2nd, 3rd vs 4th
338 ioValue = sSelect(ioValue, v2, c2);
339 ioIndex = UVec4::sSelect(ioIndex, i2, c2);
340
341 // Pass 3, test 2nd vs 3rd component
345 ioValue = sSelect(ioValue, v3, c3);
346 ioIndex = UVec4::sSelect(ioIndex, i3, c3);
347}
348
350{
351 return sEquals(*this, inV2).TestAllTrue();
352}
353
354bool Vec4::IsClose(Vec4Arg inV2, float inMaxDistSq) const
355{
356 return (inV2 - *this).LengthSq() <= inMaxDistSq;
357}
358
359bool Vec4::IsNormalized(float inTolerance) const
360{
361 return abs(LengthSq() - 1.0f) <= inTolerance;
362}
363
364bool Vec4::IsNaN() const
365{
366#if defined(JPH_USE_AVX512)
367 return _mm_fpclass_ps_mask(mValue, 0b10000001) != 0;
368#elif defined(JPH_USE_SSE)
369 return _mm_movemask_ps(_mm_cmpunord_ps(mValue, mValue)) != 0;
370#elif defined(JPH_USE_NEON)
371 uint32x4_t is_equal = vceqq_f32(mValue, mValue); // If a number is not equal to itself it's a NaN
372 return vaddvq_u32(vshrq_n_u32(is_equal, 31)) != 4;
373#else
374 return isnan(mF32[0]) || isnan(mF32[1]) || isnan(mF32[2]) || isnan(mF32[3]);
375#endif
376}
377
379{
380#if defined(JPH_USE_SSE)
381 return _mm_mul_ps(mValue, inV2.mValue);
382#elif defined(JPH_USE_NEON)
383 return vmulq_f32(mValue, inV2.mValue);
384#else
385 return Vec4(mF32[0] * inV2.mF32[0],
386 mF32[1] * inV2.mF32[1],
387 mF32[2] * inV2.mF32[2],
388 mF32[3] * inV2.mF32[3]);
389#endif
390}
391
392Vec4 Vec4::operator * (float inV2) const
393{
394#if defined(JPH_USE_SSE)
395 return _mm_mul_ps(mValue, _mm_set1_ps(inV2));
396#elif defined(JPH_USE_NEON)
397 return vmulq_n_f32(mValue, inV2);
398#else
399 return Vec4(mF32[0] * inV2, mF32[1] * inV2, mF32[2] * inV2, mF32[3] * inV2);
400#endif
401}
402
404Vec4 operator * (float inV1, Vec4Arg inV2)
405{
406#if defined(JPH_USE_SSE)
407 return _mm_mul_ps(_mm_set1_ps(inV1), inV2.mValue);
408#elif defined(JPH_USE_NEON)
409 return vmulq_n_f32(inV2.mValue, inV1);
410#else
411 return Vec4(inV1 * inV2.mF32[0],
412 inV1 * inV2.mF32[1],
413 inV1 * inV2.mF32[2],
414 inV1 * inV2.mF32[3]);
415#endif
416}
417
418Vec4 Vec4::operator / (float inV2) const
419{
420#if defined(JPH_USE_SSE)
421 return _mm_div_ps(mValue, _mm_set1_ps(inV2));
422#elif defined(JPH_USE_NEON)
423 return vdivq_f32(mValue, vdupq_n_f32(inV2));
424#else
425 return Vec4(mF32[0] / inV2, mF32[1] / inV2, mF32[2] / inV2, mF32[3] / inV2);
426#endif
427}
428
430{
431#if defined(JPH_USE_SSE)
432 mValue = _mm_mul_ps(mValue, _mm_set1_ps(inV2));
433#elif defined(JPH_USE_NEON)
434 mValue = vmulq_n_f32(mValue, inV2);
435#else
436 for (int i = 0; i < 4; ++i)
437 mF32[i] *= inV2;
438#endif
439 return *this;
440}
441
443{
444#if defined(JPH_USE_SSE)
445 mValue = _mm_mul_ps(mValue, inV2.mValue);
446#elif defined(JPH_USE_NEON)
447 mValue = vmulq_f32(mValue, inV2.mValue);
448#else
449 for (int i = 0; i < 4; ++i)
450 mF32[i] *= inV2.mF32[i];
451#endif
452 return *this;
453}
454
456{
457#if defined(JPH_USE_SSE)
458 mValue = _mm_div_ps(mValue, _mm_set1_ps(inV2));
459#elif defined(JPH_USE_NEON)
460 mValue = vdivq_f32(mValue, vdupq_n_f32(inV2));
461#else
462 for (int i = 0; i < 4; ++i)
463 mF32[i] /= inV2;
464#endif
465 return *this;
466}
467
469{
470#if defined(JPH_USE_SSE)
471 return _mm_add_ps(mValue, inV2.mValue);
472#elif defined(JPH_USE_NEON)
473 return vaddq_f32(mValue, inV2.mValue);
474#else
475 return Vec4(mF32[0] + inV2.mF32[0],
476 mF32[1] + inV2.mF32[1],
477 mF32[2] + inV2.mF32[2],
478 mF32[3] + inV2.mF32[3]);
479#endif
480}
481
483{
484#if defined(JPH_USE_SSE)
485 mValue = _mm_add_ps(mValue, inV2.mValue);
486#elif defined(JPH_USE_NEON)
487 mValue = vaddq_f32(mValue, inV2.mValue);
488#else
489 for (int i = 0; i < 4; ++i)
490 mF32[i] += inV2.mF32[i];
491#endif
492 return *this;
493}
494
496{
497#if defined(JPH_USE_SSE)
498 return _mm_sub_ps(_mm_setzero_ps(), mValue);
499#elif defined(JPH_USE_NEON)
500 return vnegq_f32(mValue);
501#else
502 return Vec4(-mF32[0], -mF32[1], -mF32[2], -mF32[3]);
503#endif
504}
505
507{
508#if defined(JPH_USE_SSE)
509 return _mm_sub_ps(mValue, inV2.mValue);
510#elif defined(JPH_USE_NEON)
511 return vsubq_f32(mValue, inV2.mValue);
512#else
513 return Vec4(mF32[0] - inV2.mF32[0],
514 mF32[1] - inV2.mF32[1],
515 mF32[2] - inV2.mF32[2],
516 mF32[3] - inV2.mF32[3]);
517#endif
518}
519
521{
522#if defined(JPH_USE_SSE)
523 mValue = _mm_sub_ps(mValue, inV2.mValue);
524#elif defined(JPH_USE_NEON)
525 mValue = vsubq_f32(mValue, inV2.mValue);
526#else
527 for (int i = 0; i < 4; ++i)
528 mF32[i] -= inV2.mF32[i];
529#endif
530 return *this;
531}
532
534{
535#if defined(JPH_USE_SSE)
536 return _mm_div_ps(mValue, inV2.mValue);
537#elif defined(JPH_USE_NEON)
538 return vdivq_f32(mValue, inV2.mValue);
539#else
540 return Vec4(mF32[0] / inV2.mF32[0],
541 mF32[1] / inV2.mF32[1],
542 mF32[2] / inV2.mF32[2],
543 mF32[3] / inV2.mF32[3]);
544#endif
545}
546
548{
549#if defined(JPH_USE_SSE)
550 return _mm_shuffle_ps(mValue, mValue, _MM_SHUFFLE(0, 0, 0, 0));
551#elif defined(JPH_USE_NEON)
552 return vdupq_laneq_f32(mValue, 0);
553#else
554 return Vec4(mF32[0], mF32[0], mF32[0], mF32[0]);
555#endif
556}
557
559{
560#if defined(JPH_USE_SSE)
561 return _mm_shuffle_ps(mValue, mValue, _MM_SHUFFLE(1, 1, 1, 1));
562#elif defined(JPH_USE_NEON)
563 return vdupq_laneq_f32(mValue, 1);
564#else
565 return Vec4(mF32[1], mF32[1], mF32[1], mF32[1]);
566#endif
567}
568
570{
571#if defined(JPH_USE_SSE)
572 return _mm_shuffle_ps(mValue, mValue, _MM_SHUFFLE(2, 2, 2, 2));
573#elif defined(JPH_USE_NEON)
574 return vdupq_laneq_f32(mValue, 2);
575#else
576 return Vec4(mF32[2], mF32[2], mF32[2], mF32[2]);
577#endif
578}
579
581{
582#if defined(JPH_USE_SSE)
583 return _mm_shuffle_ps(mValue, mValue, _MM_SHUFFLE(3, 3, 3, 3));
584#elif defined(JPH_USE_NEON)
585 return vdupq_laneq_f32(mValue, 3);
586#else
587 return Vec4(mF32[3], mF32[3], mF32[3], mF32[3]);
588#endif
589}
590
592{
593#if defined(JPH_USE_AVX512)
594 return _mm_range_ps(mValue, mValue, 0b1000);
595#elif defined(JPH_USE_SSE)
596 return _mm_max_ps(_mm_sub_ps(_mm_setzero_ps(), mValue), mValue);
597#elif defined(JPH_USE_NEON)
598 return vabsq_f32(mValue);
599#else
600 return Vec4(abs(mF32[0]), abs(mF32[1]), abs(mF32[2]), abs(mF32[3]));
601#endif
602}
603
605{
606 return sReplicate(1.0f) / mValue;
607}
608
610{
611#if defined(JPH_USE_SSE4_1)
612 return _mm_dp_ps(mValue, inV2.mValue, 0xff);
613#elif defined(JPH_USE_NEON)
614 float32x4_t mul = vmulq_f32(mValue, inV2.mValue);
615 return vdupq_n_f32(vaddvq_f32(mul));
616#else
617 float dot = 0.0f;
618 for (int i = 0; i < 4; i++)
619 dot += mF32[i] * inV2.mF32[i];
620 return Vec4::sReplicate(dot);
621#endif
622}
623
624float Vec4::Dot(Vec4Arg inV2) const
625{
626#if defined(JPH_USE_SSE4_1)
627 return _mm_cvtss_f32(_mm_dp_ps(mValue, inV2.mValue, 0xff));
628#elif defined(JPH_USE_NEON)
629 float32x4_t mul = vmulq_f32(mValue, inV2.mValue);
630 return vaddvq_f32(mul);
631#else
632 float dot = 0.0f;
633 for (int i = 0; i < 4; i++)
634 dot += mF32[i] * inV2.mF32[i];
635 return dot;
636#endif
637}
638
639float Vec4::LengthSq() const
640{
641#if defined(JPH_USE_SSE4_1)
642 return _mm_cvtss_f32(_mm_dp_ps(mValue, mValue, 0xff));
643#elif defined(JPH_USE_NEON)
644 float32x4_t mul = vmulq_f32(mValue, mValue);
645 return vaddvq_f32(mul);
646#else
647 float len_sq = 0.0f;
648 for (int i = 0; i < 4; i++)
649 len_sq += mF32[i] * mF32[i];
650 return len_sq;
651#endif
652}
653
654float Vec4::Length() const
655{
656#if defined(JPH_USE_SSE4_1)
657 return _mm_cvtss_f32(_mm_sqrt_ss(_mm_dp_ps(mValue, mValue, 0xff)));
658#elif defined(JPH_USE_NEON)
659 float32x4_t mul = vmulq_f32(mValue, mValue);
660 float32x2_t sum = vdup_n_f32(vaddvq_f32(mul));
661 return vget_lane_f32(vsqrt_f32(sum), 0);
662#else
663 return sqrt(LengthSq());
664#endif
665}
666
668{
669#if defined(JPH_USE_SSE)
670 return _mm_sqrt_ps(mValue);
671#elif defined(JPH_USE_NEON)
672 return vsqrtq_f32(mValue);
673#else
674 return Vec4(sqrt(mF32[0]), sqrt(mF32[1]), sqrt(mF32[2]), sqrt(mF32[3]));
675#endif
676}
677
678
680{
681#if defined(JPH_USE_AVX512)
682 return _mm_fixupimm_ps(mValue, mValue, _mm_set1_epi32(0xA9A90A00), 0);
683#elif defined(JPH_USE_SSE)
684 Type minus_one = _mm_set1_ps(-1.0f);
685 Type one = _mm_set1_ps(1.0f);
686 return _mm_or_ps(_mm_and_ps(mValue, minus_one), one);
687#elif defined(JPH_USE_NEON)
688 Type minus_one = vdupq_n_f32(-1.0f);
689 Type one = vdupq_n_f32(1.0f);
690 return vorrq_s32(vandq_s32(mValue, minus_one), one);
691#else
692 return Vec4(signbit(mF32[0])? -1.0f : 1.0f,
693 signbit(mF32[1])? -1.0f : 1.0f,
694 signbit(mF32[2])? -1.0f : 1.0f,
695 signbit(mF32[3])? -1.0f : 1.0f);
696#endif
697}
698
700{
701#if defined(JPH_USE_SSE4_1)
702 return _mm_div_ps(mValue, _mm_sqrt_ps(_mm_dp_ps(mValue, mValue, 0xff)));
703#elif defined(JPH_USE_NEON)
704 float32x4_t mul = vmulq_f32(mValue, mValue);
705 float32x4_t sum = vdupq_n_f32(vaddvq_f32(mul));
706 return vdivq_f32(mValue, vsqrtq_f32(sum));
707#else
708 return *this / Length();
709#endif
710}
711
712void Vec4::StoreFloat4(Float4 *outV) const
713{
714#if defined(JPH_USE_SSE)
715 _mm_storeu_ps(&outV->x, mValue);
716#elif defined(JPH_USE_NEON)
717 vst1q_f32(&outV->x, mValue);
718#else
719 for (int i = 0; i < 4; ++i)
720 (&outV->x)[i] = mF32[i];
721#endif
722}
723
725{
726#if defined(JPH_USE_SSE)
727 return _mm_cvttps_epi32(mValue);
728#elif defined(JPH_USE_NEON)
729 return vcvtq_u32_f32(mValue);
730#else
731 return UVec4(uint32(mF32[0]), uint32(mF32[1]), uint32(mF32[2]), uint32(mF32[3]));
732#endif
733}
734
736{
737#if defined(JPH_USE_SSE)
738 return UVec4(_mm_castps_si128(mValue));
739#elif defined(JPH_USE_NEON)
740 return vreinterpretq_u32_f32(mValue);
741#else
742 return *reinterpret_cast<const UVec4 *>(this);
743#endif
744}
745
747{
748#if defined(JPH_USE_SSE)
749 return _mm_movemask_ps(mValue);
750#elif defined(JPH_USE_NEON)
751 int32x4_t shift = JPH_NEON_INT32x4(0, 1, 2, 3);
752 return vaddvq_u32(vshlq_u32(vshrq_n_u32(vreinterpretq_u32_f32(mValue), 31), shift));
753#else
754 return (signbit(mF32[0])? 1 : 0) | (signbit(mF32[1])? 2 : 0) | (signbit(mF32[2])? 4 : 0) | (signbit(mF32[3])? 8 : 0);
755#endif
756}
757
758float Vec4::ReduceMin() const
759{
760 Vec4 v = sMin(mValue, Swizzle<SWIZZLE_Y, SWIZZLE_UNUSED, SWIZZLE_W, SWIZZLE_UNUSED>());
762 return v.GetX();
763}
764
765float Vec4::ReduceMax() const
766{
767 Vec4 v = sMax(mValue, Swizzle<SWIZZLE_Y, SWIZZLE_UNUSED, SWIZZLE_W, SWIZZLE_UNUSED>());
769 return v.GetX();
770}
771
772void Vec4::SinCos(Vec4 &outSin, Vec4 &outCos) const
773{
774 // Implementation based on sinf.c from the cephes library, combines sinf and cosf in a single function, changes octants to quadrants and vectorizes it
775 // Original implementation by Stephen L. Moshier (See: http://www.moshier.net/)
776
777 // Make argument positive and remember sign for sin only since cos is symmetric around x (highest bit of a float is the sign bit)
778 UVec4 sin_sign = UVec4::sAnd(ReinterpretAsInt(), UVec4::sReplicate(0x80000000U));
779 Vec4 x = Vec4::sXor(*this, sin_sign.ReinterpretAsFloat());
780
781 // x / (PI / 2) rounded to nearest int gives us the quadrant closest to x
782 UVec4 quadrant = (0.6366197723675814f * x + Vec4::sReplicate(0.5f)).ToInt();
783
784 // Make x relative to the closest quadrant.
785 // This does x = x - quadrant * PI / 2 using a two step Cody-Waite argument reduction.
786 // This improves the accuracy of the result by avoiding loss of significant bits in the subtraction.
787 // We start with x = x - quadrant * PI / 2, PI / 2 in hexadecimal notation is 0x3fc90fdb, we remove the lowest 16 bits to
788 // get 0x3fc90000 (= 1.5703125) this means we can now multiply with a number of up to 2^16 without losing any bits.
789 // This leaves us with: x = (x - quadrant * 1.5703125) - quadrant * (PI / 2 - 1.5703125).
790 // PI / 2 - 1.5703125 in hexadecimal is 0x39fdaa22, stripping the lowest 12 bits we get 0x39fda000 (= 0.0004837512969970703125)
791 // This leaves uw with: x = ((x - quadrant * 1.5703125) - quadrant * 0.0004837512969970703125) - quadrant * (PI / 2 - 1.5703125 - 0.0004837512969970703125)
792 // See: https://stackoverflow.com/questions/42455143/sine-cosine-modular-extended-precision-arithmetic
793 // After this we have x in the range [-PI / 4, PI / 4].
794 Vec4 float_quadrant = quadrant.ToFloat();
795 x = ((x - float_quadrant * 1.5703125f) - float_quadrant * 0.0004837512969970703125f) - float_quadrant * 7.549789948768648e-8f;
796
797 // Calculate x2 = x^2
798 Vec4 x2 = x * x;
799
800 // Taylor expansion:
801 // Cos(x) = 1 - x^2/2! + x^4/4! - x^6/6! + x^8/8! + ... = (((x2/8!- 1/6!) * x2 + 1/4!) * x2 - 1/2!) * x2 + 1
802 Vec4 taylor_cos = ((2.443315711809948e-5f * x2 - Vec4::sReplicate(1.388731625493765e-3f)) * x2 + Vec4::sReplicate(4.166664568298827e-2f)) * x2 * x2 - 0.5f * x2 + Vec4::sReplicate(1.0f);
803 // Sin(x) = x - x^3/3! + x^5/5! - x^7/7! + ... = ((-x2/7! + 1/5!) * x2 - 1/3!) * x2 * x + x
804 Vec4 taylor_sin = ((-1.9515295891e-4f * x2 + Vec4::sReplicate(8.3321608736e-3f)) * x2 - Vec4::sReplicate(1.6666654611e-1f)) * x2 * x + x;
805
806 // The lowest 2 bits of quadrant indicate the quadrant that we are in.
807 // Let x be the original input value and x' our value that has been mapped to the range [-PI / 4, PI / 4].
808 // since cos(x) = sin(x - PI / 2) and since we want to use the Taylor expansion as close as possible to 0,
809 // we can alternate between using the Taylor expansion for sin and cos according to the following table:
810 //
811 // quadrant sin(x) cos(x)
812 // XXX00b sin(x') cos(x')
813 // XXX01b cos(x') -sin(x')
814 // XXX10b -sin(x') -cos(x')
815 // XXX11b -cos(x') sin(x')
816 //
817 // So: sin_sign = bit2, cos_sign = bit1 ^ bit2, bit1 determines if we use sin or cos Taylor expansion
818 UVec4 bit1 = quadrant.LogicalShiftLeft<31>();
819 UVec4 bit2 = UVec4::sAnd(quadrant.LogicalShiftLeft<30>(), UVec4::sReplicate(0x80000000U));
820
821 // Select which one of the results is sin and which one is cos
822 Vec4 s = Vec4::sSelect(taylor_sin, taylor_cos, bit1);
823 Vec4 c = Vec4::sSelect(taylor_cos, taylor_sin, bit1);
824
825 // Update the signs
826 sin_sign = UVec4::sXor(sin_sign, bit2);
827 UVec4 cos_sign = UVec4::sXor(bit1, bit2);
828
829 // Correct the signs
830 outSin = Vec4::sXor(s, sin_sign.ReinterpretAsFloat());
831 outCos = Vec4::sXor(c, cos_sign.ReinterpretAsFloat());
832}
833
835{
836 // Implementation based on tanf.c from the cephes library, see Vec4::SinCos for further details
837 // Original implementation by Stephen L. Moshier (See: http://www.moshier.net/)
838
839 // Make argument positive
840 UVec4 tan_sign = UVec4::sAnd(ReinterpretAsInt(), UVec4::sReplicate(0x80000000U));
841 Vec4 x = Vec4::sXor(*this, tan_sign.ReinterpretAsFloat());
842
843 // x / (PI / 2) rounded to nearest int gives us the quadrant closest to x
844 UVec4 quadrant = (0.6366197723675814f * x + Vec4::sReplicate(0.5f)).ToInt();
845
846 // Remap x to range [-PI / 4, PI / 4], see Vec4::SinCos
847 Vec4 float_quadrant = quadrant.ToFloat();
848 x = ((x - float_quadrant * 1.5703125f) - float_quadrant * 0.0004837512969970703125f) - float_quadrant * 7.549789948768648e-8f;
849
850 // Calculate x2 = x^2
851 Vec4 x2 = x * x;
852
853 // Roughly equivalent to the Taylor expansion:
854 // Tan(x) = x + x^3/3 + 2*x^5/15 + 17*x^7/315 + 62*x^9/2835 + ...
855 Vec4 tan =
856 (((((9.38540185543e-3f * x2 + Vec4::sReplicate(3.11992232697e-3f)) * x2 + Vec4::sReplicate(2.44301354525e-2f)) * x2
857 + Vec4::sReplicate(5.34112807005e-2f)) * x2 + Vec4::sReplicate(1.33387994085e-1f)) * x2 + Vec4::sReplicate(3.33331568548e-1f)) * x2 * x + x;
858
859 // For the 2nd and 4th quadrant we need to invert the value
860 UVec4 bit1 = quadrant.LogicalShiftLeft<31>();
861 tan = Vec4::sSelect(tan, Vec4::sReplicate(-1.0f) / (tan JPH_IF_FLOATING_POINT_EXCEPTIONS_ENABLED(+ Vec4::sReplicate(FLT_MIN))), bit1); // Add small epsilon to prevent div by zero, works because tan is always positive
862
863 // Put the sign back
864 return Vec4::sXor(tan, tan_sign.ReinterpretAsFloat());
865}
866
868{
869 // Implementation based on asinf.c from the cephes library
870 // Original implementation by Stephen L. Moshier (See: http://www.moshier.net/)
871
872 // Make argument positive
873 UVec4 asin_sign = UVec4::sAnd(ReinterpretAsInt(), UVec4::sReplicate(0x80000000U));
874 Vec4 a = Vec4::sXor(*this, asin_sign.ReinterpretAsFloat());
875
876 // ASin is not defined outside the range [-1, 1] but it often happens that a value is slightly above 1 so we just clamp here
877 a = Vec4::sMin(a, Vec4::sReplicate(1.0f));
878
879 // When |x| <= 0.5 we use the asin approximation as is
880 Vec4 z1 = a * a;
881 Vec4 x1 = a;
882
883 // When |x| > 0.5 we use the identity asin(x) = PI / 2 - 2 * asin(sqrt((1 - x) / 2))
884 Vec4 z2 = 0.5f * (Vec4::sReplicate(1.0f) - a);
885 Vec4 x2 = z2.Sqrt();
886
887 // Select which of the two situations we have
888 UVec4 greater = Vec4::sGreater(a, Vec4::sReplicate(0.5f));
889 Vec4 z = Vec4::sSelect(z1, z2, greater);
890 Vec4 x = Vec4::sSelect(x1, x2, greater);
891
892 // Polynomial approximation of asin
893 z = ((((4.2163199048e-2f * z + Vec4::sReplicate(2.4181311049e-2f)) * z + Vec4::sReplicate(4.5470025998e-2f)) * z + Vec4::sReplicate(7.4953002686e-2f)) * z + Vec4::sReplicate(1.6666752422e-1f)) * z * x + x;
894
895 // If |x| > 0.5 we need to apply the remainder of the identity above
896 z = Vec4::sSelect(z, Vec4::sReplicate(0.5f * JPH_PI) - (z + z), greater);
897
898 // Put the sign back
899 return Vec4::sXor(z, asin_sign.ReinterpretAsFloat());
900}
901
903{
904 // Not the most accurate, but simple
905 return Vec4::sReplicate(0.5f * JPH_PI) - ASin();
906}
907
909{
910 // Implementation based on atanf.c from the cephes library
911 // Original implementation by Stephen L. Moshier (See: http://www.moshier.net/)
912
913 // Make argument positive
914 UVec4 atan_sign = UVec4::sAnd(ReinterpretAsInt(), UVec4::sReplicate(0x80000000U));
915 Vec4 x = Vec4::sXor(*this, atan_sign.ReinterpretAsFloat());
916 Vec4 y = Vec4::sZero();
917
918 // If x > Tan(PI / 8)
919 UVec4 greater1 = Vec4::sGreater(x, Vec4::sReplicate(0.4142135623730950f));
920 Vec4 x1 = (x - Vec4::sReplicate(1.0f)) / (x + Vec4::sReplicate(1.0f));
921
922 // If x > Tan(3 * PI / 8)
923 UVec4 greater2 = Vec4::sGreater(x, Vec4::sReplicate(2.414213562373095f));
924 Vec4 x2 = Vec4::sReplicate(-1.0f) / (x JPH_IF_FLOATING_POINT_EXCEPTIONS_ENABLED(+ Vec4::sReplicate(FLT_MIN))); // Add small epsilon to prevent div by zero, works because x is always positive
925
926 // Apply first if
927 x = Vec4::sSelect(x, x1, greater1);
928 y = Vec4::sSelect(y, Vec4::sReplicate(0.25f * JPH_PI), greater1);
929
930 // Apply second if
931 x = Vec4::sSelect(x, x2, greater2);
932 y = Vec4::sSelect(y, Vec4::sReplicate(0.5f * JPH_PI), greater2);
933
934 // Polynomial approximation
935 Vec4 z = x * x;
936 y += (((8.05374449538e-2f * z - Vec4::sReplicate(1.38776856032e-1f)) * z + Vec4::sReplicate(1.99777106478e-1f)) * z - Vec4::sReplicate(3.33329491539e-1f)) * z * x + x;
937
938 // Put the sign back
939 return Vec4::sXor(y, atan_sign.ReinterpretAsFloat());
940}
941
943{
944 UVec4 sign_mask = UVec4::sReplicate(0x80000000U);
945
946 // Determine absolute value and sign of y
947 UVec4 y_sign = UVec4::sAnd(inY.ReinterpretAsInt(), sign_mask);
948 Vec4 y_abs = Vec4::sXor(inY, y_sign.ReinterpretAsFloat());
949
950 // Determine absolute value and sign of x
951 UVec4 x_sign = UVec4::sAnd(inX.ReinterpretAsInt(), sign_mask);
952 Vec4 x_abs = Vec4::sXor(inX, x_sign.ReinterpretAsFloat());
953
954 // Always divide smallest / largest to avoid dividing by zero
955 UVec4 x_is_numerator = Vec4::sLess(x_abs, y_abs);
956 Vec4 numerator = Vec4::sSelect(y_abs, x_abs, x_is_numerator);
957 Vec4 denominator = Vec4::sSelect(x_abs, y_abs, x_is_numerator);
958 Vec4 atan = (numerator / denominator).ATan();
959
960 // If we calculated x / y instead of y / x the result is PI / 2 - result (note that this is true because we know the result is positive because the input was positive)
961 atan = Vec4::sSelect(atan, Vec4::sReplicate(0.5f * JPH_PI) - atan, x_is_numerator);
962
963 // Now we need to map to the correct quadrant
964 // x_sign y_sign result
965 // +1 +1 atan
966 // -1 +1 -atan + PI
967 // -1 -1 atan - PI
968 // +1 -1 -atan
969 // This can be written as: x_sign * y_sign * (atan - (x_sign < 0? PI : 0))
971 atan = Vec4::sXor(atan, UVec4::sXor(x_sign, y_sign).ReinterpretAsFloat());
972 return atan;
973}
974
uint32_t uint32
Definition Core.h:312
#define JPH_NAMESPACE_END
Definition Core.h:240
#define JPH_IF_FLOATING_POINT_EXCEPTIONS_ENABLED(...)
Definition Core.h:362
uint8_t uint8
Definition Core.h:310
uint64_t uint64
Definition Core.h:313
#define JPH_NAMESPACE_BEGIN
Definition Core.h:234
@ SWIZZLE_Z
Use the Z component.
Definition Swizzle.h:14
@ SWIZZLE_W
Use the W component.
Definition Swizzle.h:15
@ SWIZZLE_X
Use the X component.
Definition Swizzle.h:12
@ SWIZZLE_UNUSED
We always use the Z component when we don't specifically want to initialize a value,...
Definition Swizzle.h:16
@ SWIZZLE_Y
Use the Y component.
Definition Swizzle.h:13
Vec4 operator*(float inV1, Vec4Arg inV2)
Multiply vector with float.
Definition Vec4.inl:404
Class that holds 4 float values. Convert to Vec4 to perform calculations.
Definition Float4.h:11
float x
Definition Float4.h:25
float y
Definition Float4.h:26
float z
Definition Float4.h:27
float w
Definition Float4.h:28
Definition UVec4.h:12
JPH_INLINE UVec4 Swizzle() const
Swizzle the elements in inV.
JPH_INLINE uint32 GetZ() const
Definition UVec4.h:103
JPH_INLINE UVec4 LogicalShiftLeft() const
Shift all components by Count bits to the left (filling with zeros from the left)
JPH_INLINE uint32 GetY() const
Definition UVec4.h:102
static JPH_INLINE UVec4 sReplicate(uint32 inV)
Replicate int inV across all components.
Definition UVec4.inl:56
JPH_INLINE bool TestAllTrue() const
Test if all components are true (true is when highest bit of component is set)
Definition UVec4.inl:400
static JPH_INLINE UVec4 sAnd(UVec4Arg inV1, UVec4Arg inV2)
Logical and (component wise)
Definition UVec4.inl:194
static JPH_INLINE UVec4 sOr(UVec4Arg inV1, UVec4Arg inV2)
Logical or (component wise)
Definition UVec4.inl:166
JPH_INLINE uint32 GetW() const
Definition UVec4.h:104
Type mValue
Definition UVec4.h:210
JPH_INLINE uint32 GetX() const
Get individual components.
Definition UVec4.h:101
static JPH_INLINE UVec4 sXor(UVec4Arg inV1, UVec4Arg inV2)
Logical xor (component wise)
Definition UVec4.inl:180
JPH_INLINE UVec4 ArithmeticShiftRight() const
Shift all components by Count bits to the right (shifting in the value of the highest bit)
static JPH_INLINE UVec4 sSelect(UVec4Arg inV1, UVec4Arg inV2, UVec4Arg inControl)
Component wise select, returns inV1 when highest bit of inControl = 0 and inV2 when highest bit of in...
Definition UVec4.inl:152
JPH_INLINE Vec4 ToFloat() const
Convert each component from an int to a float.
Definition UVec4.inl:321
JPH_INLINE Vec4 ReinterpretAsFloat() const
Reinterpret UVec4 as a Vec4 (doesn't change the bits)
Definition UVec4.inl:332
uint32 mU32[4]
Definition UVec4.h:211
Definition Vec3.h:16
Type mValue
Definition Vec3.h:281
float mF32[4]
Definition Vec3.h:282
Definition Vec4.h:14
JPH_INLINE Vec4 SplatX() const
Replicate the X component to all components.
Definition Vec4.inl:547
static JPH_INLINE void sSort4(Vec4 &ioValue, UVec4 &ioIndex)
Definition Vec4.inl:301
Vec4 ATan() const
Calculate the arc tangent for each element of this vector (returns value in the range [-PI / 2,...
Definition Vec4.inl:908
static JPH_INLINE UVec4 sGreater(Vec4Arg inV1, Vec4Arg inV2)
Greater than (component wise)
Definition Vec4.inl:208
float mF32[4]
Definition Vec4.h:271
JPH_INLINE Vec4 operator-() const
Negate.
Definition Vec4.inl:495
Vec4()=default
Constructor.
static JPH_INLINE Vec4 sAnd(Vec4Arg inV1, Vec4Arg inV2)
Logical and (component wise)
Definition Vec4.inl:290
static JPH_INLINE Vec4 sLoadFloat4Aligned(const Float4 *inV)
Load 4 floats from memory, 16 bytes aligned.
Definition Vec4.inl:101
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:942
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:679
Vec4 ASin() const
Definition Vec4.inl:867
static JPH_INLINE Vec4 sXor(Vec4Arg inV1, Vec4Arg inV2)
Logical xor (component wise)
Definition Vec4.inl:279
JPH_INLINE Vec4 Abs() const
Return the absolute value of each of the components.
Definition Vec4.inl:591
JPH_INLINE Vec4 operator/(float inV2) const
Divide vector by float.
Definition Vec4.inl:418
Vec4 Tan() const
Calcluate the tangent for each element of this vector (input in radians)
Definition Vec4.inl:834
JPH_INLINE UVec4 ToInt() const
Convert each component from a float to an int.
Definition Vec4.inl:724
JPH_INLINE Vec4 & operator+=(Vec4Arg inV2)
Add two float vectors (component wise)
Definition Vec4.inl:482
static JPH_INLINE UVec4 sLessOrEqual(Vec4Arg inV1, Vec4Arg inV2)
Less than or equal (component wise)
Definition Vec4.inl:194
static JPH_INLINE UVec4 sLess(Vec4Arg inV1, Vec4Arg inV2)
Less than (component wise)
Definition Vec4.inl:180
JPH_INLINE float Length() const
Length of vector.
Definition Vec4.inl:654
static JPH_INLINE void sSort4Reverse(Vec4 &ioValue, UVec4 &ioIndex)
Definition Vec4.inl:325
static JPH_INLINE Vec4 sFusedMultiplyAdd(Vec4Arg inMul1, Vec4Arg inMul2, Vec4Arg inAdd)
Calculates inMul1 * inMul2 + inAdd.
Definition Vec4.inl:236
JPH_INLINE Vec4 Normalized() const
Normalize vector.
Definition Vec4.inl:699
static JPH_INLINE UVec4 sEquals(Vec4Arg inV1, Vec4Arg inV2)
Equals (component wise)
Definition Vec4.inl:166
static JPH_INLINE Vec4 sSelect(Vec4Arg inV1, Vec4Arg inV2, UVec4Arg inControl)
Component wise select, returns inV1 when highest bit of inControl = 0 and inV2 when highest bit of in...
Definition Vec4.inl:254
JPH_INLINE float ReduceMax() const
Get the maximum of X, Y, Z and W.
Definition Vec4.inl:765
JPH_INLINE Vec4 Reciprocal() const
Reciprocal vector (1 / value) for each of the components.
Definition Vec4.inl:604
JPH_INLINE Vec4 SplatY() const
Replicate the Y component to all components.
Definition Vec4.inl:558
JPH_INLINE UVec4 ReinterpretAsInt() const
Reinterpret Vec4 as a UVec4 (doesn't change the bits)
Definition Vec4.inl:735
static JPH_INLINE UVec4 sGreaterOrEqual(Vec4Arg inV1, Vec4Arg inV2)
Greater than or equal (component wise)
Definition Vec4.inl:222
static JPH_INLINE Vec4 sMin(Vec4Arg inV1, Vec4Arg inV2)
Return the minimum value of each of the components.
Definition Vec4.inl:138
JPH_INLINE Vec4 SplatZ() const
Replicate the Z component to all components.
Definition Vec4.inl:569
JPH_INLINE Vec4 Sqrt() const
Component wise square root.
Definition Vec4.inl:667
JPH_INLINE Vec4 & operator*=(float inV2)
Multiply vector with float.
Definition Vec4.inl:429
static JPH_INLINE Vec4 sGatherFloat4(const float *inBase, UVec4Arg inOffsets)
Gather 4 floats from memory at inBase + inOffsets[i] * Scale.
JPH_INLINE Vec4 operator+(Vec4Arg inV2) const
Add two float vectors (component wise)
Definition Vec4.inl:468
JPH_INLINE Vec4 & operator/=(float inV2)
Divide vector by float.
Definition Vec4.inl:455
JPH_INLINE bool IsNormalized(float inTolerance=1.0e-6f) const
Test if vector is normalized.
Definition Vec4.inl:359
JPH_INLINE bool operator==(Vec4Arg inV2) const
Comparison.
Definition Vec4.inl:349
JPH_INLINE Vec4 SplatW() const
Replicate the W component to all components.
Definition Vec4.inl:580
JPH_INLINE Vec4 DotV(Vec4Arg inV2) const
Dot product, returns the dot product in X, Y and Z components.
Definition Vec4.inl:609
JPH_INLINE bool IsClose(Vec4Arg inV2, float inMaxDistSq=1.0e-12f) const
Test if two vectors are close.
Definition Vec4.inl:354
JPH_INLINE float GetX() const
Get individual components.
Definition Vec4.h:112
static JPH_INLINE Vec4 sLoadFloat4(const Float4 *inV)
Load 4 floats from memory.
Definition Vec4.inl:90
static JPH_INLINE Vec4 sZero()
Vector with all zeros.
Definition Vec4.inl:63
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:268
JPH_INLINE float ReduceMin() const
Get the minimum of X, Y, Z and W.
Definition Vec4.inl:758
Type mValue
Definition Vec4.h:270
JPH_INLINE Vec4 & operator-=(Vec4Arg inV2)
Add two float vectors (component wise)
Definition Vec4.inl:520
JPH_INLINE float LengthSq() const
Squared length of vector.
Definition Vec4.inl:639
static JPH_INLINE Vec4 sMax(Vec4Arg inV1, Vec4Arg inV2)
Return the maximum of each of the components.
Definition Vec4.inl:152
JPH_INLINE float Dot(Vec4Arg inV2) const
Dot product.
Definition Vec4.inl:624
JPH_INLINE bool IsNaN() const
Test if vector contains NaN elements.
Definition Vec4.inl:364
static JPH_INLINE Vec4 sNaN()
Vector with all NaN's.
Definition Vec4.inl:85
Vec4 ACos() const
Definition Vec4.inl:902
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:746
static JPH_INLINE Vec4 sReplicate(float inV)
Replicate inV across all components.
Definition Vec4.inl:74
void SinCos(Vec4 &outSin, Vec4 &outCos) const
Calcluate the sine and cosine for each element of this vector (input in radians)
Definition Vec4.inl:772
JPH_INLINE void StoreFloat4(Float4 *outV) const
Store 4 floats to memory.
Definition Vec4.inl:712
friend JPH_INLINE Vec4 operator*(float inV1, Vec4Arg inV2)
Multiply vector with float.
Definition Vec4.inl:404