29static const __m128
_id_x = _mm_setr_ps(1.0f, 0.0f, 0.0f, 0.0f);
30static const __m128
_id_y = _mm_setr_ps(0.0f, 1.0f, 0.0f, 0.0f);
31static const __m128
_id_z = _mm_setr_ps(0.0f, 0.0f, 1.0f, 0.0f);
32static const __m128
_id_w = _mm_setr_ps(0.0f, 0.0f, 0.0f, 1.0f);
33static const __m128
_minus1 = _mm_setr_ps(-1.0f, -1.0f, -1.0f, -1.0f);
34static const __m128
_plus1 = _mm_setr_ps(1.0f, 1.0f, 1.0f, 1.0f);
35static const __m128
_zero = _mm_setr_ps(0.0f, 0.0f, 0.0f, 0.0f);
36static const __m128i
_sign = _mm_setr_epi32(0x80000000, 0x80000000, 0x80000000, 0x80000000);
37static const __m128
_mask_xyz = _mm_castsi128_ps(_mm_setr_epi32( 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0 ));
51 vec3(
const __m128& rhs);
54 void operator=(
const __m128& rhs);
56 void operator+=(
const vec3& rhs);
58 void operator-=(
const vec3& rhs);
62 void operator*=(
const vec3& rhs);
64 void operator/=(
const vec3& rhs);
71 void load(
const scalar* ptr);
73 void loadu(
const scalar* ptr);
75 void store(
scalar* ptr)
const;
77 void storeu(
scalar* ptr)
const;
79 void stream(
scalar* ptr)
const;
85 scalar& operator[](
const int index);
87 scalar operator[](
const int index)
const;
107 this->
vec = _mm_setr_ps(
x,
y,
z, 0);
116 this->
vec = _mm_setr_ps(
v,
v,
v, 0.0f);
125 this->
vec = _mm_insert_ps(rhs,
_id_w, 0b111000);
134 this->
vec = _mm_insert_ps(rhs,
_id_w, 0b111000);
143 __m128 vTemp = _mm_cmpeq_ps(this->
vec, rhs.
vec);
144 return ((_mm_movemask_ps(vTemp)==0x0f) != 0);
153 __m128 vTemp = _mm_cmpeq_ps(this->
vec, rhs.
vec);
154 return ((_mm_movemask_ps(vTemp)==0x0f) == 0);
164 this->
vec = _mm_load_ps(ptr);
165 this->
vec = _mm_and_ps(this->
vec, _mask_xyz);
175 this->
vec = _mm_loadu_ps(ptr);
176 this->
vec = _mm_and_ps(this->
vec, _mask_xyz);
186 __m128 vv = _mm_permute_ps(this->
vec, _MM_SHUFFLE(2, 2, 2, 2));
187 _mm_storel_epi64(
reinterpret_cast<__m128i*
>(ptr), _mm_castps_si128(this->
vec));
188 _mm_store_ss(&ptr[2], vv);
198 __m128 t1 = _mm_permute_ps(this->
vec, _MM_SHUFFLE(1, 1, 1, 1));
199 __m128 t2 = _mm_permute_ps(this->
vec, _MM_SHUFFLE(2, 2, 2, 2));
200 _mm_store_ss(&ptr[0], this->
vec);
201 _mm_store_ss(&ptr[1], t1);
202 _mm_store_ss(&ptr[2], t2);
220 return vec3(_mm_xor_ps(_mm_castsi128_ps(
_sign), lhs.
vec));
229 __m128 temp = _mm_set1_ps(t);
230 return _mm_mul_ps(lhs.
vec, temp);
239 return _mm_mul_ps(lhs.
vec, rhs.
vec);
248 this->
vec = _mm_mul_ps(this->
vec, rhs.
vec);
257 this->
vec = _mm_div_ps(this->
vec, rhs.
vec);
266 this->
vec = _mm_add_ps(this->
vec, rhs.
vec);
275 this->
vec = _mm_sub_ps(this->
vec, rhs.
vec);
284 __m128 temp = _mm_set1_ps(s);
285 this->
vec = _mm_mul_ps(this->
vec, temp);
294 return _mm_add_ps(lhs.
vec, rhs.
vec);
303 return _mm_sub_ps(lhs.
vec, rhs.
vec);
312 this->
vec = _mm_setr_ps(
x,
y,
z, 0);
322 return this->
v[index];
332 return this->
v[index];
341 return _mm_cvtss_f32(_mm_sqrt_ss(_mm_dp_ps(v.
vec, v.
vec, 0x71)));
350 return _mm_cvtss_f32(_mm_dp_ps(v.
vec, v.
vec, 0x71));
368 return _mm_rcp_ps(v.
vec);
377 return _mm_mul_ps(v0.
vec, v1.
vec);
387 return _mm_fmadd_ps(v0.
vec, v1.
vec, v2.
vec);
389 return _mm_add_ps(_mm_mul_ps(v0.
vec, v1.
vec),v2.
vec);
399 return _mm_div_ps(v0.
vec, v1.
vec);
408 unsigned int val = 0x7fffffff;
409 __m128 temp = _mm_set1_ps(*(
float*)&val);
410 return _mm_and_ps(v.
vec, temp);
419 __m128 tmp0, tmp1, tmp2, tmp3, result;
420 tmp0 = _mm_shuffle_ps( v0.
vec, v0.
vec, _MM_SHUFFLE(3,0,2,1) );
421 tmp1 = _mm_shuffle_ps( v1.
vec, v1.
vec, _MM_SHUFFLE(3,1,0,2) );
422 tmp2 = _mm_shuffle_ps( v0.
vec, v0.
vec, _MM_SHUFFLE(3,1,0,2) );
423 tmp3 = _mm_shuffle_ps( v1.
vec, v1.
vec, _MM_SHUFFLE(3,0,2,1) );
424 result = _mm_mul_ps( tmp0, tmp1 );
425 result = _mm_sub_ps( result, _mm_mul_ps( tmp2, tmp3 ) );
435 return _mm_cvtss_f32(_mm_dp_ps(v0.
vec, v1.
vec, 0x71));
445 __m128 R1 = _mm_sub_ps(v1.
vec,v0.
vec);
446 __m128 SF = _mm_set_ps1(f);
447 __m128 R2 = _mm_sub_ps(v2.
vec,v0.
vec);
448 __m128 SG = _mm_set_ps1(g);
449 R1 = _mm_mul_ps(R1,SF);
450 R2 = _mm_mul_ps(R2,SG);
451 R1 = _mm_add_ps(R1,v0.
vec);
452 R1 = _mm_add_ps(R1,R2);
465 __m128 P0 = _mm_set_ps1((-s3 + 2.0f * s2 - s) * 0.5f);
466 __m128 P1 = _mm_set_ps1((3.0f * s3 - 5.0f * s2 + 2.0f) * 0.5f);
467 __m128 P2 = _mm_set_ps1((-3.0f * s3 + 4.0f * s2 + s) * 0.5f);
468 __m128 P3 = _mm_set_ps1((s3 - s2) * 0.5f);
470 P0 = _mm_mul_ps(P0, v0.
vec);
471 P1 = _mm_mul_ps(P1, v1.
vec);
472 P2 = _mm_mul_ps(P2, v2.
vec);
473 P3 = _mm_mul_ps(P3, v3.
vec);
474 P0 = _mm_add_ps(P0,P1);
475 P2 = _mm_add_ps(P2,P3);
476 P0 = _mm_add_ps(P0,P2);
489 __m128 P0 = _mm_set_ps1(2.0f * s3 - 3.0f * s2 + 1.0f);
490 __m128 T0 = _mm_set_ps1(s3 - 2.0f * s2 + s);
491 __m128 P1 = _mm_set_ps1(-2.0f * s3 + 3.0f * s2);
492 __m128 T1 = _mm_set_ps1(s3 - s2);
494 __m128 vResult = _mm_mul_ps(P0, v1.
vec);
495 __m128 vTemp = _mm_mul_ps(T0, t1.
vec);
496 vResult = _mm_add_ps(vResult,vTemp);
497 vTemp = _mm_mul_ps(P1, v2.
vec);
498 vResult = _mm_add_ps(vResult,vTemp);
499 vTemp = _mm_mul_ps(T1, t2.
vec);
500 vResult = _mm_add_ps(vResult,vTemp);
511 __m128 l0 = _mm_mul_ps(v0.
vec, v0.
vec);
512 l0 = _mm_add_ps(_mm_shuffle_ps(l0, l0, _MM_SHUFFLE(0, 0, 0, 0)),
513 _mm_add_ps(_mm_shuffle_ps(l0, l0, _MM_SHUFFLE(1, 1, 1, 1)), _mm_shuffle_ps(l0, l0, _MM_SHUFFLE(2, 2, 2, 2))));
515 __m128 l1 = _mm_mul_ps(v1.
vec, v1.
vec);
516 l1 = _mm_add_ps(_mm_shuffle_ps(l1, l1, _MM_SHUFFLE(0, 0, 0, 0)),
517 _mm_add_ps(_mm_shuffle_ps(l1, l1, _MM_SHUFFLE(1, 1, 1, 1)), _mm_shuffle_ps(l1, l1, _MM_SHUFFLE(2, 2, 2, 2))));
519 __m128 l = _mm_shuffle_ps(l0, l1, _MM_SHUFFLE(0, 0, 0, 0));
521 l = _mm_mul_ss(_mm_shuffle_ps(l, l, _MM_SHUFFLE(0, 0, 0, 0)), _mm_shuffle_ps(l, l, _MM_SHUFFLE(1, 1, 1, 1)));
525 dot = _mm_add_ps(_mm_shuffle_ps(
dot,
dot, _MM_SHUFFLE(0, 0, 0, 0)),
526 _mm_add_ps(_mm_shuffle_ps(
dot,
dot, _MM_SHUFFLE(1, 1, 1, 1)),
527 _mm_add_ps(_mm_shuffle_ps(
dot,
dot, _MM_SHUFFLE(2, 2, 2, 2)), _mm_shuffle_ps(
dot,
dot, _MM_SHUFFLE(3, 3, 3, 3)))));
535 _mm_store_ss(&cangle,
dot);
545 return v0 + ((v1-v0) * s);
554 return _mm_max_ps(v0.
vec, v1.
vec);
563 return _mm_min_ps(v0.
vec, v1.
vec);
572 __m128 temp = _mm_max_ps(
min.vec,
clamp.vec);
573 temp = _mm_min_ps(temp,
max.vec);
583 if (v ==
vec3(0))
return v;
584 __m128 t = _mm_div_ps(v.
vec, _mm_sqrt_ps(_mm_dp_ps(v.
vec, v.
vec, 0x77)));
585 return _mm_insert_ps(t, v.
vec, 0xF0);
594 if (v ==
vec3(0))
return v;
595 __m128 t = _mm_rsqrt_ps(_mm_dp_ps(v.
vec, v.
vec, 0x7f));
596 t = _mm_or_ps(t,
_id_w);
597 return _mm_mul_ps(v.
vec, t);
606 __m128 res = _mm_mul_ps(incident.
vec, normal.
vec);
607 res = _mm_add_ps(_mm_shuffle_ps(res, res, _MM_SHUFFLE(0,0,0,0)),
608 _mm_add_ps(_mm_shuffle_ps(res, res, _MM_SHUFFLE(1,1,1,1)), _mm_shuffle_ps(res, res, _MM_SHUFFLE(2,2,2,2))));
609 res = _mm_add_ps(res, res);
610 res = _mm_mul_ps(res, normal.
vec);
611 res = _mm_sub_ps(incident.
vec,res);
621 __m128 vTemp = _mm_cmpge_ps(v0.
vec, v1.
vec);
622 int res = _mm_movemask_ps(vTemp) & 7;
632 __m128 vTemp = _mm_cmpge_ps(v0.
vec, v1.
vec);
633 int res = _mm_movemask_ps(vTemp) & 7;
643 __m128 vTemp = _mm_cmpgt_ps(v0.
vec, v1.
vec);
644 int res = _mm_movemask_ps(vTemp) & 7;
654 __m128 vTemp = _mm_cmpgt_ps(v0.
vec, v1.
vec);
655 int res = _mm_movemask_ps(vTemp) & 7;
665 __m128 vTemp = _mm_cmpgt_ps(v0.
vec, v1.
vec);
666 int res = _mm_movemask_ps(vTemp) & 7;
676 __m128 vTemp = _mm_cmpgt_ps(v0.
vec, v1.
vec);
677 int res = _mm_movemask_ps(vTemp) & 7;
687 __m128 vTemp = _mm_cmpge_ps(v0.
vec, v1.
vec);
688 int res = _mm_movemask_ps(vTemp) & 7;
698 __m128 vTemp = _mm_cmpge_ps(v0.
vec, v1.
vec);
699 int res = _mm_movemask_ps(vTemp) & 7;
709 __m128 vTemp = _mm_cmpeq_ps(v0.
vec, v1.
vec);
710 int res = _mm_movemask_ps(vTemp) & 7;
720 __m128 eps = _mm_setr_ps(epsilon, epsilon, epsilon, 0.0f);
721 __m128 delta = _mm_sub_ps(v0.
vec, v1.
vec);
722 __m128 temp = _mm_setzero_ps();
723 temp = _mm_sub_ps(temp, delta);
724 temp = _mm_max_ps(temp, delta);
725 temp = _mm_cmple_ps(temp, eps);
727 return (_mm_movemask_ps(temp) == 0x7) != 0;
736 __m128 delta = _mm_sub_ps(v0.
vec, v1.
vec);
737 __m128 temp = _mm_setzero_ps();
738 temp = _mm_sub_ps(temp, delta);
739 temp = _mm_max_ps(temp, delta);
740 temp = _mm_cmple_ps(temp, epsilon.
vec);
742 return (_mm_movemask_ps(temp) == 0x7) != 0;
751 return _mm_min_ps(_mm_cmplt_ps(v0.
vec, v1.
vec),
_plus1);
760 return _mm_min_ps(_mm_cmpgt_ps(v0.
vec, v1.
vec),
_plus1);
769 return _mm_min_ps(_mm_cmpeq_ps(v0.
vec, v1.
vec),
_plus1);
778 n_assert(element < 3 && element >= 0);
784 res = _mm_shuffle_ps(v.
vec, v.
vec, _MM_SHUFFLE(0, 0, 0, 0));
787 res = _mm_shuffle_ps(v.
vec, v.
vec, _MM_SHUFFLE(1, 1, 1, 1));
790 res = _mm_shuffle_ps(v.
vec, v.
vec, _MM_SHUFFLE(2, 2, 2, 2));
803 __m128 res = _mm_shuffle_ps(v.
vec, v.
vec, _MM_SHUFFLE(0, 0, 0, 0));
814 __m128 res = _mm_shuffle_ps(v.
vec, v.
vec, _MM_SHUFFLE(1, 1, 1, 1));
825 __m128 res = _mm_shuffle_ps(v.
vec, v.
vec, _MM_SHUFFLE(2, 2, 2, 2));
834permute(
const vec3& v0,
const vec3& v1,
unsigned int i0,
unsigned int i1,
unsigned int i2)
836 static __m128i three = _mm_set_epi32(3,3,3,3);
839 __m128i vControl = _mm_load_si128(
reinterpret_cast<const __m128i*
>(&elem[0]));
841 __m128i vSelect = _mm_cmpgt_epi32(vControl, three);
842 vControl = _mm_and_si128(vControl, three);
844 __m128 shuffled1 = _mm_permutevar_ps(v0.
vec, vControl);
845 __m128 shuffled2 = _mm_permutevar_ps(v1.
vec, vControl);
847 __m128 masked1 = _mm_andnot_ps(_mm_castsi128_ps(vSelect), shuffled1);
848 __m128 masked2 = _mm_and_ps(_mm_castsi128_ps(vSelect), shuffled2);
850 return _mm_or_ps(masked1, masked2);
860 return permute(v0, v1, i0, i1, i2);
869 __m128 v0masked = _mm_andnot_ps(control.
vec, v0.
vec);
870 __m128 v1masked = _mm_and_ps(v1.
vec, control.
vec);
871 return _mm_or_ps(v0masked, v1masked);
880 return _mm_floor_ps(v.
vec);
889 return _mm_ceil_ps(v.
vec);
#define n_assert(exp)
Definition debug.h:50
Different curves.
Definition angularpfeedbackloop.h:17
static const __m128 _id_z
Definition vec3.h:31
__forceinline point less(const point &v0, const point &v1)
Definition point.h:501
__forceinline vec3 cross(const vec3 &v0, const vec3 &v1)
Definition vec3.h:417
static const __m128 _id_x
Definition vec3.h:29
__forceinline point maximize(const point &v0, const point &v1)
Definition point.h:368
__forceinline quat barycentric(const quat &q0, const quat &q1, const quat &q2, scalar f, scalar g)
Definition quat.h:295
static const __m128 _zero
Definition vec3.h:35
__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:823
static const __m128i _sign
Definition vec3.h:36
__forceinline vec3 hermite(const vec3 &v1, const vec3 &t1, const vec3 &v2, const vec3 &t2, scalar s)
Definition vec3.h:484
__forceinline point equal(const point &v0, const point &v1)
Definition point.h:519
__forceinline vec3 splat_x(const vec3 &v)
Definition vec3.h:801
__forceinline vec3 splat(const vec3 &v, uint element)
Definition vec3.h:776
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:375
__forceinline scalar angle(const vec3 &v0, const vec3 &v1)
Definition vec3.h:508
__forceinline vec3 divide(const vec3 &v0, const vec3 &v1)
Definition vec3.h:397
__forceinline vec3 reciprocal(const vec3 &v)
Definition vec3.h:357
__forceinline scalar length(const quat &q)
Definition quat.h:259
__forceinline scalar lengthsq(const quat &q)
Definition quat.h:268
__forceinline scalar dot(const plane &p, const vec4 &v1)
Definition plane.h:246
__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:255
__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:597
__forceinline float clamp(float val, float minVal, float maxVal)
Float clamping.
Definition scalar.h:487
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:460
static const __m128 _id_w
Definition vec3.h:32
__forceinline TYPE min(TYPE a, TYPE b)
Definition scalar.h:390
__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:812
static const __m128 _minus1
Definition vec3.h:33
__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
half operator*(half one, half two)
Definition half.h:123
__forceinline TYPE max(TYPE a, TYPE b)
Definition scalar.h:359
__forceinline scalar abs(scalar a)
Definition scalar.h:432
__forceinline vec3 multiplyadd(const vec3 &v0, const vec3 &v1, const vec3 &v2)
Definition vec3.h:384
__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
static const __m128 _mask_xyz
Definition vec3.h:37
static const __m128 _id_y
Definition vec3.h:30
__forceinline bool lessequal_any(const point &v0, const point &v1)
Definition point.h:408
__forceinline float floor(float val)
Floating point flooring.
Definition scalar.h:533
__forceinline vec3 normalizeapprox(const vec3 &v)
Definition vec3.h:592
static const __m128 _plus1
Definition vec3.h:34
__forceinline vec3 reciprocalapprox(const vec3 &v)
Definition vec3.h:366
Nebula's scalar datatype.
A 3D vector.
Definition vec3.h:40
void loadu(const scalar *ptr)
load content from unaligned memory
Definition vec3.h:173
void stream(scalar *ptr) const
stream content to 16-byte-aligned memory circumventing the write-cache
Definition vec3.h:209
float v[3]
Definition vec3.h:97
bool operator==(const vec3 &rhs) const
equality operator
Definition vec3.h:141
void storeu(scalar *ptr) const
write content to unaligned memory through the write cache
Definition vec3.h:196
vec3()=default
default constructor, NOTE: does NOT setup components!
void load(const scalar *ptr)
load content from 16-byte-aligned memory
Definition vec3.h:162
void operator*=(scalar s)
inplace scalar multiply
Definition vec3.h:282
void operator-=(const vec3 &rhs)
inplace sub
Definition vec3.h:273
void store(scalar *ptr) const
write content to 16-byte-aligned memory through the write cache
Definition vec3.h:184
float x
Definition vec3.h:94
float z
Definition vec3.h:94
void operator/=(const vec3 &rhs)
divide by a vector component-wise
Definition vec3.h:255
float __w
Definition vec3.h:94
__m128 vec
Definition vec3.h:96
void operator+=(const vec3 &rhs)
inplace add
Definition vec3.h:264
scalar & operator[](const int index)
read-only access to indexed component
Definition vec3.h:319
bool operator!=(const vec3 &rhs) const
inequality operator
Definition vec3.h:151
void set(scalar x, scalar y, scalar z)
set content
Definition vec3.h:310
vec3(const vec3 &rhs)=default
copy constructor
float y
Definition vec3.h:94
void operator=(const __m128 &rhs)
assign an vmVector4
Definition vec3.h:132
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:181
unsigned int uint
Definition types.h:31