Vector3.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 Vector4;
template <typename T>
class Vector3
{
public:
Vector3() : x{ 0 }, y{ 0 }, z{ 0 } {}
Vector3(T _x, T _y, T _z) : x{ _x }, y{ _y }, z{ _z } {}
Vector3(const Vector3<T>& other) = default;
Vector3(Vector3<T>&& other) noexcept = default;
double DotProduct(const Vector3<T>& other) const;
Vector3<double> CrossProduct(const Vector3<T>& other) const;
double SqrMagnitude() const;
double Magnitude() const;
[[nodiscard]] Vector3<double> Normalize() const;
void NormalizeSelf();
[[nodiscard]] Vector3<T> VectorScale(const Vector3<T>& scalar) const;
void LerpSelf(const Vector3<T>& other, double t);
[[nodiscard]] Vector3<double> Lerp(const Vector3<T>& other, double t) const;
[[nodiscard]] bool Similar(const Vector3<T>& other, double epsilon = 0.00001) const;
[[nodiscard]] Vector3<int> ToInt() const;
[[nodiscard]] Vector3<double> ToDouble() const;
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;
void operator=(const Vector3<T>& other);
void operator=(Vector3<T>&& other) noexcept;
bool operator==(const Vector3<T>& other) const;
bool operator!=(const Vector3<T>& other) const;
friend std::ostream& operator << (std::ostream& os, const Vector3<T>& v)
{
return os << "[x: " << v.x << " y: " << v.y << " z: " << v.z << "]";
}
friend std::wostream& operator << (std::wostream& os, const Vector3<T>& v)
{
return os << L"[x: " << v.x << L" y: " << v.y << L" z: " << v.z << L"]";
}
T x;
T y;
T z;
// Some handy predefines
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;
};
typedef Vector3<int> Vector3i;
typedef Vector3<double> Vector3d;
}
Eule::Vector3::operator+
Vector3< T > operator+(const Vector3< T > &other) const
Definition: Vector3.cpp:372
Eule::Vector3::right
static const Vector3< double > right
Definition: Vector3.h:101
Eule::Vector3::operator<<
friend std::ostream & operator<<(std::ostream &os, const Vector3< T > &v)
Definition: Vector3.h:85
Eule::Vector3::LerpSelf
void LerpSelf(const Vector3< T > &other, double t)
Will lerp itself towards other by t.
Definition: Vector3.cpp:311
Eule::Vector3::CrossProduct
Vector3< double > CrossProduct(const Vector3< T > &other) const
Will compute the cross product to another Vector3.
Definition: Vector3.cpp:68
Eule::Vector3::left
static const Vector3< double > left
Definition: Vector3.h:102
Eule::Vector3::Similar
bool Similar(const Vector3< T > &other, double epsilon=0.00001) const
Will compare if two vectors are similar to a certain epsilon value.
Definition: Vector3.cpp:213
Eule::Vector3
Representation of a 3d vector.
Definition: Matrix4x4.h:9
Eule::Vector3::Vector3
Vector3(T _x, T _y, T _z)
Definition: Vector3.h:21
Eule::Vector3::operator-
Vector3< T > operator-() const
Definition: Vector3.cpp:806
Eule::Vector3::down
static const Vector3< double > down
Definition: Vector3.h:100
Eule::Vector3::Lerp
Vector3< double > Lerp(const Vector3< T > &other, double t) const
Will return a lerp result between this and another vector.
Definition: Vector3.cpp:330
Eule::Vector3::forward
static const Vector3< double > forward
Definition: Vector3.h:103
Eule::Vector3::one
static const Vector3< double > one
Definition: Vector3.h:105
Eule::Vector3::operator=
void operator=(const Vector3< T > &other)
Conversion method.
Definition: Vector3.cpp:816
Eule::Vector3::ToDouble
Vector3< double > ToDouble() const
Will convert this vector to a Vector3d.
Definition: Vector3.cpp:229
Eule::Vector3::ToInt
Vector3< int > ToInt() const
Will convert this vector to a Vector3i.
Definition: Vector3.cpp:223
Eule::Vector3::operator==
bool operator==(const Vector3< T > &other) const
Definition: Vector3.cpp:855
Eule::Vector3::operator*=
void operator*=(const T scale)
Definition: Vector3.cpp:583
Eule::Vector3::Vector3
Vector3()
Definition: Vector3.h:20
Eule::Vector3d
Vector3< double > Vector3d
Definition: Matrix4x4.h:9
Matrix4x4.h
Eule::Vector3i
Vector3< int > Vector3i
Definition: Vector3.h:109
Eule::Vector3::backward
static const Vector3< double > backward
Definition: Vector3.h:104
Eule::Vector3::Normalize
Vector3< double > Normalize() const
Will return the normalization of this vector.
Definition: Vector3.cpp:147
Eule::Vector3::z
T z
Definition: Vector3.h:96
Eule::Vector3::up
static const Vector3< double > up
Definition: Vector3.h:99
Eule::Vector3::operator[]
T & operator[](std::size_t idx)
Definition: Vector3.cpp:235
Eule::Vector3::x
T x
Definition: Vector3.h:94
Eule::Vector3::DotProduct
double DotProduct(const Vector3< T > &other) const
Will compute the dot product to another Vector3.
Definition: Vector3.cpp:48
Eule::Vector3::operator/
Vector3< T > operator/(const T scale) const
Definition: Vector3.cpp:626
Eule::Vector3::operator-=
void operator-=(const Vector3< T > &other)
Definition: Vector3.cpp:498
Eule::Vector3::SqrMagnitude
double SqrMagnitude() const
Will compute the square magnitude.
Definition: Vector3.cpp:88
Eule::Vector3::operator/=
void operator/=(const T scale)
Definition: Vector3.cpp:667
Eule::Vector3::operator!=
bool operator!=(const Vector3< T > &other) const
Definition: Vector3.cpp:864
Eule::Vector3::operator+=
void operator+=(const Vector3< T > &other)
Definition: Vector3.cpp:414
Eule::Vector3::Magnitude
double Magnitude() const
Will compute the magnitude.
Definition: Vector3.cpp:95
Eule::Vector3::NormalizeSelf
void NormalizeSelf()
Will normalize this vector.
Definition: Vector3.cpp:200
Eule::Vector3::operator*
Vector3< T > operator*(const T scale) const
Definition: Vector3.cpp:541
Eule::Vector3::zero
static const Vector3< double > zero
Definition: Vector3.h:106
Eule
Definition: Collider.h:4
Eule::Vector3::y
T y
Definition: Vector3.h:95
Eule::Vector3::VectorScale
Vector3< T > VectorScale(const Vector3< T > &scalar) const
Will scale self.n by scalar.n.
Definition: Vector3.cpp:135