41 #ifdef CU_MATH_VECTOR_APPLE
44 #include <Accelerate/Accelerate.h>
46 #ifdef CU_MATH_VECTOR_SSE
47 #include <xmmintrin.h>
52 #include "CUMathBase.h"
77 #if defined CU_MATH_VECTOR_APPLE
91 #elif defined CU_MATH_VECTOR_SSE
92 __declspec(align(32))
union {
140 #pragma mark Constructors
145 Vec4() : x(0), y(0), z(0), w(0) {}
155 Vec4(
float x,
float y,
float z,
float w) {
156 this->x =
x; this->y =
y; this->z =
z; this->w =
w;
167 #if defined CU_MATH_VECTOR_APPLE
168 v = *((vFloat*)array);
170 x = array[0]; y = array[1]; z = array[2]; w = array[3];
181 #if defined CU_MATH_VECTOR_APPLE
184 x = p2.
x-p1.
x; y = p2.
y-p1.
y; z = p2.
z-p1.
z; w = p2.
w-p1.
w;
194 #if defined CU_MATH_VECTOR_APPLE
197 x = copy.
x; y = copy.
y; z = copy.
z; w = copy.
w;
242 Vec4&
set(
float x,
float y,
float z,
float w) {
243 this->x =
x; this->y =
y; this->z =
z; this->w =
w;
257 #if defined CU_MATH_VECTOR_APPLE
258 v = *((vFloat*)array);
260 x = array[0]; y = array[1]; z = array[2]; w = array[3];
273 #if defined CU_MATH_VECTOR_APPLE
276 x = v.
x; y = v.
y; z = v.
z; w = v.
w;
290 #if defined CU_MATH_VECTOR_APPLE
293 x = p2.
x-p1.
x; y = p2.
y-p1.
y; z = p2.
z-p1.
z; w = p2.
w-p1.
w;
310 #pragma mark Static Arithmetic
442 #pragma mark Arithmetic
464 return Vec4(clampf(x,min.
x,max.
x), clampf(y,min.
y,max.
y),
465 clampf(z,min.
z,max.
z), clampf(w,min.
w,max.
w));
476 #if defined CU_MATH_VECTOR_APPLE
479 x += v.
x; y += v.
y; z += v.
z; w += v.
w;
494 Vec4&
add(
float x,
float y,
float z,
float w) {
495 this->x +=
x; this->y +=
y; this->z +=
z; this->w +=
w;
507 #if defined CU_MATH_VECTOR_APPLE
510 x -= v.
x; y -= v.
y; z -= v.
z; w -= v.
w;
526 this->x -=
x; this->y -=
y; this->z -=
z; this->w -=
w;
538 #if defined CU_MATH_VECTOR_APPLE
541 x *= s; y *= s; z *= s; w *= s;
557 x *= sx; y *= sy; z *= sz; w *= sw;
569 #if defined CU_MATH_VECTOR_APPLE
572 x *= v.
x; y *= v.
y; z *= v.
z; w *= v.
w;
596 Vec4&
divide(
float sx,
float sy,
float sz,
float sw);
615 x = -
x; y = -
y; z = -
z; w = -
w;
629 x = 1.0f/
x; y = 1.0f/
y; z = 1.0f/
z; w = 1.0f/
w;
672 x = func(x); y = func(y); z = func(z); w = func(w);
687 return Vec4(func(x), func(y), func(z), func(w));
692 #pragma mark Operators
772 return result.
add(v);
812 return result.
scale(s);
827 return result.
scale(v);
861 #pragma mark Comparisons
874 return (x == v.
x ? (y == v.
y ? (z == v.
z ? w < v.
w : z < v.
z) : y < v.
y) : x < v.
x);
889 return (x == v.
x ? (y == v.
y ? (z == v.
z ? w <= v.
w : z <= v.
z) : y <= v.
y) : x <= v.
x);
904 return (x == v.
x ? (y == v.
y ? (z == v.
z ? w > v.
w : z > v.
z) : y > v.
y) : x > v.
x);
919 return (x == v.
x ? (y == v.
y ? (z == v.
z ? w >= v.
w : z >= v.
z) : y >= v.
y) : x >= v.
x);
933 return x == v.
x && y == v.
y && z == v.
z && w == v.
w;
947 return x != v.
x || y != v.
y || z != v.
z || w != v.
w;
961 return x <= v.
x && y <= v.
y && z <= v.
z && w <= v.
w;
975 return x >= v.
x && y >= v.
y && z >= v.
z && w >= v.
w;
989 bool equals(
const Vec4& v,
float variance=CU_MATH_EPSILON)
const {
995 #pragma mark Linear Attributes
1002 return x == 0.0f && y == 0.0f && z == 0.0f && w == 0.0f;
1022 return x == 1.0f && y == 1.0f && z == 1.0f && w == 1.0f;
1031 return x != 0.0f && y != 0.0f && z != 0.0f && w != 0.0f;
1041 bool isUnit(
float variance=CU_MATH_EPSILON)
const {
1043 return dot <= variance && dot >= -variance;
1077 #if defined CU_MATH_VECTOR_APPLE
1078 vFloat nv = this->v-v.v;
1079 return vSnorm2(4, &nv);
1100 #if defined CU_MATH_VECTOR_APPLE
1101 vFloat nv = this->v-v.v;
1102 return vSdot(4, &nv, &nv);
1104 return (x-v.
x)*(x-v.
x)+(y-v.
y)*(y-v.
y)+(z-v.
z)*(z-v.
z)+(w-v.
w)*(w-v.
w);
1116 #if defined CU_MATH_VECTOR_APPLE
1117 return vSnorm2(4, &v);
1136 #if defined CU_MATH_VECTOR_APPLE
1137 return vSdot(4, &v, &v);
1139 return x*x+y*y+z*z+w*
w;
1145 #pragma mark Linear Algebra
1154 #if defined CU_MATH_VECTOR_APPLE
1155 return vSdot(4, &(this->v), &(v.v));
1157 return (x * v.
x + y * v.
y + z * v.
z + w * v.
w);
1226 return other * (
dot(other)/other.
dot(other));
1238 float dw = (w == 0 ? 1 : 1/
w);
1272 *
this *= (1.f - alpha);
1273 return *
this += other * alpha;
1289 return *
this * (1.f - alpha) + other * alpha;
1304 void smooth(
const Vec4& target,
float elapsed,
float response);
1308 #pragma mark Static Linear Algebra
1384 #pragma mark Conversion Methods
1396 std::string
toString(
bool verbose =
false)
const;
1455 operator Vec2()
const;
1485 operator Vec3()
const;
1534 #pragma mark Friend Operations
1545 return result.
scale(x);
Vec4(const Vec4 ©)
Definition: CUVec4.h:193
bool isZero() const
Definition: CUVec4.h:1001
Vec4 & set(const Vec4 &v)
Definition: CUVec4.h:272
static const Vec4 ZERO
Definition: CUVec4.h:117
Vec4(const Vec4 &p1, const Vec4 &p2)
Definition: CUVec4.h:180
Vec4 & add(float x, float y, float z, float w)
Definition: CUVec4.h:494
bool isNearZero(float variance=CU_MATH_EPSILON) const
Definition: CUVec4.h:1012
static Vec4 * negate(const Vec4 &v, Vec4 *dst)
static Vec4 * subtract(const Vec4 &v1, const Vec4 &v2, Vec4 *dst)
static const Vec4 ONE
Definition: CUVec4.h:119
static const Vec4 UNIT_W
Definition: CUVec4.h:127
Vec4(float x, float y, float z, float w)
Definition: CUVec4.h:155
Vec4 & add(const Vec4 &v)
Definition: CUVec4.h:475
const Vec4 operator-() const
Definition: CUVec4.h:796
float dot(const Vec4 &v) const
Definition: CUVec4.h:1153
bool isHomogenous() const
Definition: CUVec4.h:1051
Vec4 & subtract(const Vec4 &v)
Definition: CUVec4.h:506
Vec4 & operator*=(const Vec4 &v)
Definition: CUVec4.h:733
float z
Definition: CUVec4.h:111
static const Vec4 HOMOG_Y
Definition: CUVec4.h:135
Vec4 & operator*=(float s)
Definition: CUVec4.h:722
static Vec4 * scale(const Vec4 &v, float s, Vec4 *dst)
const Vec4 operator*(const Vec4 &v) const
Definition: CUVec4.h:825
static const Vec4 HOMOG_X
Definition: CUVec4.h:133
Vec4 & operator/=(float s)
Definition: CUVec4.h:744
Vec4 getHomogenized()
Definition: CUVec4.h:1253
Vec4 & setZero()
Definition: CUVec4.h:303
static const Vec4 HOMOG_ORIGIN
Definition: CUVec4.h:131
const Vec4 operator*(float s) const
Definition: CUVec4.h:810
bool operator<=(const Vec4 &v) const
Definition: CUVec4.h:888
Vec4 & scale(float s)
Definition: CUVec4.h:537
Vec4 & negate()
Definition: CUVec4.h:614
bool operator<(const Vec4 &v) const
Definition: CUVec4.h:873
Vec4(const float *array)
Definition: CUVec4.h:166
Vec4 getNegation() const
Definition: CUVec4.h:640
Definition: CUColor4.h:73
Vec4 getLerp(const Vec4 &other, float alpha)
Definition: CUVec4.h:1288
Vec4 & set(const Vec4 &p1, const Vec4 &p2)
Definition: CUVec4.h:289
static const Vec4 UNIT_X
Definition: CUVec4.h:121
const Vec4 operator/(float s) const
Definition: CUVec4.h:839
float lengthSquared() const
Definition: CUVec4.h:1135
static const Vec4 UNIT_Y
Definition: CUVec4.h:123
bool over(const Vec4 &v) const
Definition: CUVec4.h:974
void smooth(const Vec4 &target, float elapsed, float response)
float y
Definition: CUVec4.h:109
Vec4 getReciprocal() const
Definition: CUVec4.h:656
bool operator>(const Vec4 &v) const
Definition: CUVec4.h:903
static const Vec4 UNIT_Z
Definition: CUVec4.h:125
const Vec4 operator-(const Vec4 &v) const
Definition: CUVec4.h:784
static const Vec4 HOMOG_Z
Definition: CUVec4.h:137
Vec4 & map(std::function< float(float)> func)
Definition: CUVec4.h:671
Vec4 & operator/=(const Vec4 &v)
Definition: CUVec4.h:757
bool operator>=(const Vec4 &v) const
Definition: CUVec4.h:918
Vec4()
Definition: CUVec4.h:145
static Vec4 * midpoint(const Vec4 &v1, const Vec4 &v2, Vec4 *dst)
static float angle(const Vec4 &v1, const Vec4 &v2)
float distanceSquared(const Vec4 &v) const
Definition: CUVec4.h:1099
bool under(const Vec4 &v) const
Definition: CUVec4.h:960
float distance(const Vec4 &v) const
Definition: CUVec4.h:1076
Vec4 & reciprocate()
Definition: CUVec4.h:628
~Vec4()
Definition: CUVec4.h:204
bool isInvertible() const
Definition: CUVec4.h:1030
Vec4 getMidpoint(const Vec4 &other) const
Definition: CUVec4.h:1198
const Vec4 operator+(const Vec4 &v) const
Definition: CUVec4.h:770
Vec4 & lerp(const Vec4 &other, float alpha)
Definition: CUVec4.h:1271
std::string toString(bool verbose=false) const
static Vec4 * clamp(const Vec4 &v, const Vec4 &min, const Vec4 &max, Vec4 *dst)
static Vec4 * reciprocate(const Vec4 &v, Vec4 *dst)
float getAngle(const Vec4 &other) const
Vec4 & operator-=(const Vec4 &v)
Definition: CUVec4.h:711
Vec4 & set(const float *array)
Definition: CUVec4.h:256
bool equals(const Vec4 &v, float variance=CU_MATH_EPSILON) const
Definition: CUVec4.h:989
Vec4 getNormalization() const
Definition: CUVec4.h:1184
float length() const
Definition: CUVec4.h:1115
int operator*(Font::Style value)
Definition: CUFont.h:1503
bool operator==(const Vec4 &v) const
Definition: CUVec4.h:932
Vec4 & scale(const Vec4 &v)
Definition: CUVec4.h:568
Vec4 & set(float x, float y, float z, float w)
Definition: CUVec4.h:242
Vec4 getMap(std::function< float(float)> func) const
Definition: CUVec4.h:686
float x
Definition: CUVec4.h:107
Vec4 & operator+=(const Vec4 &v)
Definition: CUVec4.h:700
Vec4 & project(const Vec4 &other)
Definition: CUVec4.h:1211
bool operator!=(const Vec4 &v) const
Definition: CUVec4.h:946
Definition: CUColor4.h:1104
Vec4 & operator=(const Vec4 &v)
Definition: CUVec4.h:215
Vec4 getClamp(const Vec4 &min, const Vec4 &max) const
Definition: CUVec4.h:463
Vec4 & operator=(const float *array)
Definition: CUVec4.h:228
Definition: CUAnimationNode.h:52
Vec4 getProjection(const Vec4 &other) const
Definition: CUVec4.h:1225
const Vec4 operator/(const Vec4 &v) const
Definition: CUVec4.h:854
bool isOne() const
Definition: CUVec4.h:1021
float w
Definition: CUVec4.h:113
Vec4 & homogenize()
Definition: CUVec4.h:1237
static Vec4 * divide(const Vec4 &v, float s, Vec4 *dst)
Vec4 & subtract(float x, float y, float z, float w)
Definition: CUVec4.h:525
Vec4 & scale(float sx, float sy, float sz, float sw)
Definition: CUVec4.h:556
bool isUnit(float variance=CU_MATH_EPSILON) const
Definition: CUVec4.h:1041
static Vec4 * add(const Vec4 &v1, const Vec4 &v2, Vec4 *dst)