A 2D vector. More...
#include <vec2.h>
Public Member Functions | |
vec2 () | |
Creates a new, uninitialized vector. | |
vec2 (type xi, type yi) | |
Creates a new vector with the given coordinates. | |
vec2 (const type v[2]) | |
Creates a new vector with the given coordinates. | |
vec2 (const vec2 &v) | |
Creates a new vector as a copy of the given vector. | |
type | operator[] (const int i) const |
Returns the coordinate of this vector whose index is given. | |
type & | operator[] (const int i) |
Returns the coordinate of this vector whose index is given. | |
void | operator= (const vec2 &v) |
Assigns the given vector to this vector. | |
bool | operator== (const vec2 &v) const |
Returns true if this vector is equal to the given vector. | |
bool | operator!= (const vec2 &v) const |
Returns true if this vector is different from the given vector. | |
vec2 | operator+ (const vec2 &v) const |
Returns the sum of this vector and of the given vector. | |
vec2 | operator- (const vec2 &v) const |
Returns the difference of this vector and of the given vector. | |
vec2 | operator* (const vec2 &v) const |
Returns the product of this vector and of the given vector. | |
vec2 | operator* (const type scalar) const |
Returns the product of this vector and of the given scalar. | |
vec2 | operator/ (const vec2 &v) const |
Returns the division of this vector and of the given vector. | |
vec2 | operator/ (const type scalar) const |
Returns the division of this vector and of the given scalar. | |
vec2 | operator- () const |
Returns the opposite of this vector. | |
vec2 & | operator+= (const vec2 &v) |
Adds the given vector to this vector. | |
vec2 & | operator-= (const vec2 &v) |
Substracts the given vector from this vector. | |
vec2 & | operator*= (const type scalar) |
Multiplies this vector by the given scalar. | |
vec2 & | operator/= (const type scalar) |
Divides this vector by the given scalar. | |
bool | operator< (const vec2 &v) const |
Compare first element, then second if equal. | |
type | length () const |
Returns the length of this vector. | |
type | squaredLength () const |
Returns the squared length of this vector. | |
type | dotproduct (const vec2 &v) const |
Returns the dot product of this vector and of the given vector. | |
type | dot (const vec2 &v) const |
Alias for dotproduct, here for compatibility. | |
vec2 | normalize () const |
Returns this vector normalized to unit length. | |
vec2 | normalize (type l) const |
Returns this vector normalized to the given length. | |
vec2 | normalize (type *previousLength) const |
Returns this vector normalized to unit length. | |
vec2 | normalize (type l, type *previousLength) |
Returns this vector normalized to the given length. | |
template<class t > | |
vec2< t > | cast () |
Casts this vector to another base type. | |
Public Attributes | |
type | x |
x coordinate. | |
type | y |
x coordinate. | |
Static Public Attributes | |
static const vec2 | ZERO |
The null vector (0,0). | |
static const vec2 | UNIT_X |
The unit x vector (1,0). | |
static const vec2 | UNIT_Y |
The unit y vector (0,1). |
A 2D vector.
Creates a new vector with the given coordinates.
Creates a new vector with the given coordinates.
Creates a new vector as a copy of the given vector.
Casts this vector to another base type.
Alias for dotproduct, here for compatibility.
type ork::vec2< type >::dotproduct | ( | const vec2< type > & | v | ) | const [inline] |
Returns the dot product of this vector and of the given vector.
type ork::vec2< type >::length | ( | ) | const [inline] |
Returns the length of this vector.
vec2< type > ork::vec2< type >::normalize | ( | type | l, | |
type * | previousLength | |||
) | [inline] |
Returns this vector normalized to the given length.
Returns also its initial length.
vec2< type > ork::vec2< type >::normalize | ( | type * | previousLength | ) | const [inline] |
Returns this vector normalized to unit length.
Returns also its initial length.
Returns this vector normalized to the given length.
Returns this vector normalized to unit length.
bool ork::vec2< type >::operator!= | ( | const vec2< type > & | v | ) | const [inline] |
Returns true if this vector is different from the given vector.
vec2< type > ork::vec2< type >::operator* | ( | const type | scalar | ) | const [inline] |
Returns the product of this vector and of the given scalar.
vec2< type > ork::vec2< type >::operator* | ( | const vec2< type > & | v | ) | const [inline] |
Returns the product of this vector and of the given vector.
The product is done component by component.
Multiplies this vector by the given scalar.
vec2< type > ork::vec2< type >::operator+ | ( | const vec2< type > & | v | ) | const [inline] |
Returns the sum of this vector and of the given vector.
vec2< type > & ork::vec2< type >::operator+= | ( | const vec2< type > & | v | ) | [inline] |
Adds the given vector to this vector.
Returns the opposite of this vector.
vec2< type > ork::vec2< type >::operator- | ( | const vec2< type > & | v | ) | const [inline] |
Returns the difference of this vector and of the given vector.
vec2< type > & ork::vec2< type >::operator-= | ( | const vec2< type > & | v | ) | [inline] |
Substracts the given vector from this vector.
vec2< type > ork::vec2< type >::operator/ | ( | const type | scalar | ) | const [inline] |
Returns the division of this vector and of the given scalar.
vec2< type > ork::vec2< type >::operator/ | ( | const vec2< type > & | v | ) | const [inline] |
Returns the division of this vector and of the given vector.
The division is done component by component.
Divides this vector by the given scalar.
bool ork::vec2< type >::operator< | ( | const vec2< type > & | v | ) | const [inline] |
Compare first element, then second if equal.
Assigns the given vector to this vector.
bool ork::vec2< type >::operator== | ( | const vec2< type > & | v | ) | const [inline] |
Returns true if this vector is equal to the given vector.
type & ork::vec2< type >::operator[] | ( | const int | i | ) | [inline] |
Returns the coordinate of this vector whose index is given.
type ork::vec2< type >::operator[] | ( | const int | i | ) | const [inline] |
Returns the coordinate of this vector whose index is given.
type ork::vec2< type >::squaredLength | ( | ) | const [inline] |
Returns the squared length of this vector.
The unit x vector (1,0).
The unit y vector (0,1).