Clutter Engine 0.0.1
Loading...
Searching...
No Matches
Vector2 Struct Reference

Linearly interpolates between two vectors. More...

#include <Vector2.h>

Public Member Functions

 Vector2 ()
 Default constructor initializing the vector to (0,0).
 
 Vector2 (float pX, float pY)
 Constructor initializing the vector to (pX, pY).
 
 Vector2 (int pX, int pY)
 
 Vector2 (GLuint pX, GLuint pY)
 
 Vector2 (float pXY)
 
void operator+= (Vector2 right)
 Adds the components of another vector to this vector.
 
void operator+= (float length)
 Adds a scalar to both components of the vector.
 
void operator-= (Vector2 right)
 Subtracts the components of another vector from this vector.
 
void operator-= (float length)
 Subtracts a scalar from both components of the vector.
 
void operator*= (Vector2 multiplyer)
 Multiplies the components of this vector by another vector.
 
void operator*= (float length)
 Multiplies both components of the vector by a scalar.
 
void operator/= (Vector2 divider)
 Divides the components of this vector by another vector.
 
void operator/= (float length)
 Divides both components of the vector by a scalar.
 
void operator= (Vector2 newVec)
 Assigns the components of another vector to this vector.
 
Vector2 operator- () const
 Negates the vector.
 
float Length () const
 Calculates the length of the vector.
 
bool Equal (Vector2 right, double acceptance) const
 Checks if two vectors are equal within an acceptance range.
 
Vector2 Normalized ()
 Normalizes the vector to a unit vector.
 
float LengthSquared () const
 Calculates the squared length of the vector.
 
float Cross (const Vector2 &other) const
 Calculates the cross product of two vectors.
 
void Clamp (float minValue, float maxValue)
 Clamps the vector components to the given range.
 
std::string ToString ()
 Converts the vector to a string representation.
 
glm::vec2 ToGlm ()
 Converts the vector to a glm::vec2.
 

Static Public Member Functions

static float DistanceSquared (const Vector2 &left, const Vector2 &right)
 Calculates the squared distance between two vectors.
 
static Vector2 Lerp (const Vector2 &start, const Vector2 &end, float t)
 Linearly interpolates between two vectors.
 
static float Dot (const Vector2 &left, const Vector2 &right)
 Calculates the dot product of two vectors.
 
static Vector2 VInterp (const Vector2 &current, const Vector2 &target, float deltaTime, float interpSpeed)
 Linearly interpolates between two vectors.
 

Public Attributes

float x = 0
 The x-coordinate of the vector.
 
float y = 0
 The y-coordinate of the vector.
 

Static Public Attributes

static const Vector2 Zero { 0 , 0 }
 A vector with both coordinates set to zero.
 
static const Vector2 One { 1 , 1 }
 A vector with both coordinates set to one.
 

Friends

bool operator== (Vector2 left, Vector2 right)
 Checks if two vectors are equal.
 
bool operator!= (Vector2 left, Vector2 right)
 Checks if two vectors are not equal.
 
Vector2 operator- (Vector2 left, Vector2 right)
 Subtracts two vectors.
 
Vector2 operator- (Vector2 left, float right)
 Subtracts a scalar from a vector.
 
Vector2 operator+ (Vector2 left, Vector2 right)
 Adds two vectors.
 
Vector2 operator+ (Vector2 left, float right)
 Adds a scalar to a vector.
 
Vector2 operator* (float scalar, Vector2 right)
 Multiplies a vector by a scalar.
 
Vector2 operator* (Vector2 left, float scalar)
 Multiplies a vector by a scalar.
 
Vector2 operator* (Vector2 left, Vector2 right)
 Multiplies two vectors component-wise.
 
Vector2 operator/ (float scalar, Vector2 right)
 Divides a scalar by a vector.
 
Vector2 operator/ (Vector2 left, float scalar)
 Divides a vector by a scalar.
 
Vector2 operator/ (Vector2 left, Vector2 right)
 Divides two vectors component-wise.
 
