Eule::Vector3< T > Class Template Reference

Representation of a 3d vector. More...

`#include <Matrix4x4.h>`

Collaboration diagram for Eule::Vector3< T >:
[legend]

## Public Member Functions

| Vector3 ()
| Vector3 (T _x, T _y, T _z)
| Vector3 (const Vector3< T > &other)=default
| Vector3 (Vector3< T > &&other) noexcept=default
double | DotProduct (const Vector3< T > &other) const
| Will compute the dot product to another Vector3. More...
Vector3< double > | CrossProduct (const Vector3< T > &other) const
| Will compute the cross product to another Vector3. More...
double | SqrMagnitude () const
| Will compute the square magnitude. More...
double | Magnitude () const
| Will compute the magnitude. More...
Vector3< double > | Normalize () const
| Will return the normalization of this vector. More...
void | NormalizeSelf ()
| Will normalize this vector. More...
Vector3< T > | VectorScale (const Vector3< T > &scalar) const
| Will scale self.n by scalar.n. More...
void | LerpSelf (const Vector3< T > &other, double t)
| Will lerp itself towards other by t. More...
Vector3< double > | Lerp (const Vector3< T > &other, double t) const
| Will return a lerp result between this and another vector. More...
bool | Similar (const Vector3< T > &other, double epsilon=0.00001) const
| Will compare if two vectors are similar to a certain epsilon value. More...
Vector3< int > | ToInt () const
| Will convert this vector to a Vector3i. More...
Vector3< double > | ToDouble () const
| Will convert this vector to a Vector3d. More...
T & | operator[] (std::size_t idx)
const T & | operator[] (std::size_t idx) const
Vector3< T > | operator+ (const Vector3< T > &other) const
void | operator+= (const Vector3< T > &other)
Vector3< T > | operator- (const Vector3< T > &other) const
void | operator-= (const Vector3< T > &other)
Vector3< T > | operator* (const T scale) const
void | operator*= (const T scale)
Vector3< T > | operator/ (const T scale) const
void | operator/= (const T scale)
Vector3< T > | operator* (const Matrix4x4 &mat) const
void | operator*= (const Matrix4x4 &mat)
Vector3< T > | operator- () const
| operator Vector2< T > () const
| operator Vector4< T > () const
| Conversion method. More...
void | operator= (const Vector3< T > &other)
| Conversion method. More...
void | operator= (Vector3< T > &&other) noexcept
bool | operator== (const Vector3< T > &other) const
bool | operator!= (const Vector3< T > &other) const

## Public Attributes

T | x
T | y
T | z

## Static Public Attributes

static const Vector3< double > | up
static const Vector3< double > | down
static const Vector3< double > | right
static const Vector3< double > | left
static const Vector3< double > | forward
static const Vector3< double > | backward
static const Vector3< double > | one
static const Vector3< double > | zero

## Friends

std::ostream & | operator<< (std::ostream &os, const Vector3< T > &v)
std::wostream & | operator<< (std::wostream &os, const Vector3< T > &v)

## Detailed Description

### template<typename T>
class Eule::Vector3< T >

Representation of a 3d vector.

Contains a lot of utility methods.

Definition at line 9 of file Matrix4x4.h.

## Constructor & Destructor Documentation

## Vector3() [1/4]

template<typename T >

Eule::Vector3< T >::Vector3 | ( |  | ) |

inline

Definition at line 20 of file Vector3.h.

: x{ 0 }, y{ 0 }, z{ 0 } {}

## Vector3() [2/4]

template<typename T >

Eule::Vector3< T >::Vector3 | ( | T | _x,
|  | T | _y,
|  | T | _z
| ) |  |

inline

Definition at line 21 of file Vector3.h.

: x{ _x }, y{ _y }, z{ _z } {}

## Vector3() [3/4]

template<typename T >

Eule::Vector3< T >::Vector3 | ( | const Vector3< T > & | other | ) |

default

## Vector3() [4/4]

template<typename T >

Eule::Vector3< T >::Vector3 | ( | Vector3< T > && | other | ) |

defaultnoexcept

## Member Function Documentation

## CrossProduct()

template<typename T >

Vector3< double > Vector3::CrossProduct | ( | const Vector3< T > & | other | ) | const

