Vector4.h
Go to the documentation of this file.
#pragma once
#include <cstdlib>
#include <iomanip>
#include <ostream>
#include <sstream>
#include "Matrix4x4.h"
namespace Eule
{
template <typename T> class Vector2;
template <typename T> class Vector3;
template <typename T>
class Vector4
{
public:
Vector4() : x{ 0 }, y{ 0 }, z{ 0 }, w{ 0 } {}
Vector4(T _x, T _y, T _z, T _w) : x{ _x }, y{ _y }, z{ _z }, w{ _w } {}
Vector4(const Vector4<T>& other) = default;
Vector4(Vector4<T>&& other) noexcept = default;
double SqrMagnitude() const;
double Magnitude() const;
[[nodiscard]] Vector4<double> Normalize() const;
void NormalizeSelf();
[[nodiscard]] Vector4<T> VectorScale(const Vector4<T>& scalar) const;
void LerpSelf(const Vector4<T>& other, double t);
[[nodiscard]] Vector4<double> Lerp(const Vector4<T>& other, double t) const;
[[nodiscard]] bool Similar(const Vector4<T>& other, double epsilon = 0.00001) const;
[[nodiscard]] Vector4<int> ToInt() const;
[[nodiscard]] Vector4<double> ToDouble() const;
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;
void operator=(const Vector4<T>& other);
void operator=(Vector4<T>&& other) noexcept;
bool operator==(const Vector4<T>& other) const;
bool operator!=(const Vector4<T>& other) const;
friend std::ostream& operator << (std::ostream& os, const Vector4<T>& v)
{
return os << "[x: " << v.x << " y: " << v.y << " z: " << v.z << " w: " << v.w << "]";
}
friend std::wostream& operator << (std::wostream& os, const Vector4<T>& v)
{
return os << L"[x: " << v.x << L" y: " << v.y << L" z: " << v.z << L" w: " << v.w << L"]";
}
T x;
T y;
T z;
T w;
// Some handy predefines
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;
};
typedef Vector4<int> Vector4i;
typedef Vector4<double> Vector4d;
}
Eule::Vector4::ToInt
Vector4< int > ToInt() const
Will convert this vector to a Vector4i.
Definition: Vector4.cpp:173
Eule::Vector4::Vector4
Vector4(T _x, T _y, T _z, T _w)
Definition: Vector4.h:21
Eule::Vector4::operator+=
void operator+=(const Vector4< T > &other)
Definition: Vector4.cpp:376
Eule::Vector4::operator/
Vector4< T > operator/(const T scale) const
Definition: Vector4.cpp:603
Eule::Vector4::operator*
Vector4< T > operator*(const T scale) const
Definition: Vector4.cpp:512
Eule::Vector4::NormalizeSelf
void NormalizeSelf()
Will normalize this vector.
Definition: Vector4.cpp:148
Eule::Vector4::Vector4
Vector4()
Definition: Vector4.h:20
Eule::Vector4::backward
static const Vector4< double > backward
Definition: Vector4.h:99
Eule::Vector4::x
T x
Definition: Vector4.h:88
Eule::Vector4::operator=
void operator=(const Vector4< T > &other)
Conversion method.
Definition: Vector4.cpp:730
Eule::Vector4::operator-=
void operator-=(const Vector4< T > &other)
Definition: Vector4.cpp:466
Eule::Vector4::Normalize
Vector4< double > Normalize() const
Will return the normalization of this vector.
Definition: Vector4.cpp:92
Eule::Vector4::z
T z
Definition: Vector4.h:90
Eule::Vector4::operator*=
void operator*=(const T scale)
Definition: Vector4.cpp:557
Eule::Vector4d
Vector4< double > Vector4d
Definition: Vector4.h:107
Eule::Vector4::VectorScale
Vector4< T > VectorScale(const Vector4< T > &scalar) const
Will scale self.n by scalar.n.
Definition: Vector4.cpp:79
Eule::Vector4::operator-
Vector4< T > operator-() const
Definition: Vector4.cpp:719
Eule::Vector4::Lerp
Vector4< double > Lerp(const Vector4< T > &other, double t) const
Will return a lerp result between this and another vector.
Definition: Vector4.cpp:287
Eule::Vector4::one
static const Vector4< double > one
Definition: Vector4.h:102
Eule::Vector4::LerpSelf
void LerpSelf(const Vector4< T > &other, double t)
Will lerp itself towards other by t.
Definition: Vector4.cpp:267
Matrix4x4.h
Eule::Vector4::forward
static const Vector4< double > forward
Definition: Vector4.h:98
Eule::Vector4::operator/=
void operator/=(const T scale)
Definition: Vector4.cpp:647
Eule::Vector4::w
T w
Definition: Vector4.h:91
Eule::Vector4::down
static const Vector4< double > down
Definition: Vector4.h:95
Eule::Vector4::operator+
Vector4< T > operator+(const Vector4< T > &other) const
Definition: Vector4.cpp:331
Eule::Vector4::operator[]
T & operator[](std::size_t idx)
Definition: Vector4.cpp:185
Eule::Vector4::ToDouble
Vector4< double > ToDouble() const
Will convert this vector to a Vector4d.
Definition: Vector4.cpp:179
Eule::Vector4i
Vector4< int > Vector4i
Definition: Vector4.h:106
Eule::Vector4::operator!=
bool operator!=(const Vector4< T > &other) const
Definition: Vector4.cpp:767
Eule::Vector4::Similar
bool Similar(const Vector4< T > &other, double epsilon=0.00001) const
Will compare if two vectors are similar to a certain epsilon value.
Definition: Vector4.cpp:162
Eule::Vector4::Magnitude
double Magnitude() const
Will compute the magnitude.
Definition: Vector4.cpp:38
Eule::Vector4::future
static const Vector4< double > future
Definition: Vector4.h:100
Eule::Vector4::operator==
bool operator==(const Vector4< T > &other) const
Definition: Vector4.cpp:659
Eule::Vector4::zero
static const Vector4< double > zero
Definition: Vector4.h:103
Eule::Vector4::SqrMagnitude
double SqrMagnitude() const
Will compute the square magnitude.
Definition: Vector4.cpp:31
Eule::Vector4::up
static const Vector4< double > up
Definition: Vector4.h:94
Eule::Vector4::past
static const Vector4< double > past
Definition: Vector4.h:101
Eule::Vector4::operator<<
friend std::ostream & operator<<(std::ostream &os, const Vector4< T > &v)
Definition: Vector4.h:79
Eule::Vector4::y
T y
Definition: Vector4.h:89
Eule::Vector4::left
static const Vector4< double > left
Definition: Vector4.h:97
Eule
Definition: Collider.h:4
Eule::Vector4::right
static const Vector4< double > right
Definition: Vector4.h:96
Eule::Vector4
Representation of a 4d vector.
Definition: Vector2.h:8