42 template<
typename Type>
45 template<
typename Type>
48 template<
typename Type>
51 template<
typename Type>
54 template<
typename Type>
57 template<
typename Type>
60 template<
typename Type>
63 template<
typename Type>
73 template<
typename Type>
79 union { Type
x; Type
s; Type
r; };
80 union { Type
y; Type
t; Type
g; };
81 union { Type
z; Type
u; Type
b; };
84 explicit Vec3(
const Type &scalar) :
x(scalar),
y(scalar),
z(scalar) {}
90 template<typename OtherType, typename std::enable_if_t<std::is_integral<Type>::value && !std::is_integral<OtherType>::value,
int> = 0>
91 Vec3(
const Vec3<OtherType>& copy) :
x(static_cast<Type>(std::floor(copy.
x + 0.5f))),
y(static_cast<Type>(std::floor(copy.
y + 0.5f))),
z(static_cast<Type>(std::floor(copy.
z + 0.5f))) {}
93 template<typename OtherType, typename std::enable_if_t<!std::is_integral<Type>::value || std::is_integral<OtherType>::value,
int> = 0>
96 explicit Vec3(
const Type &p1,
const Type &p2,
const Type &p3) :
x(p1),
y(p2),
z(p3) {}
97 explicit Vec3(
const Type *array_xyz) :
x(array_xyz[0]),
y(array_xyz[1]),
z(array_xyz[2]) {}
109 static Type
dot(
const Vec3<Type>& vector1,
const Vec3<Type>& vector2) {
return vector1.x*vector2.x + vector1.y*vector2.y + vector1.z*vector2.z; }
145 Type diff_x = second.x - first.x; Type diff_y = second.y - first.y; Type diff_z = second.z - first.z;
146 return (diff_x >= -epsilon && diff_x <= epsilon && diff_y >= -epsilon && diff_y <= epsilon && diff_z >= -epsilon && diff_z <= epsilon);
253 bool operator < (
const Vec3<Type>& vector)
const {
return z < vector.z || (
z == vector.z && (
y < vector.y || (
y == vector.y &&
x < vector.x))); }
257 template<
typename Type>
261 template<
typename Type>
265 template<
typename Type>
269 template<
typename Type>
273 template<
typename Type>
277 template<
typename Type>
281 template<
typename Type>
285 template<
typename Type>
289 template<
typename Type>
293 template<
typename Type>
297 template<
typename Type>
301 template<
typename Type>
306 template<
typename Type>
310 matrix[0 * 3 + 0] *
v.x + matrix[0 * 3 + 1] *
v.y + matrix[0 * 3 + 2] *
v.z,
311 matrix[1 * 3 + 0] *
v.x + matrix[1 * 3 + 1] *
v.y + matrix[1 * 3 + 2] *
v.z,
312 matrix[2 * 3 + 0] *
v.x + matrix[2 * 3 + 1] *
v.y + matrix[2 * 3 + 2] *
v.z);
317 template<
typename Type>
321 matrix[0 * 3 + 0] *
v.x + matrix[1 * 3 + 0] *
v.y + matrix[2 * 3 + 0] *
v.z,
322 matrix[0 * 3 + 1] *
v.x + matrix[1 * 3 + 1] *
v.y + matrix[2 * 3 + 1] *
v.z,
323 matrix[0 * 3 + 2] *
v.x + matrix[1 * 3 + 2] *
v.y + matrix[2 * 3 + 2] *
v.z);
326 template<
typename Type>
335 template<
typename Type>
338 template<
typename Type>
Angle class.
Definition angle.h:60
3D matrix
Definition vec4.h:55
2D vector
Definition vec4.h:43
3D vector
Definition vec4.h:46
bool operator!=(const Vec3< Type > &vector) const
!= operator.
Definition vec3.h:250
Type datatype
Definition vec3.h:77
Vec3< Type > & operator=(const Vec3< Type > &vector)=default
= operator.
Vec3(const Vec3< Type > ©)=default
bool is_equal(const Vec3< Type > &other, Type epsilon) const
Returns true if equal within the bounds of an epsilon.
Definition vec3.h:214
static bool is_equal(const Vec3< Type > &first, const Vec3< Type > &second, Type epsilon)
Returns true if equal within the bounds of an epsilon.
Definition vec3.h:143
Vec3< Type > operator-() const
operator.
Definition vec3.h:229
static Vec3< Type > cross(const Vec3< Type > &vector1, const Vec3< Type > &vector2)
Calculate the cross product between two vectors.
Vec3(const Type *array_xyz)
Definition vec3.h:97
Type s
Definition vec3.h:79
Vec3()
Definition vec3.h:83
Type r
Definition vec3.h:79
static Type dot(const Vec3< Type > &vector1, const Vec3< Type > &vector2)
Dot products between two vectors.
Definition vec3.h:109
Vec3< Type > & rotate(const Angle &angle, const Vec3< Type > &axis)
Rotate this vector around an axis. Same as glRotate[f|d](angle, a);.
static Vec3< Type > reflect(const Vec3< Type > &incident, const Vec3< Type > &normal)
Calculate the reflection direction for an incident vector.
static Vec3< Type > round(const Vec3< Type > &vector)
Rounds all components on a vector.
Vec3< Type > & round()
Rounds all components on this vector.
Vec3(const Type &p1, const Type &p2, const Type &p3)
Definition vec3.h:96
Vec3(const Type &scalar)
Definition vec3.h:84
Type z
Definition vec3.h:81
Type y
Definition vec3.h:80
Type g
Definition vec3.h:80
Type t
Definition vec3.h:80
bool operator<(const Vec3< Type > &vector) const
< operator.
Definition vec3.h:253
Angle angle_normed(const Vec3< Type > &vector) const
Calculate the angle between this vector and an other vector, where the vectors are unit vectors.
void operator-=(const Vec3< Type > &vector)
-= operator.
Definition vec3.h:223
void operator+=(const Vec3< Type > &vector)
+= operator.
Definition vec3.h:217
void operator/=(const Vec3< Type > &vector)
/= operator.
Definition vec3.h:238
Vec3< Type > & cross(const Vec3< Type > &vector)
Calculate the cross product between this vector and an other vector.
Vec3(const Vec4< Type > ©)
Definition vec3.h:86
Vec3(const Vec2< Type > ©, const Type &p3)
Definition vec3.h:85
Type u
Definition vec3.h:81
Type distance(const Vec3< Type > &vector) const
Calculate the distance between this vector and an other vector.
Type x
Definition vec3.h:79
Type b
Definition vec3.h:81
static Vec3< Type > rotate(const Vec3< Type > &vector, const Angle &angle, const Vec3< Type > &axis)
Rotate a vector around an axis. Same as glRotate[f|d](angle, a);.
bool operator==(const Vec3< Type > &vector) const
== operator.
Definition vec3.h:247
Angle angle(const Vec3< Type > &vector) const
Calculate the angle between this vector and an other vector.
Type dot(const Vec3< Type > &vector) const
Dot products this vector with an other vector.
Definition vec3.h:167
Vec3(const Vec3< OtherType > ©)
Definition vec3.h:91
void operator*=(const Vec3< Type > &vector)
*= operator.
Definition vec3.h:232
4D vector
Definition vec4.h:75
Vec2< Type > operator/(const Vec2< Type > &v1, const Vec2< Type > &v2)
/ operator.
Definition vec2.h:306
static Vec3< Type > normalize(const Vec3< Type > &vector)
Normalizes a vector.
Definition vec3.h:339
Vec3< unsigned char > Vec3ub
Definition vec3.h:341
Type length() const
Returns the length (magnitude) of this vector.
Definition vec3.h:327
Vec3< Type > & normalize()
Normalizes this vector.
Definition vec3.h:336
Vec3< unsigned short > Vec3us
Definition vec3.h:343
Vec3< unsigned int > Vec3ui
Definition vec3.h:345
Vec3< float > Vec3f
Definition vec3.h:347
Vec2< Type > operator-(const Vec2< Type > &v1, const Vec2< Type > &v2)
operator.
Definition vec2.h:282
Vec2< Type > operator+(const Vec2< Type > &v1, const Vec2< Type > &v2)
operator.
Definition vec2.h:270
Vec3< double > Vec3d
Definition vec3.h:348
Vec3< char > Vec3b
Definition vec3.h:342
Vec2< Type > operator*(const Vec2< Type > &v1, const Vec2< Type > &v2)
operator.
Definition vec2.h:294
Vec3< short > Vec3s
Definition vec3.h:344
Vec3< int > Vec3i
Definition vec3.h:346
@ length
value is a keyword