Add Unit for vector2
Former-commit-id: 4a143363f24e08d0be12a5ef6bfb46c71b11be4a
This commit is contained in:
parent
376df6a3b7
commit
2d07922478
|
|
@ -27,12 +27,10 @@ class NzVector2
|
||||||
~NzVector2() = default;
|
~NzVector2() = default;
|
||||||
|
|
||||||
T AbsDotProduct(const NzVector2& vec) const;
|
T AbsDotProduct(const NzVector2& vec) const;
|
||||||
|
|
||||||
T AngleBetween(const NzVector2& vec) const;
|
T AngleBetween(const NzVector2& vec) const;
|
||||||
|
|
||||||
T Distance(const NzVector2& vec) const;
|
T Distance(const NzVector2& vec) const;
|
||||||
float Distancef(const NzVector2& vec) const;
|
float Distancef(const NzVector2& vec) const;
|
||||||
|
|
||||||
T DotProduct(const NzVector2& vec) const;
|
T DotProduct(const NzVector2& vec) const;
|
||||||
|
|
||||||
T GetLength() const;
|
T GetLength() const;
|
||||||
|
|
@ -40,6 +38,7 @@ class NzVector2
|
||||||
NzVector2 GetNormal(T* length = nullptr) const;
|
NzVector2 GetNormal(T* length = nullptr) const;
|
||||||
T GetSquaredLength() const;
|
T GetSquaredLength() const;
|
||||||
|
|
||||||
|
NzVector2& MakeUnit();
|
||||||
NzVector2& MakeUnitX();
|
NzVector2& MakeUnitX();
|
||||||
NzVector2& MakeUnitY();
|
NzVector2& MakeUnitY();
|
||||||
NzVector2& MakeZero();
|
NzVector2& MakeZero();
|
||||||
|
|
@ -89,6 +88,7 @@ class NzVector2
|
||||||
bool operator>=(const NzVector2& vec) const;
|
bool operator>=(const NzVector2& vec) const;
|
||||||
|
|
||||||
static NzVector2 Lerp(const NzVector2& from, const NzVector2& to, T interpolation);
|
static NzVector2 Lerp(const NzVector2& from, const NzVector2& to, T interpolation);
|
||||||
|
static NzVector2 Unit();
|
||||||
static NzVector2 UnitX();
|
static NzVector2 UnitX();
|
||||||
static NzVector2 UnitY();
|
static NzVector2 UnitY();
|
||||||
static NzVector2 Zero();
|
static NzVector2 Zero();
|
||||||
|
|
|
||||||
|
|
@ -105,6 +105,12 @@ T NzVector2<T>::GetSquaredLength() const
|
||||||
return x*x + y*y;
|
return x*x + y*y;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
NzVector2<T>& NzVector2<T>::MakeUnit()
|
||||||
|
{
|
||||||
|
return Set(F(1.0), F(1.0));
|
||||||
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
NzVector2<T>& NzVector2<T>::MakeUnitX()
|
NzVector2<T>& NzVector2<T>::MakeUnitX()
|
||||||
{
|
{
|
||||||
|
|
@ -229,7 +235,7 @@ NzVector2<T>& NzVector2<T>::Set(const NzVector4<T>& vec)
|
||||||
template<typename T>
|
template<typename T>
|
||||||
T NzVector2<T>::SquaredDistance(const NzVector2& vec) const
|
T NzVector2<T>::SquaredDistance(const NzVector2& vec) const
|
||||||
{
|
{
|
||||||
return operator-(vec).GetSquaredLength();
|
return (*this - vec).GetSquaredLength();
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
|
|
@ -443,6 +449,15 @@ NzVector2<T> NzVector2<T>::Lerp(const NzVector2& from, const NzVector2& to, T in
|
||||||
return NzLerp(from, to, interpolation);
|
return NzLerp(from, to, interpolation);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
NzVector2<T> NzVector2<T>::Unit()
|
||||||
|
{
|
||||||
|
NzVector2 vector;
|
||||||
|
vector.MakeUnit();
|
||||||
|
|
||||||
|
return vector;
|
||||||
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
NzVector2<T> NzVector2<T>::UnitX()
|
NzVector2<T> NzVector2<T>::UnitX()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue