MinGfx Toolkit  1.0
A minimal library for writing cross-platform (Windows, OSX, linux) graphics programs.
Public Member Functions | Static Public Member Functions | List of all members
mingfx::Vector2 Class Reference

Detailed Description

A 2D Vector with floating point coordinates, used for storing 2D translations, mouse movements, and screen-space vectors.

Definition at line 28 of file vector2.h.

#include <vector2.h>

Public Member Functions

 Vector2 ()
 Default constructor to create zero vector. More...
 
 Vector2 (float x, float y)
 Constructs a vector (x,y,0), where the 0 comes from the use of homogeneous coordinates in computer graphics. More...
 
 Vector2 (float *v)
 Constructs a vector given a pointer to x,y,z data. More...
 
 Vector2 (const Vector2 &v)
 Copy constructor for vector. More...
 
virtual ~Vector2 ()
 Vector destructor. More...
 
bool operator== (const Vector2 &v) const
 Check for "equality", taking floating point imprecision into account. More...
 
bool operator!= (const Vector2 &v) const
 Check for "inequality", taking floating point imprecision into account. More...
 
Vector2operator= (const Vector2 &v)
 Vector assignment operator. More...
 
float operator[] (const int i) const
 Read only access to the ith coordinate of the vector. More...
 
float & operator[] (const int i)
 Returns a reference to the ith coordinate of the vector. Use this accessor if you wish to set the coordinate rather than just request its value. Example: More...
 
float x () const
 Read only access to the x coordinate. Can also use my_vector[0]. Use the my_vector[0] = 1.0; form if you need to set the value. More...
 
float y () const
 Read only access to the y coordinate. Can also use my_vector[1]. Use the my_vector[1] = 1.0; form if you need to set the value. More...
 
float w () const
 In homogeneous coordinates, the w coordinate for all vectors is 0.0. More...
 
float Dot (const Vector2 &v) const
 Returns "this dot v". More...
 
float Length () const
 Returns the length of the vector. More...
 
void Normalize ()
 Normalizes the vector by making it unit length. More...
 
Vector2 ToUnit () const
 Returns a normalized (i.e., unit length) version of the vector without modifying the original ('this') vector. More...
 
Vector2 Lerp (const Vector2 &b, float alpha) const
 Linear interpolation between this vector and another. Alpha=0.0 returns this vector, and alpha=1.0 returns the other vector, other values blend between the two. More...
 
const float * value_ptr () const
 Returns a const pointer to the raw data array. More...
 

Static Public Member Functions

static Vector2 Normalize (const Vector2 &v)
 Returns a new vector that is the unit version of v. More...
 
static float Dot (const Vector2 &v1, const Vector2 &v2)
 Returns v1 dot v2. More...
 
static const Vector2Zero ()
 (0,0) - a shortcut for a special vector that is frequently needed More...
 
static const Vector2One ()
 (1,1) - a shortcut for a special vector that is frequently needed More...
 
static const Vector2UnitX ()
 (1,0) - a shortcut for a special vector that is frequently needed More...
 
static const Vector2UnitY ()
 (0,1) - a shortcut for a special vector that is frequently needed More...
 
static Vector2 Lerp (const Vector2 &a, const Vector2 &b, float alpha)
 Linear interpolation between two vectors. Alpha=0.0 returns 'a' and alpha=1.0 returns 'b', other values blend between the two. More...
 

Constructor & Destructor Documentation

◆ Vector2() [1/4]

mingfx::Vector2::Vector2 ( )

Default constructor to create zero vector.

◆ Vector2() [2/4]

mingfx::Vector2::Vector2 ( float  x,
float  y 
)

Constructs a vector (x,y,0), where the 0 comes from the use of homogeneous coordinates in computer graphics.

◆ Vector2() [3/4]

mingfx::Vector2::Vector2 ( float *  v)

Constructs a vector given a pointer to x,y,z data.

◆ Vector2() [4/4]

mingfx::Vector2::Vector2 ( const Vector2 v)

Copy constructor for vector.

◆ ~Vector2()

virtual mingfx::Vector2::~Vector2 ( )
virtual

Vector destructor.

Member Function Documentation

◆ Dot() [1/2]

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

Returns "this dot v".

◆ Dot() [2/2]

static float mingfx::Vector2::Dot ( const Vector2 v1,
const Vector2 v2 
)
static

Returns v1 dot v2.

◆ Length()

float mingfx::Vector2::Length ( ) const

Returns the length of the vector.

◆ Lerp() [1/2]

static Vector2 mingfx::Vector2::Lerp ( const Vector2 a,
const Vector2 b,
float  alpha 
)
static

Linear interpolation between two vectors. Alpha=0.0 returns 'a' and alpha=1.0 returns 'b', other values blend between the two.

◆ Lerp() [2/2]

Vector2 mingfx::Vector2::Lerp ( const Vector2 b,
float  alpha 
) const

Linear interpolation between this vector and another. Alpha=0.0 returns this vector, and alpha=1.0 returns the other vector, other values blend between the two.

◆ Normalize() [1/2]

void mingfx::Vector2::Normalize ( )

Normalizes the vector by making it unit length.

◆ Normalize() [2/2]

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

Returns a new vector that is the unit version of v.

◆ One()

static const Vector2& mingfx::Vector2::One ( )
static

(1,1) - a shortcut for a special vector that is frequently needed

◆ operator!=()

bool mingfx::Vector2::operator!= ( const Vector2 v) const

Check for "inequality", taking floating point imprecision into account.

◆ operator=()

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

Vector assignment operator.

◆ operator==()

bool mingfx::Vector2::operator== ( const Vector2 v) const

Check for "equality", taking floating point imprecision into account.

◆ operator[]() [1/2]

float& mingfx::Vector2::operator[] ( const int  i)

Returns a reference to the ith coordinate of the vector. Use this accessor if you wish to set the coordinate rather than just request its value. Example:

a[0] = 5.0; // set the x-coordinate of the vector
Vector2()
Default constructor to create zero vector.

◆ operator[]() [2/2]

float mingfx::Vector2::operator[] ( const int  i) const

Read only access to the ith coordinate of the vector.

◆ ToUnit()

Vector2 mingfx::Vector2::ToUnit ( ) const

Returns a normalized (i.e., unit length) version of the vector without modifying the original ('this') vector.

◆ UnitX()

static const Vector2& mingfx::Vector2::UnitX ( )
static

(1,0) - a shortcut for a special vector that is frequently needed

◆ UnitY()

static const Vector2& mingfx::Vector2::UnitY ( )
static

(0,1) - a shortcut for a special vector that is frequently needed

◆ value_ptr()

const float* mingfx::Vector2::value_ptr ( ) const

Returns a const pointer to the raw data array.

◆ w()

float mingfx::Vector2::w ( ) const
inline

In homogeneous coordinates, the w coordinate for all vectors is 0.0.

Definition at line 77 of file vector2.h.

◆ x()

float mingfx::Vector2::x ( ) const
inline

Read only access to the x coordinate. Can also use my_vector[0]. Use the my_vector[0] = 1.0; form if you need to set the value.

Definition at line 70 of file vector2.h.

◆ y()

float mingfx::Vector2::y ( ) const
inline

Read only access to the y coordinate. Can also use my_vector[1]. Use the my_vector[1] = 1.0; form if you need to set the value.

Definition at line 74 of file vector2.h.

◆ Zero()

static const Vector2& mingfx::Vector2::Zero ( )
static

(0,0) - a shortcut for a special vector that is frequently needed


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