Oficina Framework  1.3
Games Framework
vec2 Class Reference

A class representing a point in 2D space. More...

#include <OficinaTypes.hpp>

Public Member Functions

 vec2 ()
 Constructs class with null values. More...
 
 vec2 (float n)
 Constructs class with two equal values. More...
 
 vec2 (float X, float Y)
 Constructs class with two values. More...
 
vec2operator= (const vec2)
 
vec2operator= (const float)
 
const vec2 operator+ (const vec2)
 
const vec2 operator+ (const float)
 
vec2operator+= (const vec2)
 
vec2operator+= (const float)
 
const vec2 operator- (const vec2)
 
const vec2 operator- (const float)
 
vec2operator-= (const vec2)
 
vec2operator-= (const float)
 
const vec2 operator* (const vec2)
 
const vec2 operator* (const float)
 
vec2operator*= (const vec2)
 
vec2operator*= (const float)
 
const vec2 operator/ (const vec2)
 
const vec2 operator/ (const float)
 
vec2operator/= (const vec2)
 
vec2operator/= (const float)
 
bool operator> (const vec2)
 
bool operator> (const float)
 
bool operator< (const vec2)
 
bool operator< (const float)
 
bool operator>= (const vec2)
 
bool operator>= (const float)
 
bool operator<= (const vec2)
 
bool operator<= (const float)
 
bool operator== (const vec2)
 
bool operator== (const float)
 
bool operator!= (const vec2)
 
bool operator!= (const float)
 
vec2 getTruncated ()
 Returns a copy of this vec2 truncated to the nearest integer. More...
 
void truncate ()
 Truncates the coordinates of this. More...
 
float length ()
 Gets the magnitude (length) of this vector. More...
 
vec2 getNormalized ()
 Gets a normalized version of this vector. More...
 
void normalize ()
 Normalizes this vector. More...
 
void clamp (vec2 origin, vec2 end)
 Encloses this vector inside a box, with its edges described by two other vectors. More...
 
std::string toString ()
 Getsa string with the vec2 values. More...
 

Static Public Member Functions

static vec2 Zero ()
 Returns a vec2 with both coordinates having the value 0.0f. More...
 
static vec2 One ()
 Returns a vec2 with both coordinates having the value 1.0f. More...
 
static vec2 Up ()
 Returns a vec2 with coordinates indicating the Up direction. More...
 
static vec2 Down ()
 Returns a vec2 with coordinates indicating the Down direction. More...
 
static vec2 Left ()
 Returns a vec2 with coordinates indicating the Left direction. More...
 
static vec2 Right ()
 Returns a vec2 with coordinates indicating the Right direction. More...
 
static float distance (vec2 first, vec2 second)
 Calculates the distance between two vectors. More...
 
static float squareDistance (vec2 first, vec2 second)
 Calculates the square distance between two vectors. Useful if you don't want the Square Root operation to be executed on the value for performance reasons. More...
 

Public Attributes

union {
   struct {
      float   x
 X coordinate of point. More...
 
      float   y
 Y coordinate of point. More...
 
   } 
 
   struct {
      float   v [2]
 Array of coordinates of the point. More...
 
   } 
 
}; 
 

Friends

std::ostream & operator<< (std::ostream &oss, const vec2 &v)
 

Detailed Description

A class representing a point in 2D space.

Constructor & Destructor Documentation

◆ vec2() [1/3]

vec2::vec2 ( )

Constructs class with null values.

◆ vec2() [2/3]

vec2::vec2 ( float  n)

Constructs class with two equal values.

Parameters
nValue to be given to coordinates.

◆ vec2() [3/3]

vec2::vec2 ( float  X,
float  Y 
)

Constructs class with two values.

Parameters
XValue to be given to x coordinate.
YValue to be given to y coordinate.

Member Function Documentation

◆ clamp()

void vec2::clamp ( vec2  origin,
vec2  end 
)

Encloses this vector inside a box, with its edges described by two other vectors.

Parameters
originMinimum values for the vector.
endMaximum values for the vector.
Warning
In case a single coordinate of origin is bigger than end's, the vector will not be clamped on that coordinate.

◆ distance()

static float vec2::distance ( vec2  first,
vec2  second 
)
static

Calculates the distance between two vectors.

Parameters
firstFirst vector.
secondSecond vector.
Returns
Distance value between the two desired points.

◆ Down()

static vec2 vec2::Down ( )
static

Returns a vec2 with coordinates indicating the Down direction.

Returns
A down-facing vec2.

◆ getNormalized()

vec2 vec2::getNormalized ( )

