Eule::Vector4< T > Class Template Reference

Representation of a 4d vector. More...

`#include <Vector2.h>`

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

## Public Member Functions

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

## Public Attributes

T | x
T | y
T | z
T | w

## Static Public Attributes

static const Vector4< double > | up
static const Vector4< double > | down
static const Vector4< double > | right
static const Vector4< double > | left
static const Vector4< double > | forward
static const Vector4< double > | backward
static const Vector4< double > | future
static const Vector4< double > | past
static const Vector4< double > | one
static const Vector4< double > | zero

## Friends

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

## Detailed Description

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

Representation of a 4d vector.

Contains a lot of utility methods.

Definition at line 8 of file Vector2.h.

## Constructor & Destructor Documentation

## Vector4() [1/4]

template<typename T >

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

inline

Definition at line 20 of file Vector4.h.

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

## Vector4() [2/4]

template<typename T >

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

inline

Definition at line 21 of file Vector4.h.

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

## Vector4() [3/4]

template<typename T >

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

default

## Vector4() [4/4]

template<typename T >

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

defaultnoexcept

## Member Function Documentation

## Lerp()

template<typename T >

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

Will return a lerp result between this and another vector.

Definition at line 287 of file Vector4.cpp.

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

## LerpSelf()

template<typename T >

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

Will lerp itself towards other by t.

Definition at line 267 of file Vector4.cpp.

{
const double it = 1.0 - 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);
w = (int)(it * (double)w + t * (double)other.w);
return;
}

## Magnitude()

template<typename T >

double Vector4::Magnitude

Will compute the magnitude.

Definition at line 38 of file Vector4.cpp.

{
return sqrt(SqrMagnitude());
}

## Normalize()

template<typename T >

Vector4< double > Vector4::Normalize

Will return the normalization of this vector.

Definition at line 92 of file Vector4.cpp.

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

## NormalizeSelf()

template<typename T >

void Vector4::NormalizeSelf | ( |  | ) |

Will normalize this vector.

Definition at line 148 of file Vector4.cpp.

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

## operator Vector2< T >()

template<typename T >

Vector4::operator Vector2< T >

Definition at line 775 of file Vector4.cpp.

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

## operator Vector3< T >()

template<typename T >

Vector4::operator Vector3< T >

Conversion method.

Definition at line 781 of file Vector4.cpp.

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

## operator!=()

template<typename T >

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

Definition at line 767 of file Vector4.cpp.

{
return !operator==(other);
}

## operator*() [1/2]

template<typename T >

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

Definition at line 684 of file Vector4.cpp.

{
Vector4<double> newVec;
newVec.x = (mat[0][0] * x) + (mat[0][1] * y) + (mat[0][2] * z) + (mat[0][3] * w);
newVec.y = (mat[1][0] * x) + (mat[1][1] * y) + (mat[1][2] * z) + (mat[1][3] * w);
newVec.z = (mat[2][0] * x) + (mat[2][1] * y) + (mat[2][2] * z) + (mat[2][3] * w);
newVec.w = (mat[3][0] * x) + (mat[3][1] * y) + (mat[3][2] * z) + (mat[3][3] * w);
return Vector4<int>(
(int)newVec.x,
(int)newVec.y,
(int)newVec.z,
(int)newVec.w
);
}

## operator*() [2/2]

template<typename T >

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

Definition at line 512 of file Vector4.cpp.

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

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

template<typename T >

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

Definition at line 752 of file Vector4.cpp.

{
Vector4<double> buffer(x, y, z, w);
// Should this still be reversed...? like, instead of mat[x][y], use mat[y][m]
// idk right now. check that if something doesn't work
x = (int)((mat[0][0] * buffer.x) + (mat[0][1] * buffer.y) + (mat[0][2] * buffer.z) + (mat[0][3] * buffer.w));
y = (int)((mat[1][0] * buffer.x) + (mat[1][1] * buffer.y) + (mat[1][2] * buffer.z) + (mat[1][3] * buffer.w));
z = (int)((mat[2][0] * buffer.x) + (mat[2][1] * buffer.y) + (mat[2][2] * buffer.z) + (mat[2][3] * buffer.w));
w = (int)((mat[3][0] * buffer.x) + (mat[3][1] * buffer.y) + (mat[3][2] * buffer.z) + (mat[3][3] * buffer.w));
return;
}

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

template<typename T >

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

Definition at line 557 of file Vector4.cpp.

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

## operator+()

template<typename T >

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

Definition at line 331 of file Vector4.cpp.

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

## operator+=()

template<typename T >

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

Definition at line 376 of file Vector4.cpp.

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

## operator-() [1/2]

