2010-11-20 10:37:14 +00:00
|
|
|
/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */
|
|
|
|
/* If you are missing that file, acquire a complete release at teeworlds.com. */
|
2007-08-22 07:52:33 +00:00
|
|
|
#ifndef BASE_VMATH_H
|
|
|
|
#define BASE_VMATH_H
|
|
|
|
|
2023-02-28 19:41:07 +00:00
|
|
|
#include <cmath>
|
2023-11-04 13:51:39 +00:00
|
|
|
#include <cstdint>
|
2010-07-05 18:57:07 +00:00
|
|
|
|
2020-09-18 16:45:42 +00:00
|
|
|
#include "math.h"
|
|
|
|
|
2007-08-22 07:52:33 +00:00
|
|
|
// ------------------------------------
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
class vector2_base
|
|
|
|
{
|
|
|
|
public:
|
2020-09-26 19:41:58 +00:00
|
|
|
union
|
|
|
|
{
|
|
|
|
T x, u;
|
|
|
|
};
|
|
|
|
union
|
|
|
|
{
|
|
|
|
T y, v;
|
|
|
|
};
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2023-01-08 15:27:25 +00:00
|
|
|
constexpr vector2_base() = default;
|
2022-05-28 17:55:24 +00:00
|
|
|
constexpr vector2_base(T nx, T ny) :
|
2022-05-21 22:38:36 +00:00
|
|
|
x(nx), y(ny)
|
2007-08-22 07:52:33 +00:00
|
|
|
{
|
|
|
|
}
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2020-09-26 19:41:58 +00:00
|
|
|
vector2_base operator-() const { return vector2_base(-x, -y); }
|
2022-03-24 00:16:05 +00:00
|
|
|
vector2_base operator-(const vector2_base &vec) const { return vector2_base(x - vec.x, y - vec.y); }
|
|
|
|
vector2_base operator+(const vector2_base &vec) const { return vector2_base(x + vec.x, y + vec.y); }
|
|
|
|
vector2_base operator*(const T rhs) const { return vector2_base(x * rhs, y * rhs); }
|
|
|
|
vector2_base operator*(const vector2_base &vec) const { return vector2_base(x * vec.x, y * vec.y); }
|
|
|
|
vector2_base operator/(const T rhs) const { return vector2_base(x / rhs, y / rhs); }
|
|
|
|
vector2_base operator/(const vector2_base &vec) const { return vector2_base(x / vec.x, y / vec.y); }
|
|
|
|
|
|
|
|
const vector2_base &operator+=(const vector2_base &vec)
|
2020-09-26 19:41:58 +00:00
|
|
|
{
|
2022-03-24 00:16:05 +00:00
|
|
|
x += vec.x;
|
|
|
|
y += vec.y;
|
2020-09-26 19:41:58 +00:00
|
|
|
return *this;
|
|
|
|
}
|
2022-03-24 00:16:05 +00:00
|
|
|
const vector2_base &operator-=(const vector2_base &vec)
|
2020-09-26 19:41:58 +00:00
|
|
|
{
|
2022-03-24 00:16:05 +00:00
|
|
|
x -= vec.x;
|
|
|
|
y -= vec.y;
|
2020-09-26 19:41:58 +00:00
|
|
|
return *this;
|
|
|
|
}
|
2022-03-24 00:16:05 +00:00
|
|
|
const vector2_base &operator*=(const T rhs)
|
2020-09-26 19:41:58 +00:00
|
|
|
{
|
2022-03-24 00:16:05 +00:00
|
|
|
x *= rhs;
|
|
|
|
y *= rhs;
|
2020-09-26 19:41:58 +00:00
|
|
|
return *this;
|
|
|
|
}
|
2022-03-24 00:16:05 +00:00
|
|
|
const vector2_base &operator*=(const vector2_base &vec)
|
2020-09-26 19:41:58 +00:00
|
|
|
{
|
2022-03-24 00:16:05 +00:00
|
|
|
x *= vec.x;
|
|
|
|
y *= vec.y;
|
2020-09-26 19:41:58 +00:00
|
|
|
return *this;
|
|
|
|
}
|
2022-03-24 00:16:05 +00:00
|
|
|
const vector2_base &operator/=(const T rhs)
|
2020-09-26 19:41:58 +00:00
|
|
|
{
|
2022-03-24 00:16:05 +00:00
|
|
|
x /= rhs;
|
|
|
|
y /= rhs;
|
2020-09-26 19:41:58 +00:00
|
|
|
return *this;
|
|
|
|
}
|
2022-03-24 00:16:05 +00:00
|
|
|
const vector2_base &operator/=(const vector2_base &vec)
|
2020-09-26 19:41:58 +00:00
|
|
|
{
|
2022-03-24 00:16:05 +00:00
|
|
|
x /= vec.x;
|
|
|
|
y /= vec.y;
|
2020-09-26 19:41:58 +00:00
|
|
|
return *this;
|
|
|
|
}
|
2007-08-22 07:52:33 +00:00
|
|
|
|
2022-03-24 00:16:05 +00:00
|
|
|
bool operator==(const vector2_base &vec) const { return x == vec.x && y == vec.y; } //TODO: do this with an eps instead
|
|
|
|
bool operator!=(const vector2_base &vec) const { return x != vec.x || y != vec.y; }
|
2007-08-22 07:52:33 +00:00
|
|
|
|
2019-04-11 22:46:54 +00:00
|
|
|
T &operator[](const int index) { return index ? y : x; }
|
2007-08-22 07:52:33 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
template<typename T>
|
2023-01-06 19:23:10 +00:00
|
|
|
constexpr inline vector2_base<T> rotate(const vector2_base<T> &a, float angle)
|
2007-08-22 07:52:33 +00:00
|
|
|
{
|
2021-01-13 17:41:32 +00:00
|
|
|
angle = angle * pi / 180.0f;
|
2023-02-28 20:31:40 +00:00
|
|
|
float s = std::sin(angle);
|
|
|
|
float c = std::cos(angle);
|
2021-01-13 17:41:32 +00:00
|
|
|
return vector2_base<T>((T)(c * a.x - s * a.y), (T)(s * a.x + c * a.y));
|
2007-08-22 07:52:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
inline T distance(const vector2_base<T> a, const vector2_base<T> &b)
|
|
|
|
{
|
2020-09-26 19:41:58 +00:00
|
|
|
return length(a - b);
|
2007-08-22 07:52:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template<typename T>
|
2023-01-06 19:23:10 +00:00
|
|
|
constexpr inline T dot(const vector2_base<T> a, const vector2_base<T> &b)
|
2007-08-22 07:52:33 +00:00
|
|
|
{
|
2020-09-26 19:41:58 +00:00
|
|
|
return a.x * b.x + a.y * b.y;
|
2007-08-22 07:52:33 +00:00
|
|
|
}
|
|
|
|
|
2021-01-13 17:41:32 +00:00
|
|
|
inline float length(const vector2_base<float> &a)
|
|
|
|
{
|
2023-02-28 20:31:40 +00:00
|
|
|
return std::sqrt(dot(a, a));
|
2021-01-13 17:41:32 +00:00
|
|
|
}
|
|
|
|
|
2023-07-18 10:21:36 +00:00
|
|
|
inline float length(const vector2_base<int> &a)
|
|
|
|
{
|
|
|
|
return std::sqrt(dot(a, a));
|
|
|
|
}
|
|
|
|
|
2023-01-30 23:46:39 +00:00
|
|
|
inline float length_squared(const vector2_base<float> &a)
|
|
|
|
{
|
|
|
|
return dot(a, a);
|
|
|
|
}
|
|
|
|
|
2023-01-06 19:23:10 +00:00
|
|
|
constexpr inline float angle(const vector2_base<float> &a)
|
2014-02-18 16:20:28 +00:00
|
|
|
{
|
|
|
|
if(a.x == 0 && a.y == 0)
|
|
|
|
return 0.0f;
|
|
|
|
else if(a.x == 0)
|
|
|
|
return a.y < 0 ? -pi / 2 : pi / 2;
|
2023-02-28 20:31:40 +00:00
|
|
|
float result = std::atan(a.y / a.x);
|
2014-02-18 16:20:28 +00:00
|
|
|
if(a.x < 0)
|
|
|
|
result = result + pi;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2007-08-22 07:52:33 +00:00
|
|
|
template<typename T>
|
2023-01-06 19:23:10 +00:00
|
|
|
constexpr inline vector2_base<T> normalize_pre_length(const vector2_base<T> &v, T len)
|
2007-08-22 07:52:33 +00:00
|
|
|
{
|
2022-05-25 23:22:14 +00:00
|
|
|
if(len == 0)
|
|
|
|
return vector2_base<T>();
|
2021-01-13 17:41:32 +00:00
|
|
|
return vector2_base<T>(v.x / len, v.y / len);
|
2007-08-22 07:52:33 +00:00
|
|
|
}
|
|
|
|
|
2021-01-13 17:41:32 +00:00
|
|
|
inline vector2_base<float> normalize(const vector2_base<float> &v)
|
2020-10-17 18:22:13 +00:00
|
|
|
{
|
2023-01-06 19:21:25 +00:00
|
|
|
float divisor = length(v);
|
2022-05-25 23:22:14 +00:00
|
|
|
if(divisor == 0.0f)
|
|
|
|
return vector2_base<float>(0.0f, 0.0f);
|
|
|
|
float l = (float)(1.0f / divisor);
|
2021-01-13 17:41:32 +00:00
|
|
|
return vector2_base<float>(v.x * l, v.y * l);
|
2020-10-17 18:22:13 +00:00
|
|
|
}
|
|
|
|
|
Fix build with clang on debian 11
$ clang --version
Debian clang version 11.0.1-2
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
Fixes this error
```
In file included from
/home/chiller/Desktop/git/ddnet/src/base/color.h:6:
/home/chiller/Desktop/git/ddnet/src/base/vmath.h:141:38: error:
constexpr function never produces a constant expression
[-Winvalid-constexpr]
constexpr inline vector2_base<float> direction(float angle)
^
/home/chiller/Desktop/git/ddnet/src/base/vmath.h:143:29: note:
non-constexpr function 'cosf' cannot be used in a constant expression
return vector2_base<float>(cosf(angle), sinf(angle));
^
/usr/include/x86_64-linux-gnu/bits/mathcalls.h:62:1: note: declared here
__MATHCALL_VEC (cos,, (_Mdouble_ __x));
^
/usr/include/math.h:266:3: note: expanded from macro '__MATHCALL_VEC'
__MATHCALL (function, suffix, args)
^
/usr/include/math.h:273:3: note: expanded from macro '__MATHCALL'
__MATHDECL (_Mdouble_,function,suffix, args)
^
/usr/include/math.h:275:3: note: expanded from macro '__MATHDECL'
__MATHDECL_1(type, function,suffix, args); \
^
/usr/include/math.h:283:15: note: expanded from macro '__MATHDECL_1'
extern type __MATH_PRECNAME(function,suffix) args __THROW
^
/usr/include/math.h:303:34: note: expanded from macro '__MATH_PRECNAME'
^
<scratch space>:34:1: note: expanded from here
cosf
^
1 error generated.
make[2]: *** [CMakeFiles/engine-shared.dir/build.make:173:
CMakeFiles/engine-shared.dir/src/engine/shared/console.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:604:
CMakeFiles/engine-shared.dir/all] Error 2
make: *** [Makefile:171: all] Error 2
```
2023-01-16 14:08:37 +00:00
|
|
|
inline vector2_base<float> direction(float angle)
|
2014-02-18 16:20:28 +00:00
|
|
|
{
|
2023-02-28 20:31:40 +00:00
|
|
|
return vector2_base<float>(std::cos(angle), std::sin(angle));
|
2014-02-18 16:20:28 +00:00
|
|
|
}
|
|
|
|
|
2023-03-12 23:21:13 +00:00
|
|
|
inline vector2_base<float> random_direction()
|
|
|
|
{
|
|
|
|
return direction(random_angle());
|
|
|
|
}
|
|
|
|
|
2007-08-22 07:52:33 +00:00
|
|
|
typedef vector2_base<float> vec2;
|
|
|
|
typedef vector2_base<bool> bvec2;
|
|
|
|
typedef vector2_base<int> ivec2;
|
2008-03-19 23:08:26 +00:00
|
|
|
|
|
|
|
template<typename T>
|
2023-01-06 19:23:10 +00:00
|
|
|
constexpr inline bool closest_point_on_line(vector2_base<T> line_pointA, vector2_base<T> line_pointB, vector2_base<T> target_point, vector2_base<T> &out_pos)
|
2008-03-19 23:08:26 +00:00
|
|
|
{
|
2022-05-03 11:47:28 +00:00
|
|
|
vector2_base<T> AB = line_pointB - line_pointA;
|
|
|
|
T SquaredMagnitudeAB = dot(AB, AB);
|
|
|
|
if(SquaredMagnitudeAB > 0)
|
|
|
|
{
|
2022-05-04 18:08:02 +00:00
|
|
|
vector2_base<T> AP = target_point - line_pointA;
|
2022-05-03 11:47:28 +00:00
|
|
|
T APdotAB = dot(AP, AB);
|
|
|
|
T t = APdotAB / SquaredMagnitudeAB;
|
|
|
|
out_pos = line_pointA + AB * clamp(t, (T)0, (T)1);
|
2020-10-17 18:22:13 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return false;
|
2008-03-19 23:08:26 +00:00
|
|
|
}
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2007-08-22 07:52:33 +00:00
|
|
|
// ------------------------------------
|
|
|
|
template<typename T>
|
|
|
|
class vector3_base
|
|
|
|
{
|
|
|
|
public:
|
2020-09-26 19:41:58 +00:00
|
|
|
union
|
|
|
|
{
|
2022-07-01 02:23:22 +00:00
|
|
|
T x, r, h, u;
|
2020-09-26 19:41:58 +00:00
|
|
|
};
|
|
|
|
union
|
|
|
|
{
|
2022-07-01 02:23:22 +00:00
|
|
|
T y, g, s, v;
|
2020-09-26 19:41:58 +00:00
|
|
|
};
|
|
|
|
union
|
|
|
|
{
|
2022-07-01 02:23:22 +00:00
|
|
|
T z, b, l, w;
|
2020-09-26 19:41:58 +00:00
|
|
|
};
|
2007-08-22 07:52:33 +00:00
|
|
|
|
2023-01-08 15:27:25 +00:00
|
|
|
constexpr vector3_base() = default;
|
2023-01-06 19:23:10 +00:00
|
|
|
constexpr vector3_base(T nx, T ny, T nz) :
|
2022-05-21 22:38:36 +00:00
|
|
|
x(nx), y(ny), z(nz)
|
2007-08-22 07:52:33 +00:00
|
|
|
{
|
|
|
|
}
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2022-03-24 00:16:05 +00:00
|
|
|
vector3_base operator-(const vector3_base &vec) const { return vector3_base(x - vec.x, y - vec.y, z - vec.z); }
|
2020-09-26 19:41:58 +00:00
|
|
|
vector3_base operator-() const { return vector3_base(-x, -y, -z); }
|
2022-03-24 00:16:05 +00:00
|
|
|
vector3_base operator+(const vector3_base &vec) const { return vector3_base(x + vec.x, y + vec.y, z + vec.z); }
|
|
|
|
vector3_base operator*(const T rhs) const { return vector3_base(x * rhs, y * rhs, z * rhs); }
|
|
|
|
vector3_base operator*(const vector3_base &vec) const { return vector3_base(x * vec.x, y * vec.y, z * vec.z); }
|
|
|
|
vector3_base operator/(const T rhs) const { return vector3_base(x / rhs, y / rhs, z / rhs); }
|
|
|
|
vector3_base operator/(const vector3_base &vec) const { return vector3_base(x / vec.x, y / vec.y, z / vec.z); }
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2022-03-24 00:16:05 +00:00
|
|
|
const vector3_base &operator+=(const vector3_base &vec)
|
2020-09-26 19:41:58 +00:00
|
|
|
{
|
2022-03-24 00:16:05 +00:00
|
|
|
x += vec.x;
|
|
|
|
y += vec.y;
|
|
|
|
z += vec.z;
|
2020-09-26 19:41:58 +00:00
|
|
|
return *this;
|
|
|
|
}
|
2022-03-24 00:16:05 +00:00
|
|
|
const vector3_base &operator-=(const vector3_base &vec)
|
2020-09-26 19:41:58 +00:00
|
|
|
{
|
2022-03-24 00:16:05 +00:00
|
|
|
x -= vec.x;
|
|
|
|
y -= vec.y;
|
|
|
|
z -= vec.z;
|
2020-09-26 19:41:58 +00:00
|
|
|
return *this;
|
|
|
|
}
|
2022-03-24 00:16:05 +00:00
|
|
|
const vector3_base &operator*=(const T rhs)
|
2020-09-26 19:41:58 +00:00
|
|
|
{
|
2022-03-24 00:16:05 +00:00
|
|
|
x *= rhs;
|
|
|
|
y *= rhs;
|
|
|
|
z *= rhs;
|
2020-09-26 19:41:58 +00:00
|
|
|
return *this;
|
|
|
|
}
|
2022-03-24 00:16:05 +00:00
|
|
|
const vector3_base &operator*=(const vector3_base &vec)
|
2020-09-26 19:41:58 +00:00
|
|
|
{
|
2022-03-24 00:16:05 +00:00
|
|
|
x *= vec.x;
|
|
|
|
y *= vec.y;
|
|
|
|
z *= vec.z;
|
2020-09-26 19:41:58 +00:00
|
|
|
return *this;
|
|
|
|
}
|
2022-03-24 00:16:05 +00:00
|
|
|
const vector3_base &operator/=(const T rhs)
|
2020-09-26 19:41:58 +00:00
|
|
|
{
|
2022-03-24 00:16:05 +00:00
|
|
|
x /= rhs;
|
|
|
|
y /= rhs;
|
|
|
|
z /= rhs;
|
2020-09-26 19:41:58 +00:00
|
|
|
return *this;
|
|
|
|
}
|
2022-03-24 00:16:05 +00:00
|
|
|
const vector3_base &operator/=(const vector3_base &vec)
|
2020-09-26 19:41:58 +00:00
|
|
|
{
|
2022-03-24 00:16:05 +00:00
|
|
|
x /= vec.x;
|
|
|
|
y /= vec.y;
|
|
|
|
z /= vec.z;
|
2020-09-26 19:41:58 +00:00
|
|
|
return *this;
|
|
|
|
}
|
2007-08-22 07:52:33 +00:00
|
|
|
|
2022-03-24 00:16:05 +00:00
|
|
|
bool operator==(const vector3_base &vec) const { return x == vec.x && y == vec.y && z == vec.z; } //TODO: do this with an eps instead
|
|
|
|
bool operator!=(const vector3_base &vec) const { return x != vec.x || y != vec.y || z != vec.z; }
|
2007-08-22 07:52:33 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
inline T distance(const vector3_base<T> &a, const vector3_base<T> &b)
|
|
|
|
{
|
2020-09-26 19:41:58 +00:00
|
|
|
return length(a - b);
|
2007-08-22 07:52:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template<typename T>
|
2023-01-06 19:23:10 +00:00
|
|
|
constexpr inline T dot(const vector3_base<T> &a, const vector3_base<T> &b)
|
2007-08-22 07:52:33 +00:00
|
|
|
{
|
2020-09-26 19:41:58 +00:00
|
|
|
return a.x * b.x + a.y * b.y + a.z * b.z;
|
2007-08-22 07:52:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template<typename T>
|
2023-01-06 19:23:10 +00:00
|
|
|
constexpr inline vector3_base<T> cross(const vector3_base<T> &a, const vector3_base<T> &b)
|
2007-08-22 07:52:33 +00:00
|
|
|
{
|
|
|
|
return vector3_base<T>(
|
2020-09-26 19:41:58 +00:00
|
|
|
a.y * b.z - a.z * b.y,
|
|
|
|
a.z * b.x - a.x * b.z,
|
|
|
|
a.x * b.y - a.y * b.x);
|
2007-08-22 07:52:33 +00:00
|
|
|
}
|
|
|
|
|
2021-01-13 17:41:32 +00:00
|
|
|
//
|
|
|
|
inline float length(const vector3_base<float> &a)
|
|
|
|
{
|
2023-02-28 20:31:40 +00:00
|
|
|
return std::sqrt(dot(a, a));
|
2021-01-13 17:41:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline vector3_base<float> normalize(const vector3_base<float> &v)
|
|
|
|
{
|
2023-01-06 19:21:25 +00:00
|
|
|
float divisor = length(v);
|
2022-05-25 23:22:14 +00:00
|
|
|
if(divisor == 0.0f)
|
|
|
|
return vector3_base<float>(0.0f, 0.0f, 0.0f);
|
|
|
|
float l = (float)(1.0f / divisor);
|
2021-01-13 17:41:32 +00:00
|
|
|
return vector3_base<float>(v.x * l, v.y * l, v.z * l);
|
|
|
|
}
|
|
|
|
|
2007-08-22 07:52:33 +00:00
|
|
|
typedef vector3_base<float> vec3;
|
|
|
|
typedef vector3_base<bool> bvec3;
|
|
|
|
typedef vector3_base<int> ivec3;
|
|
|
|
|
|
|
|
// ------------------------------------
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
class vector4_base
|
|
|
|
{
|
|
|
|
public:
|
2020-09-26 19:41:58 +00:00
|
|
|
union
|
|
|
|
{
|
|
|
|
T x, r, h;
|
|
|
|
};
|
|
|
|
union
|
|
|
|
{
|
|
|
|
T y, g, s;
|
|
|
|
};
|
|
|
|
union
|
|
|
|
{
|
|
|
|
T z, b, l;
|
|
|
|
};
|
|
|
|
union
|
|
|
|
{
|
|
|
|
T w, a;
|
|
|
|
};
|
2007-08-22 07:52:33 +00:00
|
|
|
|
2023-01-08 15:27:25 +00:00
|
|
|
constexpr vector4_base() = default;
|
2023-01-06 19:23:10 +00:00
|
|
|
constexpr vector4_base(T nx, T ny, T nz, T nw) :
|
2022-05-21 22:38:36 +00:00
|
|
|
x(nx), y(ny), z(nz), w(nw)
|
2007-08-22 07:52:33 +00:00
|
|
|
{
|
|
|
|
}
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2022-03-24 00:16:05 +00:00
|
|
|
vector4_base operator+(const vector4_base &vec) const { return vector4_base(x + vec.x, y + vec.y, z + vec.z, w + vec.w); }
|
|
|
|
vector4_base operator-(const vector4_base &vec) const { return vector4_base(x - vec.x, y - vec.y, z - vec.z, w - vec.w); }
|
2020-09-26 19:41:58 +00:00
|
|
|
vector4_base operator-() const { return vector4_base(-x, -y, -z, -w); }
|
2022-03-24 00:16:05 +00:00
|
|
|
vector4_base operator*(const vector4_base &vec) const { return vector4_base(x * vec.x, y * vec.y, z * vec.z, w * vec.w); }
|
|
|
|
vector4_base operator*(const T rhs) const { return vector4_base(x * rhs, y * rhs, z * rhs, w * rhs); }
|
|
|
|
vector4_base operator/(const vector4_base &vec) const { return vector4_base(x / vec.x, y / vec.y, z / vec.z, w / vec.w); }
|
|
|
|
vector4_base operator/(const T vec) const { return vector4_base(x / vec, y / vec, z / vec, w / vec); }
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2022-03-24 00:16:05 +00:00
|
|
|
const vector4_base &operator+=(const vector4_base &vec)
|
2020-09-26 19:41:58 +00:00
|
|
|
{
|
2022-03-24 00:16:05 +00:00
|
|
|
x += vec.x;
|
|
|
|
y += vec.y;
|
|
|
|
z += vec.z;
|
|
|
|
w += vec.w;
|
2020-09-26 19:41:58 +00:00
|
|
|
return *this;
|
|
|
|
}
|
2022-03-24 00:16:05 +00:00
|
|
|
const vector4_base &operator-=(const vector4_base &vec)
|
2020-09-26 19:41:58 +00:00
|
|
|
{
|
2022-03-24 00:16:05 +00:00
|
|
|
x -= vec.x;
|
|
|
|
y -= vec.y;
|
|
|
|
z -= vec.z;
|
|
|
|
w -= vec.w;
|
2020-09-26 19:41:58 +00:00
|
|
|
return *this;
|
|
|
|
}
|
2022-03-24 00:16:05 +00:00
|
|
|
const vector4_base &operator*=(const T rhs)
|
2020-09-26 19:41:58 +00:00
|
|
|
{
|
2022-03-24 00:16:05 +00:00
|
|
|
x *= rhs;
|
|
|
|
y *= rhs;
|
|
|
|
z *= rhs;
|
|
|
|
w *= rhs;
|
2020-09-26 19:41:58 +00:00
|
|
|
return *this;
|
|
|
|
}
|
2022-03-24 00:16:05 +00:00
|
|
|
const vector4_base &operator*=(const vector4_base &vec)
|
2020-09-26 19:41:58 +00:00
|
|
|
{
|
2022-03-24 00:16:05 +00:00
|
|
|
x *= vec.x;
|
|
|
|
y *= vec.y;
|
|
|
|
z *= vec.z;
|
|
|
|
w *= vec.w;
|
2020-09-26 19:41:58 +00:00
|
|
|
return *this;
|
|
|
|
}
|
2022-03-24 00:16:05 +00:00
|
|
|
const vector4_base &operator/=(const T rhs)
|
2020-09-26 19:41:58 +00:00
|
|
|
{
|
2022-03-24 00:16:05 +00:00
|
|
|
x /= rhs;
|
|
|
|
y /= rhs;
|
|
|
|
z /= rhs;
|
|
|
|
w /= rhs;
|
2020-09-26 19:41:58 +00:00
|
|
|
return *this;
|
|
|
|
}
|
2022-03-24 00:16:05 +00:00
|
|
|
const vector4_base &operator/=(const vector4_base &vec)
|
2020-09-26 19:41:58 +00:00
|
|
|
{
|
2022-03-24 00:16:05 +00:00
|
|
|
x /= vec.x;
|
|
|
|
y /= vec.y;
|
|
|
|
z /= vec.z;
|
|
|
|
w /= vec.w;
|
2020-09-26 19:41:58 +00:00
|
|
|
return *this;
|
|
|
|
}
|
2007-08-22 07:52:33 +00:00
|
|
|
|
2022-03-24 00:16:05 +00:00
|
|
|
bool operator==(const vector4_base &vec) const { return x == vec.x && y == vec.y && z == vec.z && w == vec.w; } //TODO: do this with an eps instead
|
2023-01-06 19:22:32 +00:00
|
|
|
bool operator!=(const vector4_base &vec) const { return x != vec.x || y != vec.y || z != vec.z || w != vec.w; }
|
2007-08-22 07:52:33 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef vector4_base<float> vec4;
|
|
|
|
typedef vector4_base<bool> bvec4;
|
|
|
|
typedef vector4_base<int> ivec4;
|
2023-11-04 13:51:39 +00:00
|
|
|
typedef vector4_base<uint8_t> ubvec4;
|
2007-08-22 07:52:33 +00:00
|
|
|
|
|
|
|
#endif
|