3DRadSpace 0.1.0Alpha
3DRadSpace is a free, simple to use, rapid application development game engine.
Loading...
Searching...
No Matches
Engine3DRadSpace.Math::Vector2 Struct Reference

A 2D vector. More...

#include <Vector2.hpp>

Public Member Functions

constexpr Vector2 (float x=0.0f, float y=0.0f)
 Creates a vector with the specified values. If no values are provided, it creates a zero vector.
constexpr Vector2 (std::initializer_list< float > lst)
 Creates a vector from an initializer list of floats.
float Length () const
 Returns the length (magnitude) of this vector.
float LengthSquared () const
 Returns the squared length of this vector.
float Angle () const
 Returns the angle of this vector in radians, relative to the X-axis.
float Dot (const Vector2 &v) const
 Computes the dot product of this vector with another vector.
Vector2 & Normalize ()
 Normalizes this vector in-place.
Vector2 & operator+= (const Vector2 &v)
 Adds another vector to this vector in-place.
Vector2 operator+ (const Vector2 &v) const
 Adds another vector to this vector and returns the result.
Vector2 & operator- ()
 Negates this vector in-place.
Vector2 operator- () const
 Returns the negated form of this vector.
Vector2 & operator-= (const Vector2 &v)
 Subtracts another vector from this vector in-place.
Vector2 operator- (const Vector2 &v) const
 Subtracts another vector from this vector and returns the result.
float operator* (const Vector2 &v) const
 Computes the dot product of this vector with another vector.
Vector2 operator* (float s) const
 Multiplies this vector by a scalar and returns the result.
Vector2 & operator*= (float s)
 Multiplies this vector by a scalar in-place.
Vector2 & operator/= (float f)
 Divides this vector by a scalar in-place.
Vector2 operator/ (float f) const
 Divides this vector by a scalar and returns the result.
Vector2 & RotateBy (float theta)
 Rotates this vector in-place by the specified angle.
Vector2 Rotate (const Vector2 &v, float theta)
 Returns the specified vector rotated by the given angle.
Vector2 & Hadamard (const Vector2 &v)
 Element-wise (Hadamard) multiplication of this vector with another vector.
Vector2 & Transform (const Matrix3x3 &m)
 Transforms this vector in-place by the specified matrix.
Vector2 YX () const noexcept
 Returns a vector with the components swizzled to (Y, X).

Static Public Member Functions

static Vector2 Zero ()
 Returns a zero vector (0, 0).
static Vector2 UnitX ()
 Returns the unit vector along the X-axis (1, 0).
static Vector2 UnitY ()
 Returns the unit vector along the Y-axis (0, 1).
static Vector2 One ()
 Returns a vector with all components set to 1 (1, 1).
static float Dot (const Vector2 &a, const Vector2 &b)
 Computes the dot product of two vectors.
static Vector2 Normalize (const Vector2 &v)
 Returns the normalized form of the specified vector.
static Vector2 ConvertFromNormalizedScreenSpaceToClipSpace (const Vector2 &norm)
 Converts a normalized vector (in the range [-1, 1]) from screen space to clip space.
static Vector2 ConvertFromScreenCoordsToClipSpace (const Vector2 &point, const Vector2 &resolution)
 Converts a point in screen coordinates to clip space, given the screen resolution.
static Vector2 Hadamard (const Vector2 &a, const Vector2 &b)
 Element-wise (Hadamard) product of two vectors.
static Vector2 Transform (const Vector2 &v, const Matrix3x3 &m)
 Transforms the specified vector by the given matrix.

Public Attributes

float X
 X and Y components of the vector.
float Y

Detailed Description

A 2D vector.

Constructor & Destructor Documentation

◆ Vector2() [1/2]

Engine3DRadSpace.Math::Vector2::Vector2 ( float x = 0.0f,
float y = 0.0f )
inlineexplicitconstexpr

Creates a vector with the specified values. If no values are provided, it creates a zero vector.

Parameters
xThe X component.
yThe Y component.

◆ Vector2() [2/2]

Engine3DRadSpace.Math::Vector2::Vector2 ( std::initializer_list< float > lst)
inlineexplicitconstexpr

Creates a vector from an initializer list of floats.

Parameters
lstThe initializer list containing up to 2 values (X, Y).

Member Function Documentation

◆ Angle()

float Vector2::Angle ( ) const

Returns the angle of this vector in radians, relative to the X-axis.

Returns
The angle in radians.

◆ ConvertFromNormalizedScreenSpaceToClipSpace()

Vector2 Vector2::ConvertFromNormalizedScreenSpaceToClipSpace ( const Vector2 & norm)
static

Converts a normalized vector (in the range [-1, 1]) from screen space to clip space.

Parameters
normThe normalized screen space vector.
Returns
The resulting clip space vector.

◆ ConvertFromScreenCoordsToClipSpace()

Vector2 Vector2::ConvertFromScreenCoordsToClipSpace ( const Vector2 & point,
const Vector2 & resolution )
static

Converts a point in screen coordinates to clip space, given the screen resolution.

Parameters
pointThe point in screen coordinates.
resolutionThe screen resolution.
Returns
The resulting clip space vector.

◆ Dot() [1/2]

float Vector2::Dot ( const Vector2 & a,
const Vector2 & b )
static

Computes the dot product of two vectors.

Parameters
aThe first vector.
bThe second vector.
Returns
The dot product.

◆ Dot() [2/2]

float Vector2::Dot ( const Vector2 & v) const

Computes the dot product of this vector with another vector.

Parameters
vThe other vector.
Returns
The dot product.

◆ Hadamard() [1/2]

Vector2 Vector2::Hadamard ( const Vector2 & a,
const Vector2 & b )
static

Element-wise (Hadamard) product of two vectors.

Parameters
aThe first vector.
bThe second vector.
Returns
The resulting vector after Hadamard multiplication.

◆ Hadamard() [2/2]

Vector2 & Vector2::Hadamard ( const Vector2 & v)

Element-wise (Hadamard) multiplication of this vector with another vector.

Parameters
vThe vector to multiply with.
Returns
A reference to this vector after Hadamard multiplication.

◆ Length()

float Vector2::Length ( ) const

Returns the length (magnitude) of this vector.

Returns
The length of the vector.

◆ LengthSquared()

float Vector2::LengthSquared ( ) const

Returns the squared length of this vector.

Returns
The squared length of the vector.

◆ Normalize() [1/2]

Vector2 & Vector2::Normalize ( )

Normalizes this vector in-place.

Returns
A reference to this vector after normalization.

◆ Normalize() [2/2]

Vector2 Vector2::Normalize ( const Vector2 & v)
static

Returns the normalized form of the specified vector.

Parameters
vThe vector to normalize.
Returns
The normalized vector.

◆ One()

Vector2 Vector2::One ( )
static

Returns a vector with all components set to 1 (1, 1).

Returns
The one vector.

◆ operator*() [1/2]

float Vector2::operator* ( const Vector2 & v) const

Computes the dot product of this vector with another vector.

Parameters
vThe other vector.
Returns
The dot product.

◆ operator*() [2/2]

Vector2 Vector2::operator* ( float s) const

Multiplies this vector by a scalar and returns the result.

Parameters
sThe scalar value.
Returns
The resulting scaled vector.

◆ operator*=()

Vector2 & Vector2::operator*= ( float s)

Multiplies this vector by a scalar in-place.

Parameters
sThe scalar value.
Returns
A reference to this vector after scaling.

◆ operator+()

Vector2 Vector2::operator+ ( const Vector2 & v) const

Adds another vector to this vector and returns the result.

Parameters
vThe vector to add.
Returns
The resulting vector after addition.

◆ operator+=()

Vector2 & Vector2::operator+= ( const Vector2 & v)

Adds another vector to this vector in-place.

Parameters
vThe vector to add.
Returns
A reference to this vector after addition.

◆ operator-() [1/3]

Vector2 & Vector2::operator- ( )

Negates this vector in-place.

Returns
A reference to this vector after negation.

◆ operator-() [2/3]

Vector2 Vector2::operator- ( ) const

Returns the negated form of this vector.

Returns
The negated vector.

◆ operator-() [3/3]

Vector2 Vector2::operator- ( const Vector2 & v) const

Subtracts another vector from this vector and returns the result.

Parameters
vThe vector to subtract.
Returns
The resulting vector after subtraction.

◆ operator-=()

Vector2 & Vector2::operator-= ( const Vector2 & v)

Subtracts another vector from this vector in-place.

Parameters
vThe vector to subtract.
Returns
A reference to this vector after subtraction.

◆ operator/()

Vector2 Vector2::operator/ ( float f) const

Divides this vector by a scalar and returns the result.

Parameters
fThe scalar value.
Returns
The resulting vector after division.

◆ operator/=()

Vector2 & Vector2::operator/= ( float f)

Divides this vector by a scalar in-place.

Parameters
fThe scalar value.
Returns
A reference to this vector after division.

◆ Rotate()

Vector2 Vector2::Rotate ( const Vector2 & v,
float theta )

Returns the specified vector rotated by the given angle.

Parameters
vThe vector to rotate.
thetaThe rotation angle in radians.
Returns
The resulting rotated vector.

◆ RotateBy()

Vector2 & Vector2::RotateBy ( float theta)

Rotates this vector in-place by the specified angle.

Parameters
thetaThe rotation angle in radians.
Returns
A reference to this vector after rotation.

◆ Transform() [1/2]

Vector2 & Vector2::Transform ( const Matrix3x3 & m)

Transforms this vector in-place by the specified matrix.

Parameters
mThe matrix to transform by.
Returns
A reference to this vector after transformation.

◆ Transform() [2/2]

Vector2 Vector2::Transform ( const Vector2 & v,
const Matrix3x3 & m )
static

Transforms the specified vector by the given matrix.

Parameters
vThe vector to transform.
mThe matrix to transform by.
Returns
The resulting transformed vector.

◆ UnitX()

Vector2 Vector2::UnitX ( )
static

Returns the unit vector along the X-axis (1, 0).

Returns
The unit X vector.

◆ UnitY()

Vector2 Vector2::UnitY ( )
static

Returns the unit vector along the Y-axis (0, 1).

Returns
The unit Y vector.

◆ YX()

Vector2 Vector2::YX ( ) const
noexcept

Returns a vector with the components swizzled to (Y, X).

Returns
The swizzled vector.

◆ Zero()

Vector2 Vector2::Zero ( )
static

Returns a zero vector (0, 0).

Returns
The zero vector.

Member Data Documentation

◆ X

float Engine3DRadSpace.Math::Vector2::X

X and Y components of the vector.

◆ Y

float Engine3DRadSpace.Math::Vector2::Y

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