Gets a normalized version of this vector.

Returns
A normalized vector.

◆ getTruncated()

vec2 vec2::getTruncated ( )

Returns a copy of this vec2 truncated to the nearest integer.

Returns
The truncated vec2 of this.

◆ Left()

static vec2 vec2::Left ( )
static

Returns a vec2 with coordinates indicating the Left direction.

Returns
A left-facing vec2.

◆ length()

float vec2::length ( )

Gets the magnitude (length) of this vector.

Returns
The magnitude of this vector.

◆ normalize()

void vec2::normalize ( )

Normalizes this vector.

◆ One()

static vec2 vec2::One ( )
static

Returns a vec2 with both coordinates having the value 1.0f.

Returns
An unitary-value vec2.

◆ operator!=() [1/2]

bool vec2::operator!= ( const vec2  )

◆ operator!=() [2/2]

bool vec2::operator!= ( const float  )

◆ operator*() [1/2]

const vec2 vec2::operator* ( const vec2  )

◆ operator*() [2/2]

const vec2 vec2::operator* ( const float  )

◆ operator*=() [1/2]

vec2& vec2::operator*= ( const vec2  )

◆ operator*=() [2/2]

vec2& vec2::operator*= ( const float  )

◆ operator+() [1/2]

const vec2 vec2::operator+ ( const vec2  )

◆ operator+() [2/2]

const vec2 vec2::operator+ ( const float  )

◆ operator+=() [1/2]

vec2& vec2::operator+= ( const vec2  )

◆ operator+=() [2/2]

vec2& vec2::operator+= ( const float  )

◆ operator-() [1/2]

const vec2 vec2::operator- ( const vec2  )

◆ operator-() [2/2]

const vec2 vec2::operator- ( const float  )

◆ operator-=() [1/2]

vec2& vec2::operator-= ( const vec2  )

◆ operator-=() [2/2]

vec2& vec2::operator-= ( const float  )

◆ operator/() [1/2]

const vec2 vec2::operator/ ( const vec2  )

◆ operator/() [2/2]

const vec2 vec2::operator/ ( const float  )

◆ operator/=() [1/2]

vec2& vec2::operator/= ( const vec2  )

◆ operator/=() [2/2]

vec2& vec2::operator/= ( const float  )

◆ operator<() [1/2]

bool vec2::operator< ( const vec2  )

◆ operator<() [2/2]

bool vec2::operator< ( const float  )

◆ operator<=() [1/2]

bool vec2::operator<= ( const vec2  )

◆ operator<=() [2/2]

bool vec2::operator<= ( const float  )

◆ operator=() [1/2]

vec2& vec2::operator= ( const vec2  )

◆ operator=() [2/2]

vec2& vec2::operator= ( const float  )

◆ operator==() [1/2]

bool vec2::operator== ( const vec2  )

◆ operator==() [2/2]

bool vec2::operator== ( const float  )

◆ operator>() [1/2]

bool vec2::operator> ( const vec2  )

◆ operator>() [2/2]

bool vec2::operator> ( const float  )

◆ operator>=() [1/2]

bool vec2::operator>= ( const vec2  )

◆ operator>=() [2/2]

bool vec2::operator>= ( const float  )

◆ Right()

static vec2 vec2::Right ( )
static

Returns a vec2 with coordinates indicating the Right direction.

Returns
A right-facing vec2.

◆ squareDistance()

static float vec2::squareDistance ( vec2  first,
vec2  second 
)
static

Calculates the square distance between two vectors. Useful if you don't want the Square Root operation to be executed on the value for performance reasons.

Parameters
firstFirst vector.
secondSecond vector.
Returns
Square distance value between the two desired points.

◆ toString()

std::string vec2::toString ( )

Getsa string with the vec2 values.

Returns
Values inside vec2, in format {x, y}.

◆ truncate()

void vec2::truncate ( )

Truncates the coordinates of this.

◆ Up()

static vec2 vec2::Up ( )
static

Returns a vec2 with coordinates indicating the Up direction.

Returns
An up-facing vec2.

◆ Zero()

static vec2 vec2::Zero ( )
static

Returns a vec2 with both coordinates having the value 0.0f.

Returns
A null-values vec2.

Friends And Related Function Documentation

◆ operator<<

std::ostream& operator<< ( std::ostream &  oss,
const vec2 v 
)
friend

Member Data Documentation

◆ @1

union { ... }

◆ v

float vec2::v[2]

Array of coordinates of the point.

◆ x

float vec2::x

X coordinate of point.

◆ y

float vec2::y

Y coordinate of point.


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