MochiEngine
Loading...
Searching...
No Matches
Mochi::Vector2f Struct Reference

Float vector of two positions with an X and Y elements and conversion with SDL_FPoint for ease of use with SDL. It allows basic operations like sum, substraction, multiplication and division of vectors, and also multiplication and division with scalars. It also gives useful methods like the Dot, or the length of the vector (the Distance from 0,0). More...

#include <Types.hpp>

Public Member Functions

 Vector2f (float _x=0, float _y=0)
 Vector2f (const Vector2f &v)
 Vector2f (Vector2f &&v)
 Vector2f (const SDL_FPoint &p)
 operator SDL_FPoint () const
Vector2f & operator= (const Vector2f &other)
Vector2f & operator= (const SDL_FPoint &other)
Vector2f & operator+= (const Vector2f &rhs)
Vector2f & operator-= (const Vector2f &rhs)
Vector2f & operator*= (const Vector2f &rhs)
Vector2f & operator*= (const float &rhs)
Vector2f & operator/= (const Vector2f &rhs)
Vector2f & operator/= (const float &rhs)
bool operator== (const Vector2f &rhs)
std::string ToString () const
float Distance () const
 Gives the length of the vector, or the distance to the origin point.
Vector2f Normalized () const
 Returns a new copy of the vector, normlized. If vector was 0,0, returns 0,0.
void Normalize ()
 Sets the vector to its Normalized state.
float Dot (const Vector2f &rhs) const
 Gives the dot product of the vector and other vector.
float CosineProximity (const Vector2f &rhs) const
 Returns the dot product of the normalized states of the vector and other vector. This is the same as the "Dot" operation given by the Unity Engine.

Static Public Member Functions

static float Dot (Vector2f lhs, const Vector2f &rhs)
 Gives the dot product between two vectors.
static float CosineProximity (Vector2f lhs, const Vector2f &rhs)
 Returns the dot product of the normalized states of two vectors. This is the same as the "Dot" operation given by the Unity Engine.
static Vector2f MoveTowards (const Vector2f source, const Vector2f target, const float &maxMagnitude)
 Gives the resulting vector when moving a source vector towards another vector up to a maximum distance.

Public Attributes

float x
float y

Static Public Attributes

static const Vector2f Zero {0, 0}
static const Vector2f One {1, 1}
static const Vector2f Right {1, 0}
static const Vector2f Left {-1, 0}
static const Vector2f Up {0, 1}
static const Vector2f Down {0, -1}

Friends

Vector2f operator+ (Vector2f lhs, const Vector2f &rhs)
Vector2f operator- (Vector2f lhs, const Vector2f &rhs)
Vector2f operator* (Vector2f lhs, const Vector2f &rhs)
Vector2f operator* (Vector2f lhs, const float &rhs)
Vector2f operator/ (Vector2f lhs, const Vector2f &rhs)
Vector2f operator/ (Vector2f lhs, const float &rhs)

Detailed Description

Float vector of two positions with an X and Y elements and conversion with SDL_FPoint for ease of use with SDL. It allows basic operations like sum, substraction, multiplication and division of vectors, and also multiplication and division with scalars. It also gives useful methods like the Dot, or the length of the vector (the Distance from 0,0).

Member Function Documentation

◆ CosineProximity() [1/2]

float Mochi::Vector2f::CosineProximity ( const Vector2f & rhs) const
inline

Returns the dot product of the normalized states of the vector and other vector. This is the same as the "Dot" operation given by the Unity Engine.

Parameters
rhsOther vector.
Returns
The dot product of the normalized vectors.

◆ CosineProximity() [2/2]

float Mochi::Vector2f::CosineProximity ( Vector2f lhs,
const Vector2f & rhs )
inlinestatic

Returns the dot product of the normalized states of two vectors. This is the same as the "Dot" operation given by the Unity Engine.

Parameters
lhsLeft side vector.
rhsRight side vector.
Returns
The dot product of the normalized vectors.

◆ Distance()

float Mochi::Vector2f::Distance ( ) const
inline

Gives the length of the vector, or the distance to the origin point.

Returns
The length.

◆ Dot() [1/2]

float Mochi::Vector2f::Dot ( const Vector2f & rhs) const
inline

Gives the dot product of the vector and other vector.

Parameters
rhsOther vector.
Returns
The dot product.

◆ Dot() [2/2]

float Mochi::Vector2f::Dot ( Vector2f lhs,
const Vector2f & rhs )
inlinestatic

Gives the dot product between two vectors.

Parameters
lhsLeft side vector
rhsRight side vector
Returns
The dot product.

◆ MoveTowards()

Vector2f Mochi::Vector2f::MoveTowards ( const Vector2f source,
const Vector2f target,
const float & maxMagnitude )
inlinestatic

Gives the resulting vector when moving a source vector towards another vector up to a maximum distance.

Parameters
sourceWhere to start.
targetWhere to end, at most.
maxMagnitudeThe maximum distance to move.
Returns
Target vector if distance was less than max magnitude, or a point inbetween if not.

◆ Normalized()

Vector2f Mochi::Vector2f::Normalized ( ) const
inline

Returns a new copy of the vector, normlized. If vector was 0,0, returns 0,0.

Returns
The normalized vector.

The documentation for this struct was generated from the following file: