Leonetienne/Eule
Homemade math library, mainly targetted towards computer graphics
Public Member Functions | Public Attributes | Static Public Attributes | Friends | List of all members
Eule::Vector4< T > Class Template Reference

Representation of a 4d vector. More...

#include <Vector2.h>

Collaboration diagram for Eule::Vector4< T >:
Collaboration graph
[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

x
 
y
 
z
 
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.

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

◆ Vector4() [2/4]

template<typename T >
Eule::Vector4< T >::Vector4 ( _x,
_y,
_z,
_w 
)
inline

Definition at line 21 of file Vector4.h.

21 : 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.

288 {
289  Vector4d copy(this->ToDouble());
290  copy.LerpSelf(other.ToDouble(), t);
291 
292  return copy;
293 }

◆ 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.

268 {
269  const double it = 1.0 - t;
270 
271  x = (int)(it * (double)x + t * (double)other.x);
272  y = (int)(it * (double)y + t * (double)other.y);
273  z = (int)(it * (double)z + t * (double)other.z);
274  w = (int)(it * (double)w + t * (double)other.w);
275 
276  return;
277 }

◆ Magnitude()

template<typename T >
double Vector4::Magnitude

Will compute the magnitude.

Definition at line 38 of file Vector4.cpp.

39 {
40  return sqrt(SqrMagnitude());
41 }

◆ Normalize()

template<typename T >
Vector4< double > Vector4::Normalize

Will return the normalization of this vector.

Definition at line 92 of file Vector4.cpp.

93 {
94  Vector4<double> norm(x, y, z, w);
95  norm.NormalizeSelf();
96 
97  return norm;
98 }

◆ NormalizeSelf()

template<typename T >
void Vector4::NormalizeSelf ( )

Will normalize this vector.

Definition at line 148 of file Vector4.cpp.

149 {
150  std::cerr << "Stop normalizing int-vectors!!" << std::endl;
151  x = 0;
152  y = 0;
153  z = 0;
154  w = 0;
155 
156  return;
157 }

◆ operator Vector2< T >()

template<typename T >
Vector4::operator Vector2< T >

Definition at line 775 of file Vector4.cpp.

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

◆ operator Vector3< T >()

template<typename T >
Vector4::operator Vector3< T >

Conversion method.

Definition at line 781 of file Vector4.cpp.

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

◆ operator!=()

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

Definition at line 767 of file Vector4.cpp.

768 {
769  return !operator==(other);
770 }

◆ operator*() [1/2]

template<typename T >
Vector4< int > Vector4::operator* ( const Matrix4x4 mat) const

Definition at line 684 of file Vector4.cpp.

685 {
686  Vector4<double> newVec;
687 
688  newVec.x = (mat[0][0] * x) + (mat[0][1] * y) + (mat[0][2] * z) + (mat[0][3] * w);
689  newVec.y = (mat[1][0] * x) + (mat[1][1] * y) + (mat[1][2] * z) + (mat[1][3] * w);
690  newVec.z = (mat[2][0] * x) + (mat[2][1] * y) + (mat[2][2] * z) + (mat[2][3] * w);
691  newVec.w = (mat[3][0] * x) + (mat[3][1] * y) + (mat[3][2] * z) + (mat[3][3] * w);
692 
693  return Vector4<int>(
694  (int)newVec.x,
695  (int)newVec.y,
696  (int)newVec.z,
697  (int)newVec.w
698  );
699 }

◆ operator*() [2/2]

template<typename T >
Vector4< T > Vector4::operator* ( const T  scale) const

Definition at line 512 of file Vector4.cpp.

513 {
514  return Vector4<T>(
515  x * scale,
516  y * scale,
517  z * scale,
518  w * scale
519  );
520 }

◆ operator*=() [1/2]

template<typename T >
void Vector4::operator*= ( const Matrix4x4 mat)

Definition at line 752 of file Vector4.cpp.

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

◆ operator*=() [2/2]

template<typename T >
void Vector4::operator*= ( const T  scale)

Definition at line 557 of file Vector4.cpp.

558 {
559  x *= scale;
560  y *= scale;
561  z *= scale;
562  w *= scale;
563  return;
564 }

◆ operator+()

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

Definition at line 331 of file Vector4.cpp.

332 {
333  return Vector4<T>(
334  x + other.x,
335  y + other.y,
336  z + other.z,
337  w + other.w
338  );
339 }

◆ operator+=()

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

Definition at line 376 of file Vector4.cpp.

377 {
378  x += other.x;
379  y += other.y;
380  z += other.z;
381  w += other.w;
382  return;
383 }

◆ operator-() [1/2]

template<typename T >
Vector4< T > Vector4::operator-

Definition at line 719 of file Vector4.cpp.

720 {
721  return Vector4<T>(
722  -x,
723  -y,
724  -z,
725  -w
726  );
727 }

◆ operator-() [2/2]

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

Definition at line 421 of file Vector4.cpp.

422 {
423  return Vector4<T>(
424  x - other.x,
425  y - other.y,
426  z - other.z,
427  w - other.w
428  );
429 }

◆ operator-=()

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

Definition at line 466 of file Vector4.cpp.

467 {
468  x -= other.x;
469  y -= other.y;
470  z -= other.z;
471  w -= other.w;
472  return;
473 }

◆ operator/()

template<typename T >
Vector4< T > Vector4::operator/ ( const T  scale) const

Definition at line 603 of file Vector4.cpp.

604 {
605  return Vector4<T>(
606  x / scale,
607  y / scale,
608  z / scale,
609  w / scale
610  );
611 }

◆ operator/=()

template<typename T >
void Vector4::operator/= ( const T  scale)

Definition at line 647 of file Vector4.cpp.

648 {
649  x /= scale;
650  y /= scale;
651  z /= scale;
652  w /= scale;
653  return;
654 }

◆ operator=() [1/2]

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

Conversion method.

Definition at line 730 of file Vector4.cpp.

731 {
732  x = other.x;
733  y = other.y;
734  z = other.z;
735  w = other.w;
736 
737  return;
738 }

◆ operator=() [2/2]

template<typename T >
void Vector4::operator= ( Vector4< T > &&  other)
noexcept

Definition at line 741 of file Vector4.cpp.

742 {
743  x = std::move(other.x);
744  y = std::move(other.y);
745  z = std::move(other.z);
746  w = std::move(other.w);
747 
748  return;
749 }

◆ operator==()

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

Definition at line 659 of file Vector4.cpp.

660 {
661  return
662  (x == other.x) &&
663  (y == other.y) &&
664  (z == other.z) &&
665  (w == other.w);
666 }

◆ operator[]() [1/2]

template<typename T >
T & Vector4::operator[] ( std::size_t  idx)

Definition at line 185 of file Vector4.cpp.

186 {
187  switch (idx)
188  {
189  case 0:
190  return x;
191  case 1:
192  return y;
193  case 2:
194  return z;
195  case 3:
196  return w;
197  default:
198  throw std::out_of_range("Array descriptor on Vector4<T> out of range!");
199  }
200 }

◆ operator[]() [2/2]

template<typename T >
const T & Vector4::operator[] ( std::size_t  idx) const

Definition at line 203 of file Vector4.cpp.

204 {
205  switch (idx)
206  {
207  case 0:
208  return x;
209  case 1:
210  return y;
211  case 2:
212  return z;
213  case 3:
214  return w;
215  default:
216  throw std::out_of_range("Array descriptor on Vector4<T> out of range!");
217  }
218 }

◆ 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.

163 {
164  return
165  (::Math::Similar(x, other.x, epsilon)) &&
166  (::Math::Similar(y, other.y, epsilon)) &&
167  (::Math::Similar(z, other.z, epsilon)) &&
168  (::Math::Similar(w, other.w, epsilon))
169  ;
170 }

◆ SqrMagnitude()

template<typename T >
double Vector4::SqrMagnitude ( ) const

Will compute the square magnitude.

Definition at line 31 of file Vector4.cpp.

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

◆ ToDouble()

template<typename T >
Vector4< double > Vector4::ToDouble

Will convert this vector to a Vector4d.

Definition at line 179 of file Vector4.cpp.

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

◆ ToInt()

template<typename T >
Vector4< int > Vector4::ToInt

Will convert this vector to a Vector4i.

Definition at line 173 of file Vector4.cpp.

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

◆ 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.

80 {
81  return Vector4<int>(
82  x * scalar.x,
83  y * scalar.y,
84  z * scalar.z,
85  w * scalar.w
86  );
87 }

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.

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

◆ 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.

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

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::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 >