Arcade Shooter
Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | List of all members
KatanaEngine::Vector2 Class Reference

Defines a vector with 2 components (x and y). This is additional information... More...

#include <Vector2.h>

Public Member Functions

 Vector2 (const float x=0, const float y=0)
 Instantiates a new Vector2 object. More...
 
float LengthSquared () const
 Calculates the length of the vector squared. More...
 
float Length () const
 Calculates the length of the vector. More...
 
void Set (const float x, const float y)
 Sets the components of the vector. More...
 
void Set (const Vector2 vector)
 Sets the components of the vector. More...
 
void Normalize ()
 Resize a vector to a length of one unit. If the starting vector is the zero vector, the call will be ignored.
 
bool IsZero () const
 Determines if the vector is the zero vector. More...
 
float DotProduct (const Vector2 &vector) const
 Calculates the dot product of two vectors. More...
 
float CrossProduct (const Vector2 &vector) const
 Calculates the cross product between two vectors. More...
 
Vector2 Left ()
 Calculates the left-hand orthogonal vector. More...
 
Vector2 Right ()
 Calculates the right-hand orthogonal vector. More...
 
const Point ToPoint () const
 Converts the vector into a point. More...
 
std::string ToString () const
 Gets a string representation of the vector. More...
 
void Display () const
 Prints the vector to the console.
 
Vector2operator= (const Vector2 &vector)
 Assigns the reference of a vector. More...
 
Vector2operator+= (const Vector2 &vector)
 Adds a vector. More...
 
Vector2operator-= (const Vector2 &vector)
 Subtracts a vector. More...
 
Vector2operator*= (const float scalar)
 Multiplies by a scalar. More...
 
Vector2operator/= (const float scalar)
 Divides by a scalar. More...
 
const Vector2 operator- () const
 Negates the vector. More...
 
const Vector2 operator+ (const Vector2 &vector) const
 Adds two vectors. More...
 
const Vector2 operator- (const Vector2 &vector) const
 Subtracts a vector from another. More...
 
const Vector2 operator* (const float scalar) const
 Multiplies a vector by a scalar. More...
 
const Vector2 operator/ (const float scalar) const
 Divides a vector by a scalar. More...
 
bool operator== (const Vector2 &vector) const
 Determines if two vectors are equal. More...
 
bool operator!= (const Vector2 &vector) const
 Determines if two vectors are not equal. More...
 

Static Public Member Functions

static float Distance (const Vector2 &vector1, const Vector2 &vector2)
 Calculates the distance between two vectors. More...
 
static float DistanceSquared (const Vector2 &vector1, const Vector2 &vector2)
 Calculates the distance squared between two vectors. More...
 
static Vector2 Lerp (const Vector2 &start, const Vector2 &end, const float value)
 Linearly interpolate between two vectors. More...
 
static Vector2 GetRandom (bool normalize=false)
 Creates a random vector. More...
 

Public Attributes

float X
 The x-coordinate of the vector.
 
float Y
 The y-coordinate of the vector.
 

Static Public Attributes

static const Vector2 Zero = Vector2(0, 0)
 A vector with both of its components set to zero.
 
static const Vector2 One = Vector2(1, 1)
 A vector with both of its components set to one.
 
static const Vector2 UnitX = Vector2(1, 0)
 A unit vector on the x-axis.
 
static const Vector2 UnitY = Vector2(0, 1)
 A unit vector on the y-axis.
 

Detailed Description

Defines a vector with 2 components (x and y). This is additional information...

Constructor & Destructor Documentation

◆ Vector2()

KatanaEngine::Vector2::Vector2 ( const float  x = 0,
const float  y = 0 
)

Instantiates a new Vector2 object.

Parameters
xThe X component
yThe Y component

Member Function Documentation

◆ CrossProduct()

float KatanaEngine::Vector2::CrossProduct ( const Vector2 vector) const

Calculates the cross product between two vectors.

Parameters
vectorThe other vector.
Returns
The calculated cross product.

◆ Distance()

float KatanaEngine::Vector2::Distance ( const Vector2 vector1,
const Vector2 vector2 
)
static

Calculates the distance between two vectors.

Parameters
vector1The first vector.
vector2The second vector.
Returns
The calculated distance.

◆ DistanceSquared()

float KatanaEngine::Vector2::DistanceSquared ( const Vector2 vector1,
const Vector2 vector2 
)
static

Calculates the distance squared between two vectors.

Parameters
vector1The first vector.
vector2The second vector.
Returns
The calculated distance squared.

◆ DotProduct()

float KatanaEngine::Vector2::DotProduct ( const Vector2 vector) const

Calculates the dot product of two vectors.

Parameters
vectorThe other vector.
Returns
The calculated dot product.
Remarks
If the two vectors are unit vectors, the dot product returns a floating point value between -1 and 1 that can be used to determine some properties of the angle between two vectors. For example, it can show whether the vectors are orthogonal, parallel, or have an acute or obtuse angle between them.

◆ GetRandom()

Vector2 KatanaEngine::Vector2::GetRandom ( bool  normalize = false)
static

Creates a random vector.

Parameters
normalizeSpecify true to generate a unit vector. False will generate a vector with a random length.
Returns
The random vector.

◆ IsZero()

bool KatanaEngine::Vector2::IsZero ( ) const
inline

Determines if the vector is the zero vector.

Returns
Returns true if both components are zero, false otherwise.

◆ Left()

Vector2 KatanaEngine::Vector2::Left ( )
inline

Calculates the left-hand orthogonal vector.

Returns
Returns the left vector.

◆ Length()

float KatanaEngine::Vector2::Length ( ) const

Calculates the length of the vector.

Returns
The length of the vector.

◆ LengthSquared()

float KatanaEngine::Vector2::LengthSquared ( ) const

Calculates the length of the vector squared.

Returns
float The length of the vector squared.

◆ Lerp()

Vector2 KatanaEngine::Vector2::Lerp ( const Vector2 start,
const Vector2 end,
const float  value 
)
static

Linearly interpolate between two vectors.

Parameters
startThe result when the value is zero.
endThe result when the value is one.
valueA value between 0 and 1 that will indicate the resulting weight between start and end.
Returns
Returns the interpolated vector between start and end.

◆ operator!=()

bool KatanaEngine::Vector2::operator!= ( const Vector2 vector) const

Determines if two vectors are not equal.

Parameters
vectorThe vector to compare.
Returns
Returns true if the vectors are not equal, false otherwise.

◆ operator*()

const Vector2 KatanaEngine::Vector2::operator* ( const float  scalar) const

Multiplies a vector by a scalar.

Parameters
scalarThe scalar to multiply by.
Returns
Returns the resulting vector.

◆ operator*=()

Vector2 & KatanaEngine::Vector2::operator*= ( const float  scalar)

Multiplies by a scalar.

Parameters
scalarThe scalar to multiply by.
Returns
Returns the resulting vector.

◆ operator+()

const Vector2 KatanaEngine::Vector2::operator+ ( const Vector2 vector) const

Adds two vectors.

Parameters
vectorThe vector to add.
Returns
Returns the resulting vector.

◆ operator+=()

Vector2 & KatanaEngine::Vector2::operator+= ( const Vector2 vector)

Adds a vector.

Parameters
vectorThe vector to add.
Returns
Returns the resulting vector.

◆ operator-() [1/2]

const Vector2 KatanaEngine::Vector2::operator- ( ) const
inline

Negates the vector.

Returns
Returns the resulting vector.

◆ operator-() [2/2]

const Vector2 KatanaEngine::Vector2::operator- ( const Vector2 vector) const

Subtracts a vector from another.

Parameters
vectorThe vector to subtract.
Returns
Returns the resulting vector.

◆ operator-=()

Vector2 & KatanaEngine::Vector2::operator-= ( const Vector2 vector)

Subtracts a vector.

Parameters
vectorThe vector to subtract.
Returns
Returns the resulting vector.

◆ operator/()

const Vector2 KatanaEngine::Vector2::operator/ ( const float  scalar) const

Divides a vector by a scalar.

Parameters
scalarThe scalar to divide by.
Returns
Returns the resulting vector.

◆ operator/=()

Vector2 & KatanaEngine::Vector2::operator/= ( const float  scalar)

Divides by a scalar.

Parameters
scalarThe scalar to divide by.
Returns
Returns the resulting vector.

◆ operator=()

Vector2 & KatanaEngine::Vector2::operator= ( const Vector2 vector)

Assigns the reference of a vector.

Parameters
vectorThe reference vector.
Returns
Returns the resulting vector.

◆ operator==()

bool KatanaEngine::Vector2::operator== ( const Vector2 vector) const

Determines if two vectors are equal.

Parameters
vectorThe vector to compare.
Returns
Returns true if the vectors are equal, false otherwise.

◆ Right()

Vector2 KatanaEngine::Vector2::Right ( )
inline

Calculates the right-hand orthogonal vector.

Returns
Returns the right vector.

◆ Set() [1/2]

void KatanaEngine::Vector2::Set ( const float  x,
const float  y 
)
inline

Sets the components of the vector.

Parameters
xThe X component.
yThe Y component.

◆ Set() [2/2]

void KatanaEngine::Vector2::Set ( const Vector2  vector)
inline

Sets the components of the vector.

Parameters
vectorThe vector whose components to copy.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ ToPoint()

const Point KatanaEngine::Vector2::ToPoint ( ) const

Converts the vector into a point.

Returns
Returns the closest point to the vector displacement.

◆ ToString()

std::string KatanaEngine::Vector2::ToString ( ) const

Gets a string representation of the vector.

Returns
Returns a string displaying the components of the vector.

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