20 inline Vector3(
void) : x(0), y(0), z(0) {}
21 inline Vector3(T a_x, T a_y, T a_z) : x(a_x), y(a_y), z(a_z) {}
24 #ifdef TOLUA_EXPOSITION // Hardcoded copy constructors (tolua++ does not support function templates .. yet) 33 template <typename U, typename = typename std::enable_if<!std::is_same<U, T>::value>::type>
34 Vector3(
const Vector3<U> & a_Rhs): x(static_cast<T>(a_Rhs.x)), y(static_cast<T>(a_Rhs.y)), z(static_cast<T>(a_Rhs.z)) {}
37 inline void Set(T a_x, T a_y, T a_z)
46 double Len = 1.0 /
Length();
48 x =
static_cast<T
>(x * Len);
49 y =
static_cast<T
>(y * Len);
50 z =
static_cast<T
>(z * Len);
55 double Len = 1.0 /
Length();
58 static_cast<T
>(x * Len),
59 static_cast<T>(y * Len),
60 static_cast<T
>(z * Len)
70 double Len = 1.0 /
Length();
73 static_cast<T>(x * Len),
74 static_cast<T>(y * Len),
75 static_cast<T>(z * Len)
84 #pragma clang diagnostic push 85 #pragma clang diagnostic ignored "-Wfloat-equal" 88 return ((x != 0) || (y != 0) || (z != 0));
91 #pragma clang diagnostic pop 97 return sqrt(static_cast<double>(x * x + y * y + z * z));
102 return x * x + y * y + z *
z;
107 return x * a_Rhs.
x + y * a_Rhs.
y + z * a_Rhs.
z;
129 y * a_Rhs.
z - z * a_Rhs.
y,
130 z * a_Rhs.
x - x * a_Rhs.
z,
131 x * a_Rhs.
y - y * a_Rhs.
x 141 #pragma clang diagnostic push 142 #pragma clang diagnostic ignored "-Wfloat-equal" 145 return !((x != a_Rhs.
x) || (y != a_Rhs.
y) || (z != a_Rhs.
z));
148 #pragma clang diagnostic pop 154 return (std::abs(x - a_Rhs.
x) < a_Eps) && (std::abs(y - a_Rhs.
y) < a_Eps) && (std::abs(z - a_Rhs.
z) < a_Eps);
157 inline void Move(T a_X, T a_Y, T a_Z)
198 inline bool operator < (const Vector3<T> & a_Rhs)
const 323 if (std::abs(z - a_OtherEnd.
z) <
EPS)
328 return (a_Z - z) / (a_OtherEnd.
z -
z);
338 if (std::abs(y - a_OtherEnd.
y) <
EPS)
343 return (a_Y - y) / (a_OtherEnd.
y -
y);
353 if (std::abs(x - a_OtherEnd.
x) <
EPS)
358 return (a_X - x) / (a_OtherEnd.
x -
x);
381 template <
typename ArgFormatter>
382 friend void format_arg(fmt::BasicFormatter<char, ArgFormatter> & a_Formatter,
const char *& a_FormatStr,
Vector3 a_Vec)
384 std::array<T, 3> Data{{a_Vec.
x, a_Vec.
y, a_Vec.
z}};
386 a_Formatter.writer() <<
'{';
387 fmt::format_arg(a_Formatter, a_FormatStr, fmt::join(Data.cbegin(), Data.cend(),
", "));
388 a_Formatter.writer() <<
'}';
414 template <
typename What>
422 size_t Hash =
static_cast<size_t>(a_Vector.
y);
424 Hash ^=
static_cast<size_t>(a_Vector.
x);
425 Hash ^=
static_cast<size_t>(a_Vector.
z) << 8;
434 template <
typename T>
437 template <
typename T>
Vector3< T > operator+(const Vector3< T > &a_Rhs) const
bool operator>(const Vector3< T > &a_Rhs) const
Vector3< int > Floor(void) const
Returns a new Vector3i with coords set to std::floor() of this vector's coords.
T Dot(const Vector3< T > &a_Rhs) const
Vector3(T a_x, T a_y, T a_z)
bool Equals(const Vector3< T > &a_Rhs) const
#define TOLUA_TEMPLATE_BIND(x)
void TurnCCW(void)
Rotates the vector 90 degrees counterclockwise around the vertical axis.
Vector3< T > addedXZ(T a_AddX, T a_AddZ) const
Returns a copy of this vector moved by the specified amount on the X and Z axes.
Vector3< float > Vector3f
Vector3(const Vector3< U > &a_Rhs)
void operator+=(const Vector3< T > &a_Rhs)
void Move(T a_X, T a_Y, T a_Z)
bool HasNonZeroLength(void) const
void Set(T a_x, T a_y, T a_z)
void Move(const Vector3< T > &a_Diff)
std::vector< Vector3i > cVector3iArray
Vector3< T > addedY(T a_AddY) const
Returns a copy of this vector moved by the specified amount on the y axis.
static const double NO_INTERSECTION
Return value of LineCoeffToPlane() if the line is parallel to the plane.
Vector3< T > addedX(T a_AddX) const
Returns a copy of this vector moved by the specified amount on the X axis.
Vector3< T > operator*(const Vector3< T > &a_Rhs) const
void Clamp(T a_Min, T a_Max)
Clamps each coord into the specified range.
bool operator!=(const Vector3< T > &a_Rhs) const
Vector3< T > operator/(const Vector3< T > &a_Rhs)
double Length(void) const
Vector3< double > Vector3d
bool operator==(const Vector3< T > &a_Rhs) const
Vector3< T > Cross(const Vector3< T > &a_Rhs) const
Vector3< T > addedZ(T a_AddZ) const
Returns a copy of this vector moved by the specified amount on the Z axis.
void operator-=(const Vector3< T > &a_Rhs)
double LineCoeffToYZPlane(const Vector3< T > &a_OtherEnd, T a_X) const
Returns the coefficient for the (a_OtherEnd - this) line to reach the specified X coord...
double LineCoeffToXZPlane(const Vector3< T > &a_OtherEnd, T a_Y) const
Returns the coefficient for the (a_OtherEnd - this) line to reach the specified Y coord...
double SqrLength(void) const
void operator*=(const Vector3< T > &a_Rhs)
static const double EPS
The max difference between two coords for which the coords are assumed equal.
double LineCoeffToXYPlane(const Vector3< T > &a_OtherEnd, T a_Z) const
Returns the coefficient for the (a_OtherEnd - this) line to reach the specified Z coord...
void NormalizeCopy(Vector3< T > &a_Rhs) const
Sets the given vector to the normalized version of this vector.
size_t operator()(const Vector3< What > &a_Vector) const
Provides a hash of a vector's contents.
Vector3< T > NormalizeCopy(void) const
void TurnCW(void)
Rotates the vector 90 degrees clockwise around the vertical axis.
friend void format_arg(fmt::BasicFormatter< char, ArgFormatter > &a_Formatter, const char *&a_FormatStr, Vector3 a_Vec)
Allows formatting a Vector<T> using the same format specifiers as for T e.g.
void Abs()
Updates each coord to its absolute value.
std::enable_if< std::is_arithmetic< T >::value, C >::type FloorC(T a_Value)
Floors a value, then casts it to C (an int by default)
Vector3< T > operator-(void) const
bool EqualsEps(const Vector3< T > &a_Rhs, T a_Eps) const