template<typename T >

Vector4< T > Vector4::operator-

Definition at line 719 of file Vector4.cpp.

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

## operator-() [2/2]

template<typename T >

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

Definition at line 421 of file Vector4.cpp.

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

## operator-=()

template<typename T >

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

Definition at line 466 of file Vector4.cpp.

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

## operator/()

template<typename T >

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

Definition at line 603 of file Vector4.cpp.

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

## operator/=()

template<typename T >

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

Definition at line 647 of file Vector4.cpp.

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

## operator=() [1/2]

template<typename T >

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

Conversion method.

Definition at line 730 of file Vector4.cpp.

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

## operator=() [2/2]

template<typename T >

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

noexcept

Definition at line 741 of file Vector4.cpp.

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

## operator==()

template<typename T >

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

Definition at line 659 of file Vector4.cpp.

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

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

template<typename T >

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

Definition at line 185 of file Vector4.cpp.

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

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

template<typename T >

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

Definition at line 203 of file Vector4.cpp.

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

## Similar()

template<typename T >

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

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

Definition at line 162 of file Vector4.cpp.

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

## SqrMagnitude()

template<typename T >

double Vector4::SqrMagnitude | ( |  | ) | const

Will compute the square magnitude.

Definition at line 31 of file Vector4.cpp.

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

## ToDouble()

template<typename T >

Vector4< double > Vector4::ToDouble

Will convert this vector to a Vector4d.

Definition at line 179 of file Vector4.cpp.

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

## ToInt()

template<typename T >

Vector4< int > Vector4::ToInt

Will convert this vector to a Vector4i.

Definition at line 173 of file Vector4.cpp.

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

## VectorScale()

template<typename T >

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

Will scale self.n by scalar.n.

Definition at line 79 of file Vector4.cpp.

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

## Friends And Related Function Documentation

## operator<< [1/2]

template<typename T >

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

friend

Definition at line 79 of file Vector4.h.

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

## operator<< [2/2]

template<typename T >

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

friend

Definition at line 83 of file Vector4.h.

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

## Member Data Documentation

## backward

template<typename T >

const Vector4< double > Vector4::backward

static

Definition at line 99 of file Vector4.h.

## down

template<typename T >

const Vector4< double > Vector4::down

static

Definition at line 95 of file Vector4.h.

## forward

template<typename T >

const Vector4< double > Vector4::forward

static

Definition at line 98 of file Vector4.h.

## future

template<typename T >

const Vector4< double > Vector4::future

static

Definition at line 100 of file Vector4.h.

## left

template<typename T >

const Vector4< double > Vector4::left

static

Definition at line 97 of file Vector4.h.

## one

template<typename T >

const Vector4< double > Vector4::one

static

Definition at line 102 of file Vector4.h.

## past

template<typename T >

const Vector4< double > Vector4::past

static

Definition at line 101 of file Vector4.h.

## right

template<typename T >

const Vector4< double > Vector4::right

static

Definition at line 96 of file Vector4.h.

## up

template<typename T >

const Vector4< double > Vector4::up

static

Definition at line 94 of file Vector4.h.

## w

template<typename T >

T Eule::Vector4< T >::w

Definition at line 91 of file Vector4.h.

## x

template<typename T >

T Eule::Vector4< T >::x

Definition at line 88 of file Vector4.h.

## y

template<typename T >

T Eule::Vector4< T >::y

Definition at line 89 of file Vector4.h.

## z

template<typename T >

T Eule::Vector4< T >::z

Definition at line 90 of file Vector4.h.

## zero

template<typename T >

const Vector4< double > Vector4::zero

static

Definition at line 103 of file Vector4.h.

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

- Eule/Vector2.h
- Eule/Vector4.h
- Eule/Vector4.cpp

Eule::Vector3
Representation of a 3d vector.
Definition: Matrix4x4.h:9
Eule::Vector4::x
T x
Definition: Vector4.h:88
Eule::Vector4::z
T z
Definition: Vector4.h:90
Eule::Vector4::w
T w
Definition: Vector4.h:91
Eule::Vector4::ToDouble
Vector4< double > ToDouble() const
Will convert this vector to a Vector4d.
Definition: Vector4.cpp:179
Eule::Vector2
Representation of a 2d vector.
Definition: Vector2.h:14
Eule::Vector4::operator==
bool operator==(const Vector4< T > &other) const
Definition: Vector4.cpp:659
Eule::Vector4::SqrMagnitude
double SqrMagnitude() const
Will compute the square magnitude.
Definition: Vector4.cpp:31
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::Vector4::y
T y
Definition: Vector4.h:89
Eule::Vector4< double >