34 #include "../api_core.h"
44 template<
typename Type>
47 template<
typename Type>
50 template<
typename Type>
53 template<
typename Type>
56 template<
typename Type>
59 template<
typename Type>
62 template<
typename Type>
65 template<
typename Type>
75 template<
typename Type>
81 union { Type
x; Type
s; Type
r; };
82 union { Type
y; Type
t; Type
g; };
83 union { Type
z; Type
u; Type
b; };
86 explicit Vec3(
const Type &scalar) :
x(scalar),
y(scalar),
z(scalar) { }
94 explicit Vec3(
const Type &p1,
const Type &p2,
const Type &p3) :
x(p1),
y(p2),
z(p3) { }
95 explicit Vec3(
const Type *array_xyz) :
x(array_xyz[0]),
y(array_xyz[1]),
z(array_xyz[2]) { }
107 static Type
dot(
const Vec3<Type>& vector1,
const Vec3<Type>& vector2) {
return vector1.x*vector2.x + vector1.y*vector2.y + vector1.z*vector2.z; }
143 Type diff_x = second.x - first.x; Type diff_y = second.y - first.y; Type diff_z = second.z - first.z;
144 return (diff_x >= -epsilon && diff_x <= epsilon && diff_y >= -epsilon && diff_y <= epsilon && diff_z >= -epsilon && diff_z <= epsilon );
260 bool operator < (const Vec3<Type>& vector)
const {
return z < vector.z || (
z == vector.z && (
y < vector.y || (
y == vector.y &&
x < vector.x))); }
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>
305 template<
typename Type>
309 template<
typename Type>
314 template<
typename Type>
318 matrix[0*3+0]*v.x + matrix[0*3+1]*v.y + matrix[0*3+2]*v.z,
319 matrix[1*3+0]*v.x + matrix[1*3+1]*v.y + matrix[1*3+2]*v.z,
320 matrix[2*3+0]*v.x + matrix[2*3+1]*v.y + matrix[2*3+2]*v.z);
325 template<
typename Type>
329 matrix[0*3+0]*v.x + matrix[1*3+0]*v.y + matrix[2*3+0]*v.z,
330 matrix[0*3+1]*v.x + matrix[1*3+1]*v.y + matrix[2*3+1]*v.z,
331 matrix[0*3+2]*v.x + matrix[1*3+2]*v.y + matrix[2*3+2]*v.z);
406 template<
typename Type>
415 template<
typename Type>
418 template<
typename Type>
Type t
Definition: vec3.h:82
Vec3(const Type &p1, const Type &p2, const Type &p3)
Definition: vec3.h:94
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:95
Angle angle(const Vec3< Type > &vector) const
Calculate the angle between this vector and an other vector.
Type x
Definition: vec3.h:81
Vec3< float > Vec3f
Definition: vec3.h:427
Angle class.
Definition: angle.h:63
Vec3< unsigned int > Vec3ui
Definition: vec3.h:425
Type y
Definition: vec3.h:82
Vec3< Type > & round()
Rounds all components on this vector.
Type z
Definition: vec4.h:83
Vec3< Type > & normalize()
Normalizes this vector.
Definition: vec3.h:416
void operator+=(const Vec3< Type > &vector)
+= operator.
Definition: vec3.h:224
Vec2< Type > operator/(const Vec2< Type > &v1, const Vec2< Type > &v2)
/ operator.
Definition: vec2.h:314
Type distance(const Vec3< Type > &vector) const
Calculate the distance between this vector and an other vector.
static Vec3< Type > reflect(const Vec3< Type > &incident, const Vec3< Type > &normal)
Calculate the reflection direction for an incident vector.
Vec3< unsigned char > Vec3ub
Definition: vec3.h:421
Type length() const
Returns the length (magnitude) of this vector.
Definition: vec3.h:407
Vec3(const Vec4< Type > ©)
Definition: vec3.h:88
void operator/=(const Vec3< Type > &vector)
/= operator.
Definition: vec3.h:245
Vec3()
Definition: vec3.h:85
Type u
Definition: vec3.h:83
Vec3< short > Vec3s
Definition: vec3.h:424
Type x
Definition: vec2.h:82
Vec3< int > Vec3i
Definition: vec3.h:426
void operator-=(const Vec3< Type > &vector)
-= operator.
Definition: vec3.h:230
Vec2< Type > operator+(const Vec2< Type > &v1, const Vec2< Type > &v2)
operator.
Definition: vec2.h:278
static Type dot(const Vec3< Type > &vector1, const Vec3< Type > &vector2)
Dot products between two vectors.
Definition: vec3.h:107
Type r
Definition: vec3.h:81
Vec3< unsigned short > Vec3us
Definition: vec3.h:423
Vec3< char > Vec3b
Definition: vec3.h:422
2D vector
Definition: line.h:49
3D matrix
Definition: mat2.h:49
Vec2< Type > operator*(const Vec2< Type > &v1, const Vec2< Type > &v2)
operator.
Definition: vec2.h:302
Type y
Definition: vec4.h:82
void operator*=(const Vec3< Type > &vector)
*= operator.
Definition: vec3.h:239
Vec3(const Vec2< Type > ©, const Type &p3)
Definition: vec3.h:87
Type s
Definition: vec3.h:81
Vec3< Type > operator-() const
operator.
Definition: vec3.h:236
bool operator!=(const Vec3< Type > &vector) const
!= operator.
Definition: vec3.h:257
Vec3< double > Vec3d
Definition: vec3.h:428
bool operator==(const Vec3< Type > &vector) const
== operator.
Definition: vec3.h:254
Vec3(const Type &scalar)
Definition: vec3.h:86
Type b
Definition: vec3.h:83
Type g
Definition: vec3.h:82
Type x
Definition: vec4.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);.
4D vector
Definition: size.h:48
Vec2< Type > operator-(const Vec2< Type > &v1, const Vec2< Type > &v2)
operator.
Definition: vec2.h:290
bool is_equal(const Vec3< Type > &other, Type epsilon) const
Returns true if equal within the bounds of an epsilon.
Definition: vec3.h:216
Type datatype
Definition: vec3.h:79
Vec3< Type > & operator=(const Vec3< Type > &vector)
= operator.
Definition: vec3.h:251
Type z
Definition: vec3.h:83
Angle angle_normed(const Vec3< Type > &vector) const
Calculate the angle between this vector and an other vector, where the vectors are unit vectors...
Type dot(const Vec3< Type > &vector) const
Dot products this vector with an other vector.
Definition: vec3.h:169
Type y
Definition: vec2.h:83
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:141