43 template<
typename Type>
46 template<
typename Type>
49 template<
typename Type>
52 template<
typename Type>
55 template<
typename Type>
58 template<
typename Type>
61 template<
typename Type>
64 template<
typename Type>
74 template<
typename Type>
80 union { Type
x; Type
s; Type
r; };
81 union { Type
y; Type
t; Type
g; };
82 union { Type
z; Type
u; Type
b; };
85 explicit Vec3(
const Type &scalar) :
x(scalar),
y(scalar),
z(scalar) { }
93 explicit Vec3(
const Type &p1,
const Type &p2,
const Type &p3) :
x(p1),
y(p2),
z(p3) { }
94 explicit Vec3(
const Type *array_xyz) :
x(array_xyz[0]),
y(array_xyz[1]),
z(array_xyz[2]) { }
106 static Type
dot(
const Vec3<Type>& vector1,
const Vec3<Type>& vector2) {
return vector1.x*vector2.x + vector1.y*vector2.y + vector1.z*vector2.z; }
142 Type diff_x = second.x - first.x; Type diff_y = second.y - first.y; Type diff_z = second.z - first.z;
143 return (diff_x >= -epsilon && diff_x <= epsilon && diff_y >= -epsilon && diff_y <= epsilon && diff_z >= -epsilon && diff_z <= epsilon );
259 bool operator < (
const Vec3<Type>& vector)
const {
return z < vector.z || (
z == vector.z && (
y < vector.y || (
y == vector.y &&
x < vector.x))); }
264 template<
typename Type>
268 template<
typename Type>
272 template<
typename Type>
276 template<
typename Type>
280 template<
typename Type>
284 template<
typename Type>
288 template<
typename Type>
292 template<
typename Type>
296 template<
typename Type>
300 template<
typename Type>
304 template<
typename Type>
308 template<
typename Type>
313 template<
typename Type>
317 matrix[0*3+0]*
v.x + matrix[0*3+1]*
v.y + matrix[0*3+2]*
v.z,
318 matrix[1*3+0]*
v.x + matrix[1*3+1]*
v.y + matrix[1*3+2]*
v.z,
319 matrix[2*3+0]*
v.x + matrix[2*3+1]*
v.y + matrix[2*3+2]*
v.z);
324 template<
typename Type>
328 matrix[0*3+0]*
v.x + matrix[1*3+0]*
v.y + matrix[2*3+0]*
v.z,
329 matrix[0*3+1]*
v.x + matrix[1*3+1]*
v.y + matrix[2*3+1]*
v.z,
330 matrix[0*3+2]*
v.x + matrix[1*3+2]*
v.y + matrix[2*3+2]*
v.z);
405 template<
typename Type>
414 template<
typename Type>
417 template<
typename Type>
bool operator<(const Vec3< Type > &vector) const
< operator.
Definition: vec3.h:259
Type x
Definition: vec4.h:80
Vec3< float > Vec3f
Definition: vec3.h:426
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:140
Vec3< int > Vec3i
Definition: vec3.h:425
void operator-=(const Vec3< Type > &vector)
-= operator.
Definition: vec3.h:229
Vec3< double > Vec3d
Definition: vec3.h:427
Vec3(const Vec3< int > ©)
Type y
Definition: vec2.h:81
Vec3< Type > & operator=(const Vec3< Type > &vector)
= operator.
Definition: vec3.h:250
Type g
Definition: vec3.h:81
void operator+=(const Vec3< Type > &vector)
+= operator.
Definition: vec3.h:223
Vec2< Type > operator+(const Vec2< Type > &v1, const Vec2< Type > &v2)
operator.
Definition: vec2.h:276
bool is_equal(const Vec3< Type > &other, Type epsilon) const
Returns true if equal within the bounds of an epsilon.
Definition: vec3.h:215
Type length() const
Returns the length (magnitude) of this vector.
Definition: vec3.h:406
Vec3< unsigned int > Vec3ui
Definition: vec3.h:424
Vec3< Type > & normalize()
Normalizes this vector.
Definition: vec3.h:415
Vec3< Type > & cross(const Vec3< Type > &vector)
Calculate the cross product between this vector and an other vector.
Vec3< Type > & rotate(const Angle &angle, const Vec3< Type > &axis)
Rotate this vector around an axis. Same as glRotate[f|d](angle, a);.
Type x
Definition: vec2.h:80
Vec3(const Type *array_xyz)
Definition: vec3.h:94
Vec3< Type > & round()
Rounds all components on this vector.
Type z
Definition: vec4.h:82
void operator/=(const Vec3< Type > &vector)
/= operator.
Definition: vec3.h:244
Vec3(const Vec3< float > ©)
Vec2< Type > operator/(const Vec2< Type > &v1, const Vec2< Type > &v2)
/ operator.
Definition: vec2.h:312
Angle class.
Definition: angle.h:63
static Vec3< Type > reflect(const Vec3< Type > &incident, const Vec3< Type > &normal)
Calculate the reflection direction for an incident vector.
Vec3()
Definition: vec3.h:84
Vec2< Type > operator*(const Vec2< Type > &v1, const Vec2< Type > &v2)
operator.
Definition: vec2.h:300
Type s
Definition: vec3.h:80
static Vec3< Type > normalize(const Vec3< Type > &vector)
Normalizes a vector.
Definition: vec3.h:418
2D vector
Definition: line.h:48
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);.
Vec3< char > Vec3b
Definition: vec3.h:421
Vec3(const Type &scalar)
Definition: vec3.h:85
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:238
@ length
value is a keyword
Type r
Definition: vec3.h:80
Vec3< unsigned short > Vec3us
Definition: vec3.h:422
static Type dot(const Vec3< Type > &vector1, const Vec3< Type > &vector2)
Dot products between two vectors.
Definition: vec3.h:106
Type dot(const Vec3< Type > &vector) const
Dot products this vector with an other vector.
Definition: vec3.h:168
bool operator!=(const Vec3< Type > &vector) const
!= operator.
Definition: vec3.h:256
static Vec3< Type > round(const Vec3< Type > &vector)
Rounds all components on a vector.
Angle angle(const Vec3< Type > &vector) const
Calculate the angle between this vector and an other vector.
4D vector
Definition: size.h:47
Vec3(const Vec2< Type > ©, const Type &p3)
Definition: vec3.h:86
Vec3(const Type &p1, const Type &p2, const Type &p3)
Definition: vec3.h:93
Type y
Definition: vec4.h:81
Vec3(const Vec4< Type > ©)
Definition: vec3.h:87
Vec2< Type > operator-(const Vec2< Type > &v1, const Vec2< Type > &v2)
operator.
Definition: vec2.h:288
Type u
Definition: vec3.h:82
Vec3< short > Vec3s
Definition: vec3.h:423
3D matrix
Definition: mat2.h:48
Type b
Definition: vec3.h:82
Vec3(const Vec3< double > ©)
Type t
Definition: vec3.h:81
static Vec3< Type > cross(const Vec3< Type > &vector1, const Vec3< Type > &vector2)
Calculate the cross product between two vectors.
Type datatype
Definition: vec3.h:78
Type x
Definition: vec3.h:80
Type distance(const Vec3< Type > &vector) const
Calculate the distance between this vector and an other vector.
Type z
Definition: vec3.h:82
Vec3< unsigned char > Vec3ub
Definition: vec3.h:420
bool operator==(const Vec3< Type > &vector) const
== operator.
Definition: vec3.h:253
Type y
Definition: vec3.h:81
Vec3< Type > operator-() const
operator.
Definition: vec3.h:235