Vector2 Clamp (Vector2 temp, float minValue, float maxValue)
 Clamps the vector components to the given range.
 

Detailed Description

Linearly interpolates between two vectors.

Parameters
currentThe current vector.
targetThe target vector.
deltaTimeThe time step.
interpSpeedThe interpolation speed.
Returns
The interpolated vector.

A 2D vector structure.

Constructor & Destructor Documentation

◆ Vector2()

Vector2::Vector2 ( float pX,
float pY )
inline

Constructor initializing the vector to (pX, pY).

Parameters
pXThe x-coordinate.
pYThe y-coordinate.

Member Function Documentation

◆ Clamp()

void Vector2::Clamp ( float minValue,
float maxValue )
inline

Clamps the vector components to the given range.

Parameters
minValueThe minimum value.
maxValueThe maximum value.

◆ Cross()

float Vector2::Cross ( const Vector2 & other) const
inline

Calculates the cross product of two vectors.

/**

Parameters
otherThe other vector.
Returns
The cross product of the two vectors.

◆ DistanceSquared()

static float Vector2::DistanceSquared ( const Vector2 & left,
const Vector2 & right )
inlinestatic

Calculates the squared distance between two vectors.

Parameters
leftThe left vector.
rightThe right vector.
Returns
The squared distance between the two vectors.

◆ Dot()

static float Vector2::Dot ( const Vector2 & left,
const Vector2 & right )
inlinestatic

Calculates the dot product of two vectors.

Parameters
leftThe left vector.
rightThe right vector.
Returns
The dot product of the two vectors.

◆ Equal()

bool Vector2::Equal ( Vector2 right,
double acceptance ) const
inline

Checks if two vectors are equal within an acceptance range.

Parameters
rightThe vector to compare to.
acceptanceThe acceptance range.
Returns
True if the vectors are equal within the acceptance range, false otherwise.

◆ Length()

float Vector2::Length ( ) const
inline

Calculates the length of the vector.

Returns
The length of the vector.

◆ LengthSquared()

float Vector2::LengthSquared ( ) const
inline

Calculates the squared length of the vector.

Returns
The squared length of the vector.

◆ Lerp()

static Vector2 Vector2::Lerp ( const Vector2 & start,
const Vector2 & end,
float t )
inlinestatic

Linearly interpolates between two vectors.

Parameters
startThe start vector.
endThe end vector.
tThe interpolation factor (0.0 to 1.0).
Returns
The interpolated vector.

◆ Normalized()

Vector2 Vector2::Normalized ( )
inline

Normalizes the vector to a unit vector.

Returns
The normalized vector.

◆ operator*=() [1/2]

void Vector2::operator*= ( float length)
inline

Multiplies both components of the vector by a scalar.

Parameters
lengthThe scalar to multiply by.

◆ operator*=() [2/2]

void Vector2::operator*= ( Vector2 multiplyer)
inline

Multiplies the components of this vector by another vector.

Parameters
multiplierThe vector to multiply by.

◆ operator+=() [1/2]

void Vector2::operator+= ( float length)
inline

Adds a scalar to both components of the vector.

Parameters
lengthThe scalar to add.

◆ operator+=() [2/2]

void Vector2::operator+= ( Vector2 right)
inline

Adds the components of another vector to this vector.

Parameters
rightThe vector to add.

◆ operator-()

Vector2 Vector2::operator- ( ) const
inline

Negates the vector.

Returns
The negated vector.

◆ operator-=() [1/2]

void Vector2::operator-= ( float length)
inline

Subtracts a scalar from both components of the vector.

Parameters
lengthThe scalar to subtract.

◆ operator-=() [2/2]

void Vector2::operator-= ( Vector2 right)
inline

Subtracts the components of another vector from this vector.

Parameters
rightThe vector to subtract.

◆ operator/=() [1/2]

void Vector2::operator/= ( float length)
inline

Divides both components of the vector by a scalar.

Parameters
lengthThe scalar to divide by.

◆ operator/=() [2/2]

void Vector2::operator/= ( Vector2 divider)
inline

Divides the components of this vector by another vector.

Parameters
dividerThe vector to divide by.

◆ operator=()

void Vector2::operator= ( Vector2 newVec)
inline

Assigns the components of another vector to this vector.

Parameters
newVecThe vector to assign.

◆ ToGlm()

glm::vec2 Vector2::ToGlm ( )
inline

Converts the vector to a glm::vec2.

Returns
A glm::vec2 representing the vector.

◆ ToString()

std::string Vector2::ToString ( )
inline

Converts the vector to a string representation.

Returns
A string representing the vector in the format " (x , y) ".

◆ VInterp()

static Vector2 Vector2::VInterp ( const Vector2 & current,
const Vector2 & target,
float deltaTime,
float interpSpeed )
inlinestatic

Linearly interpolates between two vectors.

Parameters
currentThe current vector.
targetThe target vector.
deltaTimeThe time step.
interpSpeedThe interpolation speed.
Returns
The interpolated vector.

Friends And Related Symbol Documentation

◆ Clamp

Vector2 Clamp ( Vector2 temp,
float minValue,
float maxValue )
friend

Clamps the vector components to the given range.

Parameters
tempThe vector to clamp.
minValueThe minimum value.
maxValueThe maximum value.
Returns
The clamped vector.

◆ operator!=

bool operator!= ( Vector2 left,
Vector2 right )
friend

Checks if two vectors are not equal.

Parameters
leftThe left vector.
rightThe right vector.
Returns
True if the vectors are not equal, false otherwise.

◆ operator* [1/3]

Vector2 operator* ( float scalar,
Vector2 right )
friend

Multiplies a vector by a scalar.

Parameters
scalarThe scalar.
rightThe vector.
Returns
The result of the multiplication.

◆ operator* [2/3]

Vector2 operator* ( Vector2 left,
float scalar )
friend

Multiplies a vector by a scalar.

Parameters
leftThe vector.
scalarThe scalar.
Returns
The result of the multiplication.

◆ operator* [3/3]

Vector2 operator* ( Vector2 left,
Vector2 right )
friend

Multiplies two vectors component-wise.

Parameters
leftThe left vector.
rightThe right vector.
Returns
The result of the multiplication.

◆ operator+ [1/2]

Vector2 operator+ ( Vector2 left,
float right )
friend

Adds a scalar to a vector.

Parameters
leftThe vector.
rightThe scalar.
Returns
The result of the addition.

◆ operator+ [2/2]

Vector2 operator+ ( Vector2 left,
Vector2 right )
friend

Adds two vectors.

Parameters
leftThe left vector.
rightThe right vector.
Returns
The result of the addition.

◆ operator- [1/2]

Vector2 operator- ( Vector2 left,
float right )
friend

Subtracts a scalar from a vector.

Parameters
leftThe vector.
rightThe scalar.
Returns
The result of the subtraction.

◆ operator- [2/2]

Vector2 operator- ( Vector2 left,
Vector2 right )
friend

Subtracts two vectors.

Parameters
leftThe left vector.
rightThe right vector.
Returns
The result of the subtraction.

◆ operator/ [1/3]

Vector2 operator/ ( float scalar,
Vector2 right )
friend

Divides a scalar by a vector.

Parameters
scalarThe scalar.
rightThe vector.
Returns
The result of the division.

◆ operator/ [2/3]

Vector2 operator/ ( Vector2 left,
float scalar )
friend

Divides a vector by a scalar.

Parameters
leftThe vector.
scalarThe scalar.
Returns
The result of the division.

◆ operator/ [3/3]

Vector2 operator/ ( Vector2 left,
Vector2 right )
friend

Divides two vectors component-wise.

Parameters
leftThe left vector.
rightThe right vector.
Returns
The result of the division.

◆ operator==

bool operator== ( Vector2 left,
Vector2 right )
friend

Checks if two vectors are equal.

Parameters
leftThe left vector.
rightThe right vector.
Returns
True if the vectors are equal, false otherwise.

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