Will compute the cross product to another Vector3.

Definition at line 68 of file Vector3.cpp.

{
Vector3<double> cp;
cp.x = ((double)y * (double)other.z) - ((double)z * (double)other.y);
cp.y = ((double)z * (double)other.x) - ((double)x * (double)other.z);
cp.z = ((double)x * (double)other.y) - ((double)y * (double)other.x);
return cp;
}

## DotProduct()

template<typename T >

double Vector3::DotProduct | ( | const Vector3< T > & | other | ) | const

Will compute the dot product to another Vector3.

Definition at line 48 of file Vector3.cpp.

{
int iDot = (x * other.x) + (y * other.y) + (z * other.z);
return (double)iDot;
}

## Lerp()

template<typename T >

Vector3< double > Vector3::Lerp | ( | const Vector3< T > & | other,
|  | double | t
| ) |  | const

Will return a lerp result between this and another vector.

Definition at line 330 of file Vector3.cpp.

{
Vector3d copy(this->ToDouble());
copy.LerpSelf(other.ToDouble(), t);
return copy;
}

## LerpSelf()

template<typename T >

void Vector3::LerpSelf | ( | const Vector3< T > & | other,
|  | double | t
| ) |  |

Will lerp itself towards other by t.

Definition at line 311 of file Vector3.cpp.

{
const double it = 1.0 - t; // Inverse t
x = (int)(it * (double)x + t * (double)other.x);
y = (int)(it * (double)y + t * (double)other.y);
z = (int)(it * (double)z + t * (double)other.z);
return;
}

## Magnitude()

template<typename T >

double Vector3::Magnitude

Will compute the magnitude.

Definition at line 95 of file Vector3.cpp.

{
return sqrt(SqrMagnitude());
}

## Normalize()

template<typename T >

Vector3< double > Vector3::Normalize

Will return the normalization of this vector.

Definition at line 147 of file Vector3.cpp.

{
Vector3<double> norm(x, y, z);
norm.NormalizeSelf();
return norm;
}

## NormalizeSelf()

template<typename T >

void Vector3::NormalizeSelf | ( |  | ) |

Will normalize this vector.

Definition at line 200 of file Vector3.cpp.

{
std::cerr << "Stop normalizing int-vectors!!" << std::endl;
x = 0;
y = 0;
z = 0;
return;
}

## operator Vector2< T >()

template<typename T >

Vector3::operator Vector2< T >

Definition at line 873 of file Vector3.cpp.

{
return Vector2<T>(x, y);
}

## operator Vector4< T >()

template<typename T >

Vector3::operator Vector4< T >

Conversion method.

Definition at line 879 of file Vector3.cpp.

{
return Vector4<T>(x, y, z, 0);
}

## operator!=()

template<typename T >

bool Vector3::operator!= | ( | const Vector3< T > & | other | ) | const

Definition at line 864 of file Vector3.cpp.

{
return !operator==(other);
}

## operator*() [1/2]

template<typename T >

Vector3< int > Vector3::operator* | ( | const Matrix4x4 & | mat | ) | const

Definition at line 731 of file Vector3.cpp.

{
Vector3<double> newVec;
// Rotation, Scaling
newVec.x = ((mat[0][0] * x) + (mat[1][0] * y) + (mat[2][0] * z));
newVec.y = ((mat[0][1] * x) + (mat[1][1] * y) + (mat[2][1] * z));
newVec.z = ((mat[0][2] * x) + (mat[1][2] * y) + (mat[2][2] * z));
// Translation
newVec.x += mat[0][3];
newVec.y += mat[1][3];
newVec.z += mat[2][3];
return Vector3<int>(
(int)newVec.x,
(int)newVec.y,
(int)newVec.z
);
}

## operator*() [2/2]

template<typename T >

Vector3< T > Vector3::operator* | ( | const T | scale | ) | const

Definition at line 541 of file Vector3.cpp.

{
return Vector3<T>(
x * scale,
y * scale,
z * scale
);
}

## operator*=() [1/2]

template<typename T >

void Vector3::operator*= | ( | const Matrix4x4 & | mat | ) |

Definition at line 836 of file Vector3.cpp.

{
Vector3<double> buffer(x, y, z);
x = (int)((mat[0][0] * buffer.x) + (mat[0][1] * buffer.y) + (mat[0][2] * buffer.z));
y = (int)((mat[1][0] * buffer.x) + (mat[1][1] * buffer.y) + (mat[1][2] * buffer.z));
z = (int)((mat[2][0] * buffer.x) + (mat[2][1] * buffer.y) + (mat[2][2] * buffer.z));
// Translation
x += (int)mat[0][3];
y += (int)mat[1][3];
z += (int)mat[2][3];
return;
}

## operator*=() [2/2]

template<typename T >

void Vector3::operator*= | ( | const T | scale | ) |

Definition at line 583 of file Vector3.cpp.

{
x *= scale;
y *= scale;
z *= scale;
return;
}

## operator+()

template<typename T >

Vector3< T > Vector3::operator+ | ( | const Vector3< T > & | other | ) | const

Definition at line 372 of file Vector3.cpp.

{
return Vector3<T>(
x + other.x,
y + other.y,
z + other.z
);
}

## operator+=()

template<typename T >

void Vector3::operator+= | ( | const Vector3< T > & | other | ) |

Definition at line 414 of file Vector3.cpp.

{
x += other.x;
y += other.y;
z += other.z;
return;
}

## operator-() [1/2]

template<typename T >

Vector3< T > Vector3::operator-

Definition at line 806 of file Vector3.cpp.

{
return Vector3<T>(
-x,
-y,
-z
);
}

## operator-() [2/2]

template<typename T >

Vector3< T > Vector3::operator- | ( | const Vector3< T > & | other | ) | const

Definition at line 456 of file Vector3.cpp.

{
return Vector3<T>(
x - other.x,
y - other.y,
z - other.z
);
}

## operator-=()

template<typename T >

void Vector3::operator-= | ( | const Vector3< T > & | other | ) |

Definition at line 498 of file Vector3.cpp.

{
x -= other.x;
y -= other.y;
z -= other.z;
return;
}

## operator/()

template<typename T >

Vector3< T > Vector3::operator/ | ( | const T | scale | ) | const

Definition at line 626 of file Vector3.cpp.

{
return Vector3<T>(
x / scale,
y / scale,
z / scale
);
}

## operator/=()

template<typename T >

void Vector3::operator/= | ( | const T | scale | ) |

Definition at line 667 of file Vector3.cpp.

{
x /= scale;
y /= scale;
z /= scale;
return;
}

## operator=() [1/2]

template<typename T >

void Vector3::operator= | ( | const Vector3< T > & | other | ) |

Conversion method.

Definition at line 816 of file Vector3.cpp.

{
x = other.x;
y = other.y;
z = other.z;
return;
}

## operator=() [2/2]

template<typename T >

void Vector3::operator= | ( | Vector3< T > && | other | ) |

noexcept

Definition at line 826 of file Vector3.cpp.

{
x = std::move(other.x);
y = std::move(other.y);
z = std::move(other.z);
return;
}

## operator==()

template<typename T >

bool Vector3::operator== | ( | const Vector3< T > & | other | ) | const

Definition at line 855 of file Vector3.cpp.

{
return
(x == other.x) &&
(y == other.y) &&
(z == other.z);
}

## operator[]() [1/2]

template<typename T >

T & Vector3::operator[] | ( | std::size_t | idx | ) |

Definition at line 235 of file Vector3.cpp.

{
switch (idx)
{
case 0:
return x;
case 1:
return y;
case 2:
return z;
default:
throw std::out_of_range("Array descriptor on Vector3<T> out of range!");
}
}

## operator[]() [2/2]

template<typename T >

const T & Vector3::operator[] | ( | std::size_t | idx | ) | const

Definition at line 251 of file Vector3.cpp.

{
switch (idx)
{
case 0:
return x;
case 1:
return y;
case 2:
return z;
default:
throw std::out_of_range("Array descriptor on Vector3<T> out of range!");
}
}

## Similar()

template<typename T >

bool Vector3::Similar | ( | const Vector3< T > & | other,
|  | double | epsilon = `0.00001`
| ) |  | const

Will compare if two vectors are similar to a certain epsilon value.

Definition at line 213 of file Vector3.cpp.

