41 #include "CUMathBase.h"
85 #pragma mark Constructors
90 Vec3() : x(0), y(0), z(0) {}
99 Vec3(
float x,
float y,
float z) { this->x =
x; this->y =
y; this->z =
z; }
106 Vec3(
const float* array) { x = array[0]; y = array[1]; z = array[2]; }
115 x = p2.
x-p1.
x; y = p2.
y-p1.
y; z = p2.
z-p1.
z;
165 this->x =
x; this->y =
y; this->z =
z;
177 x = array[0]; y = array[1]; z = array[2];
189 x = v.
x; y = v.
y; z = v.
z;
202 x = p2.
x-p1.
x; y = p2.
y-p1.
y; z = p2.
z-p1.
z;
218 #pragma mark Static Arithmetic
346 #pragma mark Arithmetic
356 x = clampf(x, min.
x, max.
x);
357 y = clampf(y, min.
y, max.
y);
358 z = clampf(z, min.
z, max.
z);
373 return Vec3(clampf(x,min.
x,max.
x), clampf(y, min.
y, max.
y),clampf(z, min.
z, max.
z));
384 x += v.
x; y += v.
y; z += v.
z;
398 this->x +=
x; this->y +=
y; this->z +=
z;
410 x -= v.
x; y -= v.
y; z -= v.
z;
424 this->x -=
x; this->y -=
y; this->z -=
z;
436 x *= s; y *= s; z *= s;
450 x *= sx; y *= sy; z *= sz;
462 x *= v.
x; y *= v.
y; z *= v.
z;
503 x = -
x; y = -
y; z = -
z;
517 x = 1.0f/
x; y = 1.0f/
y; z = 1.0f/
z;
560 x = func(x); y = func(y); z = func(z);
575 return Vec3(func(x), func(y), func(z));
580 #pragma mark Operators
660 return result.
add(v);
700 return result.
scale(s);
715 return result.
scale(v);
749 #pragma mark Comparisons
762 return (x == v.
x ? (y == v.
y ? z < v.
z : y < v.
y) : x < v.
x);
777 return (x == v.
x ? (y == v.
y ? z <= v.
z : y <= v.
y) : x <= v.
x);
792 return (x == v.
x ? (y == v.
y ? z > v.
z : y > v.
y) : x > v.
x);
807 return (x == v.
x ? (y == v.
y ? z >= v.
z : y >= v.
y) : x >= v.
x);
821 return x == v.
x && y == v.
y && z == v.
z;
835 return x != v.
x || y != v.
y || z != v.
z;
849 return x <= v.
x && y <= v.
y && z <= v.
z;
863 return x >= v.
x && y >= v.
y && z >= v.
z;
877 bool equals(
const Vec3& v,
float variance=CU_MATH_EPSILON)
const {
883 #pragma mark Linear Attributes
890 return x == 0.0f && y == 0.0f && z == 0.0f;
910 return x == 1.0f && y == 1.0f && z == 1.0f;
919 return x != 0.0f && y != 0.0f && z != 0.0f;
929 bool isUnit(
float variance=CU_MATH_EPSILON)
const {
931 return dot < variance && dot > -variance;
976 return (x-v.
x)*(x-v.
x)+(y-v.
y)*(y-v.
y)+(z-v.
z)*(z-v.
z);
1008 #pragma mark Linear Algebra
1016 float dot(
const Vec3& v)
const {
return (x * v.
x + y * v.
y + z * v.
z); }
1026 return *(
cross(*
this,v,
this));
1040 return result.
cross(other);
1081 return Vec3((x + other.
x) / 2.0f, (y + other.
y) / 2.0f, (z + other.
z) / 2.0f);
1106 return other * (
dot(other)/other.
dot(other));
1122 *
this *= (1.f - alpha);
1123 return *
this += other * alpha;
1139 return *
this * (1.f - alpha) + other * alpha;
1160 #pragma mark Static Linear Algebra
1235 #pragma mark Conversion Methods
1247 std::string
toString(
bool verbose =
false)
const;
1303 operator Vec2()
const;
1331 operator Vec4()
const;
1358 #pragma mark Friend Operations
1370 return result.
scale(x);
Vec3 & scale(float s)
Definition: CUVec3.h:435
float dot(const Vec3 &v) const
Definition: CUVec3.h:1016
Vec3 getClamp(const Vec3 &min, const Vec3 &max) const
Definition: CUVec3.h:372
Vec3 & setZero()
Definition: CUVec3.h:211
Vec3 getLerp(const Vec3 &other, float alpha)
Definition: CUVec3.h:1138
Vec3 getNormalization() const
Definition: CUVec3.h:1066
bool isNearZero(float variance=CU_MATH_EPSILON) const
Definition: CUVec3.h:900
Vec3 & cross(const Vec3 &v)
Definition: CUVec3.h:1025
float x
Definition: CUVec3.h:66
Vec3(float x, float y, float z)
Definition: CUVec3.h:99
const Vec3 operator-() const
Definition: CUVec3.h:684
Vec3 & operator*=(const Vec3 &v)
Definition: CUVec3.h:621
Vec3 & operator/=(float s)
Definition: CUVec3.h:632
Vec3 & lerp(const Vec3 &other, float alpha)
Definition: CUVec3.h:1121
Vec3()
Definition: CUVec3.h:90
bool operator<(const Vec3 &v) const
Definition: CUVec3.h:761
static const Vec3 UNIT_Z
Definition: CUVec3.h:81
Vec3 & operator/=(const Vec3 &v)
Definition: CUVec3.h:645
bool isOne() const
Definition: CUVec3.h:909
float z
Definition: CUVec3.h:70
Vec3 & set(float x, float y, float z)
Definition: CUVec3.h:164
const Vec3 operator*(float s) const
Definition: CUVec3.h:698
Vec3 & add(float x, float y, float z)
Definition: CUVec3.h:397
const Vec3 operator-(const Vec3 &v) const
Definition: CUVec3.h:672
bool under(const Vec3 &v) const
Definition: CUVec3.h:848
float distanceSquared(const Vec3 &v) const
Definition: CUVec3.h:975
Vec3 getCross(const Vec3 &other) const
Definition: CUVec3.h:1038
float length() const
Definition: CUVec3.h:986
Vec3 & set(const Vec3 &p1, const Vec3 &p2)
Definition: CUVec3.h:201
Vec3 & reciprocate()
Definition: CUVec3.h:516
static Vec3 * subtract(const Vec3 &v1, const Vec3 &v2, Vec3 *dst)
Vec3 & map(std::function< float(float)> func)
Definition: CUVec3.h:559
bool operator<=(const Vec3 &v) const
Definition: CUVec3.h:776
Definition: CUColor4.h:73
Vec3 getProjection(const Vec3 &other) const
Definition: CUVec3.h:1105
const Vec3 operator*(const Vec3 &v) const
Definition: CUVec3.h:713
float getAngle(const Vec3 &other, const Vec3 &up=Vec3::UNIT_Z) const
const Vec3 operator/(const Vec3 &v) const
Definition: CUVec3.h:742
bool isInvertible() const
Definition: CUVec3.h:918
static float angle(const Vec3 &v1, const Vec3 &v2, const Vec3 &up=Vec3::UNIT_Z)
const Vec3 operator/(float s) const
Definition: CUVec3.h:727
bool isUnit(float variance=CU_MATH_EPSILON) const
Definition: CUVec3.h:929
static const Vec3 UNIT_Y
Definition: CUVec3.h:79
Vec3 & operator+=(const Vec3 &v)
Definition: CUVec3.h:588
bool over(const Vec3 &v) const
Definition: CUVec3.h:862
static Vec3 * negate(const Vec3 &v, Vec3 *dst)
static const Vec3 ONE
Definition: CUVec3.h:75
~Vec3()
Definition: CUVec3.h:128
Vec3 & set(const Vec3 &v)
Definition: CUVec3.h:188
bool operator!=(const Vec3 &v) const
Definition: CUVec3.h:834
Vec3 & operator=(const Vec3 &v)
Definition: CUVec3.h:140
Vec3 & smooth(const Vec3 &target, float elapsed, float response)
Vec3 & set(const float *array)
Definition: CUVec3.h:176
float distance(const Vec3 &v) const
Definition: CUVec3.h:957
Vec3 & subtract(const Vec3 &v)
Definition: CUVec3.h:409
Vec3 & add(const Vec3 &v)
Definition: CUVec3.h:383
Vec3 & scale(float sx, float sy, float sz)
Definition: CUVec3.h:449
Vec3 & clamp(const Vec3 &min, const Vec3 &max)
Definition: CUVec3.h:355
bool operator>(const Vec3 &v) const
Definition: CUVec3.h:791
Vec3 getNegation() const
Definition: CUVec3.h:528
Vec3(const Vec3 ©)
Definition: CUVec3.h:123
static Vec3 * add(const Vec3 &v1, const Vec3 &v2, Vec3 *dst)
static Vec3 * midpoint(const Vec3 &v1, const Vec3 &v2, Vec3 *dst)
Vec3 & operator*=(float s)
Definition: CUVec3.h:610
static Vec3 * scale(const Vec3 &v, float s, Vec3 *dst)
const Vec3 operator+(const Vec3 &v) const
Definition: CUVec3.h:658
Vec3 & subtract(float x, float y, float z)
Definition: CUVec3.h:423
bool operator==(const Vec3 &v) const
Definition: CUVec3.h:820
static Vec3 * reciprocate(const Vec3 &v, Vec3 *dst)
Vec3 getMidpoint(const Vec3 &other) const
Definition: CUVec3.h:1080
Vec3 & operator=(const float *array)
Definition: CUVec3.h:151
int operator*(Font::Style value)
Definition: CUFont.h:1503
Vec3(const float *array)
Definition: CUVec3.h:106
static Vec3 * divide(const Vec3 &v, float s, Vec3 *dst)
Vec3 & operator-=(const Vec3 &v)
Definition: CUVec3.h:599
Vec3 & project(const Vec3 &other)
Definition: CUVec3.h:1091
std::string toString(bool verbose=false) const
Definition: CUColor4.h:1104
float y
Definition: CUVec3.h:68
Definition: CUAnimationNode.h:52
float lengthSquared() const
Definition: CUVec3.h:1002
bool isZero() const
Definition: CUVec3.h:889
static const Vec3 ZERO
Definition: CUVec3.h:73
static const Vec3 UNIT_X
Definition: CUVec3.h:77
static Vec3 * clamp(const Vec3 &v, const Vec3 &min, const Vec3 &max, Vec3 *dst)
bool operator>=(const Vec3 &v) const
Definition: CUVec3.h:806
Vec3 getReciprocal() const
Definition: CUVec3.h:544
Vec3 getMap(std::function< float(float)> func) const
Definition: CUVec3.h:574
Vec3 & negate()
Definition: CUVec3.h:502
Vec3 & scale(const Vec3 &v)
Definition: CUVec3.h:461
Vec3(const Vec3 &p1, const Vec3 &p2)
Definition: CUVec3.h:114
bool equals(const Vec3 &v, float variance=CU_MATH_EPSILON) const
Definition: CUVec3.h:877
Vec3 Point3
Definition: CUVec3.h:1374