more vector stuff
parent
b4619085b7
commit
f96e74902a
|
@ -60,6 +60,19 @@ struct Vec2 {
|
|||
x /= o.x; y /= o.y;
|
||||
return *this;
|
||||
}
|
||||
|
||||
Vec2 &neg() {
|
||||
x = -x; y = -y;
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool is_zero() const {
|
||||
return (x == 0) && (y == 0);
|
||||
}
|
||||
|
||||
T dot(const Vec2<T> &o) const {
|
||||
return (x * o.x) + (y * o.y);
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
|
@ -92,6 +105,11 @@ inline Vec2<T> operator/(const Vec2<T> &a, const Vec2<T> &b) {
|
|||
return Vec2<T>(a).div(b);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline Vec2<T> operator-(const Vec2<T> &a) {
|
||||
return Vec2<T>(a).neg();
|
||||
}
|
||||
|
||||
using Vec2f = Vec2<float>;
|
||||
using Vec2d = Vec2<double>;
|
||||
using Vec2b = Vec2<byte>;
|
||||
|
@ -148,6 +166,19 @@ struct Vec3 {
|
|||
x /= o.x; y /= o.y; z /= o.z;
|
||||
return *this;
|
||||
}
|
||||
|
||||
Vec3 &neg() {
|
||||
x = -x; y = -y; z = -z;
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool is_zero() const {
|
||||
return (x == 0) && (y == 0) && (z == 0);
|
||||
}
|
||||
|
||||
T dot(const Vec3<T> &o) const {
|
||||
return (x * o.x) + (y * o.y) + (z * o.z);
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
|
@ -180,6 +211,11 @@ inline Vec3<T> operator/(const Vec3<T> &a, const Vec3<T> &b) {
|
|||
return Vec3<T>(a).div(b);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline Vec3<T> operator-(const Vec3<T> &a) {
|
||||
return Vec3<T>(a).neg();
|
||||
}
|
||||
|
||||
using Vec3f = Vec3<float>;
|
||||
using Vec3d = Vec3<double>;
|
||||
using Vec3b = Vec3<byte>;
|
||||
|
@ -236,6 +272,19 @@ struct Vec4 {
|
|||
x /= o.x; y /= o.y; z /= o.z; w /= o.w;
|
||||
return *this;
|
||||
}
|
||||
|
||||
Vec4 &neg() {
|
||||
x = -x; y = -y; z = -z; w = -w;
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool is_zero() const {
|
||||
return (x == 0) && (y == 0) && (z == 0) && (w == 0);
|
||||
}
|
||||
|
||||
T dot(const Vec4<T> &o) const {
|
||||
return (x * o.x) + (y * o.y) + (z * o.z) + (w * o.w);
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
|
@ -268,6 +317,11 @@ inline Vec4<T> operator/(const Vec4<T> &a, const Vec4<T> &b) {
|
|||
return Vec4<T>(a).div(b);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline Vec4<T> operator-(const Vec4<T> &a) {
|
||||
return Vec4<T>(a).neg();
|
||||
}
|
||||
|
||||
using Vec4f = Vec4<float>;
|
||||
using Vec4d = Vec4<double>;
|
||||
using Vec4b = Vec4<byte>;
|
||||
|
|
Loading…
Reference in New Issue