{
return
(::Math::Similar(x, other.x, epsilon)) &&
(::Math::Similar(y, other.y, epsilon)) &&
(::Math::Similar(z, other.z, epsilon))
;
}

## SqrMagnitude()

template<typename T >

double Vector3::SqrMagnitude | ( |  | ) | const

Will compute the square magnitude.

Definition at line 88 of file Vector3.cpp.

{
int iSqrMag = x*x + y*y + z*z;
return (double)iSqrMag;
}

## ToDouble()

template<typename T >

Vector3< double > Vector3::ToDouble

Will convert this vector to a Vector3d.

Definition at line 229 of file Vector3.cpp.

{
return Vector3<double>((double)x, (double)y, (double)z);
}

## ToInt()

template<typename T >

Vector3< int > Vector3::ToInt

Will convert this vector to a Vector3i.

Definition at line 223 of file Vector3.cpp.

{
return Vector3<int>((int)x, (int)y, (int)z);
}

## VectorScale()

template<typename T >

Vector3< int > Vector3::VectorScale | ( | const Vector3< T > & | scalar | ) | const

Will scale self.n by scalar.n.

Definition at line 135 of file Vector3.cpp.

{
return Vector3<int>(
x * scalar.x,
y * scalar.y,
z * scalar.z
);
}

## Friends And Related Function Documentation

## operator<< [1/2]

template<typename T >

std::ostream& operator<< | ( | std::ostream & | os,
|  | const Vector3< T > & | v
| ) |  |

friend

Definition at line 85 of file Vector3.h.

{
return os << "[x: " << v.x << " y: " << v.y << " z: " << v.z << "]";
}

## operator<< [2/2]

template<typename T >

std::wostream& operator<< | ( | std::wostream & | os,
|  | const Vector3< T > & | v
| ) |  |

friend

Definition at line 89 of file Vector3.h.

{
return os << L"[x: " << v.x << L" y: " << v.y << L" z: " << v.z << L"]";
}

## Member Data Documentation

## backward

template<typename T >

const Vector3< double > Vector3::backward

static

Definition at line 104 of file Vector3.h.

## down

template<typename T >

const Vector3< double > Vector3::down

static

Definition at line 100 of file Vector3.h.

## forward

template<typename T >

const Vector3< double > Vector3::forward

static

Definition at line 103 of file Vector3.h.

## left

template<typename T >

const Vector3< double > Vector3::left

static

Definition at line 102 of file Vector3.h.

## one

template<typename T >

const Vector3< double > Vector3::one

static

Definition at line 105 of file Vector3.h.

## right

template<typename T >

const Vector3< double > Vector3::right

static

Definition at line 101 of file Vector3.h.

## up

template<typename T >

const Vector3< double > Vector3::up

static

Definition at line 99 of file Vector3.h.

## x

template<typename T >

T Eule::Vector3< T >::x

Definition at line 94 of file Vector3.h.

## y

template<typename T >

T Eule::Vector3< T >::y

Definition at line 95 of file Vector3.h.

## z

template<typename T >

T Eule::Vector3< T >::z

Definition at line 96 of file Vector3.h.

## zero

template<typename T >

const Vector3< double > Vector3::zero

static

Definition at line 106 of file Vector3.h.

The documentation for this class was generated from the following files:

- Eule/Matrix4x4.h
- Eule/Vector3.h
- Eule/Vector3.cpp

Eule::Vector3< double >
Eule::Vector3::ToDouble
Vector3< double > ToDouble() const
Will convert this vector to a Vector3d.
Definition: Vector3.cpp:229
Eule::Vector3::operator==
bool operator==(const Vector3< T > &other) const
Definition: Vector3.cpp:855
Eule::Vector3::z
T z
Definition: Vector3.h:96
Eule::Vector3::x
T x
Definition: Vector3.h:94
Eule::Vector2
Representation of a 2d vector.
Definition: Vector2.h:14
Eule::Vector3::SqrMagnitude
double SqrMagnitude() const
Will compute the square magnitude.
Definition: Vector3.cpp:88
Eule::Math::Similar
static constexpr bool Similar(const double a, const double b, const double epsilon=0.00001)
Compares two double values with a given accuracy.
Eule::Vector3::y
T y
Definition: Vector3.h:95
Eule::Vector4
Representation of a 4d vector.
Definition: Vector2.h:8