Nebula
Loading...
Searching...
No Matches
vec3.h
Go to the documentation of this file.
1#pragma once
2//------------------------------------------------------------------------------
16#include "core/types.h"
17#include "math/scalar.h"
18#include "core/simd.h"
19
20//------------------------------------------------------------------------------
21namespace Math
22{
23struct mat4;
24struct vec3;
25
26static const f32x4 _id_x = set_f32x4(1.0f, 0.0f, 0.0f, 0.0f);
27static const f32x4 _id_y = set_f32x4(0.0f, 1.0f, 0.0f, 0.0f);
28static const f32x4 _id_z = set_f32x4(0.0f, 0.0f, 1.0f, 0.0f);
29static const f32x4 _id_w = set_f32x4(0.0f, 0.0f, 0.0f, 1.0f);
30static const f32x4 _minus1 = set_f32x4(-1.0f, -1.0f, -1.0f, -1.0f);
31static const f32x4 _plus1 = set_f32x4(1.0f, 1.0f, 1.0f, 1.0f);
32static const f32x4 _zero = set_f32x4(0.0f, 0.0f, 0.0f, 0.0f);
33static const i32x4 _sign = set_i32x4(0x80000000, 0x80000000, 0x80000000, 0x80000000);
34static const f32x4 _mask_xyz = cast_i32x4_to_f32x4(set_i32x4( 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0 ));
35
37{
38public:
40 vec3() = default;
42 vec3(scalar x, scalar y, scalar z);
44 vec3(float3 f3);
46 explicit vec3(scalar v);
48 vec3(const vec3& rhs) = default;
50 vec3(const f32x4& rhs);
51
53 void operator=(const f32x4& rhs);
55 void operator+=(const vec3& rhs);
57 void operator-=(const vec3& rhs);
59 void operator*=(scalar s);
61 void operator*=(const vec3& rhs);
63 void operator/=(const vec3& rhs);
65 bool operator==(const vec3& rhs) const;
67 bool operator!=(const vec3& rhs) const;
68
70 void load(const scalar* ptr);
72 void loadu(const scalar* ptr);
74 void store(scalar* ptr) const;
76 void storeu(scalar* ptr) const;
78 void stream(scalar* ptr) const;
79
81 void set(scalar x, scalar y, scalar z);
82
84 scalar& operator[](const int index);
86 scalar operator[](const int index) const;
87
88 union
89 {
90 struct
91 {
92 // we can access __w to check it, but we don't actually use it
93 float x, y, z, __w;
94 };
95 f32x4 vec;
96 float v[3];
97 };
98};
99
100//------------------------------------------------------------------------------
103__forceinline
105{
106 this->vec = set_f32x4(x, y, z, 0);
107}
108
109//------------------------------------------------------------------------------
112__forceinline
114{
115 this->vec = _mm_setr_ps(f3.x, f3.y, f3.z, 0);
116}
117
118//------------------------------------------------------------------------------
121__forceinline
123{
124 this->vec = set_f32x4(v, v, v, 0.0f);
125}
126
127//------------------------------------------------------------------------------
130__forceinline
131vec3::vec3(const f32x4& rhs)
132{
133 this->vec = set_last_f32x4(rhs, 0);
134}
135
136//------------------------------------------------------------------------------
139__forceinline void
140vec3::operator=(const f32x4& rhs)
141{
142 this->vec = set_last_f32x4(rhs, 0);
143}
144
145//------------------------------------------------------------------------------
148__forceinline bool
149vec3::operator==(const vec3& rhs) const
150{
151 return (((_mm_movemask_ps(_mm_cmpeq_ps(this->vec, rhs.vec)) & 7) == 7) != 0);
152}
153
154//------------------------------------------------------------------------------
157__forceinline bool
158vec3::operator!=(const vec3 &rhs) const
159{
160 return !(((_mm_movemask_ps(_mm_cmpeq_ps(this->vec, rhs.vec)) & 7) == 7) != 0);
161}
162
163//------------------------------------------------------------------------------
167__forceinline void
169{
170 this->vec = load_aligned_f32x3(ptr);
171}
172
173//------------------------------------------------------------------------------
177__forceinline void
179{
180 this->vec = load_unaligned_f32x3(ptr);
181}
182
183//------------------------------------------------------------------------------
187__forceinline void
189{
190 store_f32x3(this->vec, ptr);
191}
192
193//------------------------------------------------------------------------------
197__forceinline void
199{
200 store_f32x3(this->vec, ptr);
201}
202
203//------------------------------------------------------------------------------
206__forceinline void
208{
209 this->store(ptr);
210}
211
212//------------------------------------------------------------------------------
215__forceinline vec3
216operator-(const vec3& lhs)
217{
218 return vec3(flip_sign_f32x4(lhs.vec));
219}
220
221//------------------------------------------------------------------------------
225__forceinline vec3
226operator*(const vec3& lhs, scalar t)
227{
228 f32x4 temp = _mm_set1_ps(t);
229 return mul_f32x4(lhs.vec, temp);
230}
231
232//------------------------------------------------------------------------------
236__forceinline vec3
237operator*(const vec3& lhs, const vec3& rhs)
238{
239 return mul_f32x4(lhs.vec, rhs.vec);
240}
241
242//------------------------------------------------------------------------------
246__forceinline vec3
247operator/(const vec3& lhs, scalar t)
248{
249 __m128 temp = _mm_set1_ps(t);
250 return _mm_div_ps(lhs.vec, temp);
251}
252
253//------------------------------------------------------------------------------
256__forceinline void
258{
259 this->vec = mul_f32x4(this->vec, rhs.vec);
260}
261
262//------------------------------------------------------------------------------
265__forceinline void
267{
268 this->vec = div_f32x4(this->vec, rhs.vec);
269}
270
271//------------------------------------------------------------------------------
274__forceinline void
276{
277 this->vec = add_f32x4(this->vec, rhs.vec);
278}
279
280//------------------------------------------------------------------------------
283__forceinline void
285{
286 this->vec = sub_f32x4(this->vec, rhs.vec);
287}
288
289//------------------------------------------------------------------------------
292__forceinline void
294{
295 f32x4 temp = splat_f32x4(s);
296 this->vec = mul_f32x4(this->vec, temp);
297}
298
299//------------------------------------------------------------------------------
302__forceinline vec3
303operator+(const vec3& lhs, const vec3 &rhs)
304{
305 return add_f32x4(lhs.vec, rhs.vec);
306}
307
308//------------------------------------------------------------------------------
311__forceinline vec3
312operator-(const vec3& lhs, const vec3& rhs)
313{
314 return sub_f32x4(lhs.vec, rhs.vec);
315}
316
317//------------------------------------------------------------------------------
320__forceinline void
322{
323 this->vec = set_f32x4(x, y, z, 0);
324}
325
326//------------------------------------------------------------------------------
329__forceinline scalar&
330vec3::operator[]( const int index )
331{
332 n_assert(index < 3);
333 return this->v[index];
334}
335
336//------------------------------------------------------------------------------
339__forceinline scalar
340vec3::operator[](const int index) const
341{
342 n_assert(index < 3);
343 return this->v[index];
344}
345
346//------------------------------------------------------------------------------
349__forceinline scalar
350length(const vec3& v)
351{
352 scalar dot = dot_f32x3(v.vec, v.vec);
353 return sqrt(dot);
354}
355
356//------------------------------------------------------------------------------
359__forceinline scalar
360lengthsq(const vec3& v)
361{
362 return dot_f32x3(v.vec, v.vec);
363}
364
365//------------------------------------------------------------------------------
368__forceinline vec3
370{
371 return div_f32x4(_plus1, v.vec);
372}
373
374//------------------------------------------------------------------------------
377__forceinline vec3
379{
380 return rcp_f32x4(v.vec);
381}
382
383//------------------------------------------------------------------------------
386__forceinline vec3
387multiply(const vec3& v0, const vec3& v1)
388{
389 return mul_f32x4(v0.vec, v1.vec);
390}
391
392//------------------------------------------------------------------------------
395__forceinline vec3
396multiplyadd( const vec3& v0, const vec3& v1, const vec3& v2 )
397{
398 return fma_f32x4(v0.vec, v1.vec, v2.vec);
399}
400
401//------------------------------------------------------------------------------
404__forceinline vec3
405divide(const vec3& v0, const vec3& v1)
406{
407 return div_f32x4(v0.vec, v1.vec);
408}
409
410//------------------------------------------------------------------------------
413__forceinline vec3
414abs(const vec3& v)
415{
416 return abs_f32x4(v.vec);
417}
418
419//------------------------------------------------------------------------------
422__forceinline vec3
423cross(const vec3& v0, const vec3& v1)
424{
425 f32x4 tmp0, tmp1, tmp2, tmp3, result;
426 tmp0 = shuffle_f32x4( v0.vec, v0.vec, 3,0,2,1 );
427 tmp1 = shuffle_f32x4( v1.vec, v1.vec, 3,1,0,2 );
428 tmp2 = shuffle_f32x4( v0.vec, v0.vec, 3,1,0,2 );
429 tmp3 = shuffle_f32x4( v1.vec, v1.vec, 3,0,2,1 );
430 result = mul_f32x4( tmp0, tmp1 );
431 result = sub_f32x4( result, mul_f32x4( tmp2, tmp3 ) );
432 return result;
433}
434
435//------------------------------------------------------------------------------
438__forceinline scalar
439dot(const vec3& v0, const vec3& v1)
440{
441 return dot_f32x3(v0.vec, v1.vec);
442}
443
444//------------------------------------------------------------------------------
448__forceinline vec3
449barycentric(const vec3& v0, const vec3 &v1, const vec3 &v2, scalar f, scalar g)
450{
451 f32x4 R1 = sub_f32x4(v1.vec,v0.vec);
452 f32x4 SF = splat_f32x4(f);
453 f32x4 R2 = sub_f32x4(v2.vec,v0.vec);
454 f32x4 SG = splat_f32x4(g);
455 R1 = mul_f32x4(R1,SF);
456 R2 = mul_f32x4(R2,SG);
457 R1 = add_f32x4(R1,v0.vec);
458 R1 = add_f32x4(R1,R2);
459 return R1;
460}
461
462//------------------------------------------------------------------------------
465__forceinline vec3
466catmullrom(const vec3& v0, const vec3& v1, const vec3& v2, const vec3& v3, scalar s)
467{
468 scalar s2 = s * s;
469 scalar s3 = s * s2;
470
471 f32x4 P0 = splat_f32x4((-s3 + 2.0f * s2 - s) * 0.5f);
472 f32x4 P1 = splat_f32x4((3.0f * s3 - 5.0f * s2 + 2.0f) * 0.5f);
473 f32x4 P2 = splat_f32x4((-3.0f * s3 + 4.0f * s2 + s) * 0.5f);
474 f32x4 P3 = splat_f32x4((s3 - s2) * 0.5f);
475
476 P0 = mul_f32x4(P0, v0.vec);
477 P1 = mul_f32x4(P1, v1.vec);
478 P2 = mul_f32x4(P2, v2.vec);
479 P3 = mul_f32x4(P3, v3.vec);
480 P0 = add_f32x4(P0,P1);
481 P2 = add_f32x4(P2,P3);
482 P0 = add_f32x4(P0,P2);
483 return P0;
484}
485
486//------------------------------------------------------------------------------
489__forceinline vec3
490hermite(const vec3& v1, const vec3& t1, const vec3& v2, const vec3& t2, scalar s)
491{
492 scalar s2 = s * s;
493 scalar s3 = s * s2;
494
495 f32x4 P0 = splat_f32x4(2.0f * s3 - 3.0f * s2 + 1.0f);
496 f32x4 T0 = splat_f32x4(s3 - 2.0f * s2 + s);
497 f32x4 P1 = splat_f32x4(-2.0f * s3 + 3.0f * s2);
498 f32x4 T1 = splat_f32x4(s3 - s2);
499
500 f32x4 vResult = mul_f32x4(P0, v1.vec);
501 f32x4 vTemp = mul_f32x4(T0, t1.vec);
502 vResult = add_f32x4(vResult,vTemp);
503 vTemp = mul_f32x4(P1, v2.vec);
504 vResult = add_f32x4(vResult,vTemp);
505 vTemp = mul_f32x4(T1, t2.vec);
506 vResult = add_f32x4(vResult,vTemp);
507 return vResult;
508}
509
510//------------------------------------------------------------------------------
513__forceinline scalar
514angle(const vec3& v0, const vec3& v1)
515{
516 f32x4 l0 = mul_f32x4(v0.vec, v0.vec);
517 l0 = add_f32x4(shuffle_f32x4(l0, l0, 0, 0, 0, 0),
518 add_f32x4(shuffle_f32x4(l0, l0, 1, 1, 1, 1), shuffle_f32x4(l0, l0, 2, 2, 2, 2)));
519
520 f32x4 l1 = mul_f32x4(v1.vec, v1.vec);
521 l1 = add_f32x4(shuffle_f32x4(l1, l1, 0, 0, 0, 0),
522 add_f32x4(shuffle_f32x4(l1, l1, 1, 1, 1, 1), shuffle_f32x4(l1, l1, 2, 2, 2, 2)));
523
524 f32x4 l = shuffle_f32x4(l0, l1, 0, 0, 0, 0);
525 l = rsqrt_f32x4(l);
526 l = mul_first_f32x4(shuffle_f32x4(l, l, 0, 0, 0, 0), shuffle_f32x4(l, l, 1, 1, 1, 1));
527
528
529 f32x4 dot = mul_f32x4(v0.vec, v1.vec);
530 dot = add_f32x4(shuffle_f32x4(dot, dot, 0, 0, 0, 0),
531 add_f32x4(shuffle_f32x4(dot, dot, 1, 1, 1, 1),
532 add_f32x4(shuffle_f32x4(dot, dot, 2, 2, 2, 2), shuffle_f32x4(dot, dot, 3, 3, 3, 3))));
533
534 dot = mul_first_f32x4(dot, l);
535
536 dot = max_first_f32x4(dot, _minus1);
537 dot = min_first_f32x4(dot, _plus1);
538
539 scalar cangle;
540 store_f32(dot, &cangle);
541 return acos(cangle);
542}
543
544//------------------------------------------------------------------------------
547__forceinline vec3
548lerp(const vec3& v0, const vec3& v1, scalar s)
549{
550 return fma_f32x4(sub_f32x4(v1.vec, v0.vec), splat_f32x4(s), v0.vec);
551}
552
553//------------------------------------------------------------------------------
556__forceinline vec3
557maximize(const vec3& v0, const vec3& v1)
558{
559 return max_f32x4(v0.vec, v1.vec);
560}
561
562//------------------------------------------------------------------------------
565__forceinline vec3
566minimize(const vec3& v0, const vec3& v1)
567{
568 return min_f32x4(v0.vec, v1.vec);
569}
570
571//------------------------------------------------------------------------------
574__forceinline vec3
575clamp(const vec3& clamp, const vec3& min, const vec3& max)
576{
577 f32x4 temp = max_f32x4(min.vec, clamp.vec);
578 temp = min_f32x4(temp, max.vec);
579 return vec3(temp);
580}
581
582//------------------------------------------------------------------------------
585__forceinline vec3
587{
588 if (v == vec3(0)) return v;
589
590 f32x4 t = div_f32x4(v.vec, splat_f32x4(sqrt(dot_f32x3(v.vec, v.vec))));
591 return vec3(t);
592}
593
594//------------------------------------------------------------------------------
597__forceinline vec3
599{
600 if (v == vec3(0)) return v;
601 f32x4 t = splat_f32x4(1.0f / sqrt(dot_f32x3(v.vec, v.vec)));
602 return mul_f32x4(v.vec, set_last_f32x4(t, 0));
603}
604
605//------------------------------------------------------------------------------
608__forceinline vec3
609reflect(const vec3& normal, const vec3& incident)
610{
611 f32x4 res = mul_f32x4(incident.vec, normal.vec);
612 res = add_f32x4(shuffle_f32x4(res, res, 0, 0, 0, 0),
613 add_f32x4(shuffle_f32x4(res, res, 1, 1, 1, 1), shuffle_f32x4(res, res, 2, 2, 2, 2)));
614 res = add_f32x4(res, res);
615 res = mul_f32x4(res, normal.vec);
616 res = sub_f32x4(incident.vec,res);
617 return res;
618}
619
620//------------------------------------------------------------------------------
623__forceinline bool
624less_any(const vec3& v0, const vec3& v1)
625{
626 __m128 vTemp = _mm_cmpge_ps(v0.vec, v1.vec);
627 int res = _mm_movemask_ps(vTemp) & 0x7;
628 return res != 0x7;
629}
630
631//------------------------------------------------------------------------------
634__forceinline bool
635less_all(const vec3& v0, const vec3& v1)
636{
637 __m128 vTemp = _mm_cmpge_ps(v0.vec, v1.vec);
638 int res = _mm_movemask_ps(vTemp) & 0x7;
639 return res == 0;
640}
641
642//------------------------------------------------------------------------------
645__forceinline bool
646lessequal_any(const vec3& v0, const vec3& v1)
647{
648 __m128 vTemp = _mm_cmpgt_ps(v0.vec, v1.vec);
649 int res = _mm_movemask_ps(vTemp) & 7;
650 return res != 0x7;
651}
652
653//------------------------------------------------------------------------------
656__forceinline bool
657lessequal_all(const vec3& v0, const vec3& v1)
658{
659 __m128 vTemp = _mm_cmpgt_ps(v0.vec, v1.vec);
660 int res = _mm_movemask_ps(vTemp) & 0x7;
661 return res == 0;
662}
663
664//------------------------------------------------------------------------------
667__forceinline bool
668greater_any(const vec3& v0, const vec3& v1)
669{
670 __m128 vTemp = _mm_cmpgt_ps(v0.vec, v1.vec);
671 int res = _mm_movemask_ps(vTemp) & 0x7;
672 return res != 0;
673}
674
675//------------------------------------------------------------------------------
678__forceinline bool
679greater_all(const vec3& v0, const vec3& v1)
680{
681 __m128 vTemp = _mm_cmpgt_ps(v0.vec, v1.vec);
682 int res = _mm_movemask_ps(vTemp) & 0x7;
683 return res == 0x7;
684}
685
686//------------------------------------------------------------------------------
689__forceinline bool
690greaterequal_any(const vec3& v0, const vec3& v1)
691{
692 __m128 vTemp = _mm_cmpge_ps(v0.vec, v1.vec);
693 int res = _mm_movemask_ps(vTemp) & 0x7;
694 return res != 0;
695}
696
697//------------------------------------------------------------------------------
700__forceinline bool
701greaterequal_all(const vec3& v0, const vec3& v1)
702{
703 __m128 vTemp = _mm_cmpge_ps(v0.vec, v1.vec);
704 int res = _mm_movemask_ps(vTemp) & 0x7;
705 return res == 0x7;
706}
707
708//------------------------------------------------------------------------------
711__forceinline bool
712equal_any(const vec3& v0, const vec3& v1)
713{
714 __m128 vTemp = _mm_cmpeq_ps(v0.vec, v1.vec);
715 int res = _mm_movemask_ps(vTemp) & 0x7;
716 return res != 0;
717}
718
719//------------------------------------------------------------------------------
722__forceinline bool
723nearequal(const vec3& v0, const vec3& v1, float epsilon)
724{
725 __m128 eps = _mm_setr_ps(epsilon, epsilon, epsilon, 0);
726 __m128 delta = _mm_sub_ps(v0.vec, v1.vec);
727 __m128 temp = _mm_setzero_ps();
728 temp = _mm_sub_ps(temp, delta);
729 temp = _mm_max_ps(temp, delta);
730 temp = _mm_cmple_ps(temp, eps);
731 return (_mm_movemask_ps(temp) & 0x7) != 0;
732}
733
734//------------------------------------------------------------------------------
737__forceinline bool
738nearequal(const vec3& v0, const vec3& v1, const vec3& epsilon)
739{
740 __m128 delta = _mm_sub_ps(v0.vec, v1.vec);
741 __m128 temp = _mm_setzero_ps();
742 temp = _mm_sub_ps(temp, delta);
743 temp = _mm_max_ps(temp, delta);
744 temp = _mm_cmple_ps(temp, epsilon.vec);
745 auto foo = _mm_movemask_ps(temp) & 0x7;
746 return (_mm_movemask_ps(temp) & 0x7) == 0x7;
747}
748
749//------------------------------------------------------------------------------
752__forceinline vec3
753less(const vec3& v0, const vec3& v1)
754{
755 return _mm_min_ps(_mm_cmplt_ps(v0.vec, v1.vec), _plus1);
756}
757
758//------------------------------------------------------------------------------
761__forceinline vec3
762greater(const vec3& v0, const vec3& v1)
763{
764 return _mm_min_ps(_mm_cmpgt_ps(v0.vec, v1.vec), _plus1);
765}
766
767//------------------------------------------------------------------------------
770__forceinline vec3
771equal(const vec3& v0, const vec3& v1)
772{
773 return _mm_min_ps(_mm_cmpeq_ps(v0.vec, v1.vec), _plus1);
774}
775
776//------------------------------------------------------------------------------
779__forceinline vec3
780splat(const vec3& v, uint element)
781{
782 n_assert(element < 3 && element >= 0);
783
784 f32x4 res;
785 switch (element)
786 {
787 case 0:
788 res = shuffle_f32x4(v.vec, v.vec, 0, 0, 0, 0);
789 break;
790 case 1:
791 res = shuffle_f32x4(v.vec, v.vec, 1, 1, 1, 1);
792 break;
793 case 2:
794 res = shuffle_f32x4(v.vec, v.vec, 2, 2, 2, 2);
795 break;
796 }
797 return set_last_f32x4(res, 0);
798}
799
800//------------------------------------------------------------------------------
803__forceinline vec3
804splat_x(const vec3& v)
805{
806 f32x4 res = shuffle_f32x4(v.vec, v.vec, 0, 0, 0, 0);
807 return set_last_f32x4(res, 0);
808}
809
810//------------------------------------------------------------------------------
813__forceinline vec3
814splat_y(const vec3& v)
815{
816 f32x4 res = shuffle_f32x4(v.vec, v.vec, 1, 1, 1, 1);
817 return set_last_f32x4(res, 0);
818}
819
820//------------------------------------------------------------------------------
823__forceinline vec3
824splat_z(const vec3& v)
825{
826 f32x4 res = shuffle_f32x4(v.vec, v.vec, 2, 2, 2, 2);
827 return set_last_f32x4(res, 0);
828}
829
830//------------------------------------------------------------------------------
833__forceinline vec3
834permute(const vec3& v0, const vec3& v1, unsigned int i0, unsigned int i1, unsigned int i2)
835{
836 static i32x4 three = _mm_set_epi32(3,3,3,3);
837
838 NEBULA_ALIGN16 unsigned int elem[4] = { i0, i1, i2, 7 };
839 i32x4 vControl = _mm_load_si128(reinterpret_cast<const __m128i*>(&elem[0]));
840
841 i32x4 vSelect = _mm_cmpgt_epi32(vControl, three);
842 vControl = _mm_and_si128(vControl, three);
843
844 f32x4 shuffled1 = _mm_permutevar_ps(v0.vec, vControl);
845 f32x4 shuffled2 = _mm_permutevar_ps(v1.vec, vControl);
846
847 f32x4 masked1 = _mm_andnot_ps(_mm_castsi128_ps(vSelect), shuffled1);
848 f32x4 masked2 = _mm_and_ps(_mm_castsi128_ps(vSelect), shuffled2);
849
850 return _mm_or_ps(masked1, masked2);
851}
852
853//------------------------------------------------------------------------------
856__forceinline vec3
857select(const vec3& v0, const vec3& v1, const uint i0, const uint i1, const uint i2)
858{
859 //FIXME this should be converted to something similar as XMVectorSelect
860 return permute(v0, v1, i0, i1, i2);
861}
862
863//------------------------------------------------------------------------------
866__forceinline vec3
867select(const vec3& v0, const vec3& v1, const vec3& control)
868{
869 f32x4 v0masked = _mm_andnot_ps(control.vec, v0.vec);
870 f32x4 v1masked = _mm_and_ps(v1.vec, control.vec);
871 return _mm_or_ps(v0masked, v1masked);
872}
873
874//------------------------------------------------------------------------------
877__forceinline vec3
878floor(const vec3& v)
879{
880 return _mm_floor_ps(v.vec);
881}
882
883//------------------------------------------------------------------------------
886__forceinline vec3
887ceiling(const vec3& v)
888{
889 return _mm_ceil_ps(v.vec);
890}
891
892} // namespace Math
893//------------------------------------------------------------------------------
894
895
896
897
898
899
900
901
#define n_assert(exp)
Definition debug.h:50
Different curves.
Definition angularpfeedbackloop.h:17
__forceinline point less(const point &v0, const point &v1)
Definition point.h:501
static const f32x4 _zero
Definition vec3.h:32
static const f32x4 _plus1
Definition vec3.h:31
__forceinline vec3 cross(const vec3 &v0, const vec3 &v1)
Definition vec3.h:423
__forceinline point maximize(const point &v0, const point &v1)
Definition point.h:368
static const f32x4 _id_w
Definition vec3.h:29
__forceinline quat barycentric(const quat &q0, const quat &q1, const quat &q2, scalar f, scalar g)
Definition quat.h:296
__forceinline bool equal_any(const point &v0, const point &v1)
Definition point.h:474
__forceinline bool greaterequal_any(const point &v0, const point &v1)
Definition point.h:452
__forceinline vec3 ceiling(const vec3 &v)
Definition vec3.h:887
__forceinline vec3 splat_z(const vec3 &v)
Definition vec3.h:824
__forceinline vec3 hermite(const vec3 &v1, const vec3 &t1, const vec3 &v2, const vec3 &t2, scalar s)
Definition vec3.h:490
__forceinline scalar sqrt(scalar x)
Definition scalar.h:236
__forceinline point equal(const point &v0, const point &v1)
Definition point.h:519
__forceinline vec3 splat_x(const vec3 &v)
Definition vec3.h:804
__forceinline vec3 splat(const vec3 &v, uint element)
Definition vec3.h:780
mat4 reflect(const vec4 &p)
based on this http://www.opengl.org/discussion_boards/showthread.php/169605-reflection-matrix-how-to-...
Definition mat4.cc:22
__forceinline vec3 multiply(const vec3 &v0, const vec3 &v1)
Definition vec3.h:387
__forceinline scalar angle(const vec3 &v0, const vec3 &v1)
Definition vec3.h:514
__forceinline vec3 divide(const vec3 &v0, const vec3 &v1)
Definition vec3.h:405
__forceinline vec3 reciprocal(const vec3 &v)
Definition vec3.h:369
__forceinline scalar length(const quat &q)
Definition quat.h:260
half operator/(half one, half two)
Definition half.h:132
__forceinline scalar lengthsq(const quat &q)
Definition quat.h:269
__forceinline scalar dot(const plane &p, const vec4 &v1)
Definition plane.h:252
__forceinline vec3 permute(const vec3 &v0, const vec3 &v1, unsigned int i0, unsigned int i1, unsigned int i2)
Definition vec3.h:834
__forceinline plane normalize(const plane &p)
Definition plane.h:261
__forceinline bool greaterequal_all(const point &v0, const point &v1)
Definition point.h:463
__forceinline bool greater_any(const point &v0, const point &v1)
Definition point.h:430
__forceinline float lerp(float x, float y, float l)
Linearly interpolate between 2 values: ret = x + l * (y - x)
Definition scalar.h:616
static const f32x4 _id_y
Definition vec3.h:27
__forceinline float clamp(float val, float minVal, float maxVal)
Float clamping.
Definition scalar.h:506
static const f32x4 _id_z
Definition vec3.h:28
half operator-(half one, half two)
Definition half.h:114
__forceinline bool less_any(const point &v0, const point &v1)
Definition point.h:386
__forceinline vec3 catmullrom(const vec3 &v0, const vec3 &v1, const vec3 &v2, const vec3 &v3, scalar s)
Definition vec3.h:466
__forceinline TYPE min(TYPE a, TYPE b)
Definition scalar.h:399
__forceinline bool less_all(const point &v0, const point &v1)
Definition point.h:397
__forceinline bool lessequal_all(const point &v0, const point &v1)
Definition point.h:419
__forceinline vec3 select(const vec3 &v0, const vec3 &v1, const uint i0, const uint i1, const uint i2)
Definition vec3.h:857
__forceinline vec3 splat_y(const vec3 &v)
Definition vec3.h:814
__forceinline point minimize(const point &v0, const point &v1)
Definition point.h:377
float scalar
Definition scalar.h:45
__forceinline point greater(const point &v0, const point &v1)
Definition point.h:510
half operator+(half one, half two)
Definition half.h:105
static const i32x4 _sign
Definition vec3.h:33
half operator*(half one, half two)
Definition half.h:123
__forceinline TYPE max(TYPE a, TYPE b)
Definition scalar.h:368
__forceinline scalar abs(scalar a)
Definition scalar.h:451
static const f32x4 _mask_xyz
Definition vec3.h:34
__forceinline vec3 multiplyadd(const vec3 &v0, const vec3 &v1, const vec3 &v2)
Definition vec3.h:396
static const f32x4 _minus1
Definition vec3.h:30
__forceinline scalar acos(scalar x)
Definition scalar.h:218
__forceinline bool greater_all(const point &v0, const point &v1)
Definition point.h:441
__forceinline bool nearequal(const point &v0, const point &v1, float epsilon)
Definition point.h:485
__forceinline bool lessequal_any(const point &v0, const point &v1)
Definition point.h:408
static const f32x4 _id_x
Definition vec3.h:26
__forceinline float floor(float val)
Floating point flooring.
Definition scalar.h:552
__forceinline vec3 normalizeapprox(const vec3 &v)
Definition vec3.h:598
__forceinline vec3 reciprocalapprox(const vec3 &v)
Definition vec3.h:378
Nebula's scalar datatype.
Maps generic SIMD-like types and intrinsics to either SSE4+AVX or NEON.
vec3()=default
default constructor, NOTE: does NOT setup components!
Definition scalar.h:67
scalar x
Definition scalar.h:70
scalar y
Definition scalar.h:70
scalar z
Definition scalar.h:70
A 4x4 single point precision float matrix.
Definition mat4.h:49
A 3D vector.
Definition vec3.h:37
void loadu(const scalar *ptr)
load content from unaligned memory
Definition vec3.h:178
void stream(scalar *ptr) const
stream content to 16-byte-aligned memory circumventing the write-cache
Definition vec3.h:207
float v[3]
Definition vec3.h:96
bool operator==(const vec3 &rhs) const
equality operator
Definition vec3.h:149
void storeu(scalar *ptr) const
write content to unaligned memory through the write cache
Definition vec3.h:198
vec3()=default
default constructor, NOTE: does NOT setup components!
void load(const scalar *ptr)
load content from 16-byte-aligned memory
Definition vec3.h:168
void operator*=(scalar s)
inplace scalar multiply
Definition vec3.h:293
void operator-=(const vec3 &rhs)
inplace sub
Definition vec3.h:284
void store(scalar *ptr) const
write content to 16-byte-aligned memory through the write cache
Definition vec3.h:188
float x
Definition vec3.h:93
float z
Definition vec3.h:93
void operator/=(const vec3 &rhs)
divide by a vector component-wise
Definition vec3.h:266
float __w
Definition vec3.h:93
f32x4 vec
Definition vec3.h:95
void operator+=(const vec3 &rhs)
inplace add
Definition vec3.h:275
scalar & operator[](const int index)
read-only access to indexed component
Definition vec3.h:330
bool operator!=(const vec3 &rhs) const
inequality operator
Definition vec3.h:158
void operator=(const f32x4 &rhs)
assign an vmVector4
Definition vec3.h:140
void set(scalar x, scalar y, scalar z)
set content
Definition vec3.h:321
vec3(const vec3 &rhs)=default
copy constructor
float y
Definition vec3.h:93
bool operator==(const TiXmlString &a, const TiXmlString &b)
Definition tinystr.h:272
bool operator!=(const TiXmlString &a, const TiXmlString &b)
Definition tinystr.h:282
#define NEBULA_ALIGN16
Definition types.h:143
unsigned int uint
Definition types.h:33