Public Member Functions | Public Attributes | Related Functions | List of all members
cpp3ds::Vector3< T > Class Template Reference

Utility template class for manipulating 3-dimensional vectors. More...

#include <Vector3.hpp>

Public Member Functions

 Vector3 ()
 Default constructor. More...
 
 Vector3 (T X, T Y, T Z)
 Construct the vector from its coordinates. More...
 
template<typename U >
 Vector3 (const Vector3< U > &vector)
 Construct the vector from another type of vector. More...
 

Public Attributes

x
 X coordinate of the vector. More...
 
y
 Y coordinate of the vector. More...
 
z
 Z coordinate of the vector. More...
 

Related Functions

(Note that these are not member functions.)

template<typename T >
Vector3< T > operator- (const Vector3< T > &left)
 Overload of unary operator -. More...
 
template<typename T >
Vector3< T > & operator+= (Vector3< T > &left, const Vector3< T > &right)
 Overload of binary operator +=. More...
 
template<typename T >
Vector3< T > & operator-= (Vector3< T > &left, const Vector3< T > &right)
 Overload of binary operator -=. More...
 
template<typename T >
Vector3< T > operator+ (const Vector3< T > &left, const Vector3< T > &right)
 Overload of binary operator +. More...
 
template<typename T >
Vector3< T > operator- (const Vector3< T > &left, const Vector3< T > &right)
 Overload of binary operator -. More...
 
template<typename T >
Vector3< T > operator* (const Vector3< T > &left, T right)
 Overload of binary operator *. More...
 
template<typename T >
Vector3< T > operator* (T left, const Vector3< T > &right)
 Overload of binary operator *. More...
 
template<typename T >
Vector3< T > & operator*= (Vector3< T > &left, T right)
 Overload of binary operator *=. More...
 
template<typename T >
Vector3< T > operator/ (const Vector3< T > &left, T right)
 Overload of binary operator /. More...
 
template<typename T >
Vector3< T > & operator/= (Vector3< T > &left, T right)
 Overload of binary operator /=. More...
 
template<typename T >
bool operator== (const Vector3< T > &left, const Vector3< T > &right)
 Overload of binary operator ==. More...
 
template<typename T >
bool operator!= (const Vector3< T > &left, const Vector3< T > &right)
 Overload of binary operator !=. More...
 

Detailed Description

template<typename T>
class cpp3ds::Vector3< T >

Utility template class for manipulating 3-dimensional vectors.

cpp3ds::Vector3 is a simple class that defines a mathematical vector with three coordinates (x, y and z).

It can be used to represent anything that has three dimensions: a size, a point, a velocity, etc.

The template parameter T is the type of the coordinates. It can be any type that supports arithmetic operations (+, -, /, *) and comparisons (==, !=), for example int or float.

You generally don't have to care about the templated form (cpp3ds::Vector3<T>), the most common specializations have special typedefs:

The cpp3ds::Vector3 class has a small and simple interface, its x and y members can be accessed directly (there's no accessor like setX(), getX()) and it contains no mathematical function like dot product, cross product, length, etc.

Usage example:

cpp3ds::Vector3f v1(16.5f, 24.f, -8.2f);
v1.x = 18.2f;
float y = v1.y;
float z = v1.z;
cpp3ds::Vector3f v2 = v1 * 5.f;
v3 = v1 + v2;
bool different = (v2 != v3);

Note: for 2-dimensional vectors, see cpp3ds::Vector2.

Definition at line 37 of file Vector3.hpp.

Constructor & Destructor Documentation

template<typename T>
cpp3ds::Vector3< T >::Vector3 ( )

Default constructor.

Creates a Vector3(0, 0, 0).

template<typename T>
cpp3ds::Vector3< T >::Vector3 ( X,
Y,
Z 
)

Construct the vector from its coordinates.

Parameters
XX coordinate
YY coordinate
ZZ coordinate
template<typename T>
template<typename U >
cpp3ds::Vector3< T >::Vector3 ( const Vector3< U > &  vector)
explicit

Construct the vector from another type of vector.

This constructor doesn't replace the copy constructor, it's called only when U != T. A call to this constructor will fail to compile if U is not convertible to T.

Parameters
vectorVector to convert

Friends And Related Function Documentation

template<typename T >
bool operator!= ( const Vector3< T > &  left,
const Vector3< T > &  right 
)
related

Overload of binary operator !=.

This operator compares strict difference between two vectors.

Parameters
leftLeft operand (a vector)
rightRight operand (a vector)
Returns
True if left is not equal to right
template<typename T >
Vector3< T > operator* ( const Vector3< T > &  left,
right 
)
related

Overload of binary operator *.

Parameters
leftLeft operand (a vector)
rightRight operand (a scalar value)
Returns
Memberwise multiplication by right
template<typename T >
Vector3< T > operator* ( left,
const Vector3< T > &  right 
)
related

Overload of binary operator *.

Parameters
leftLeft operand (a scalar value)
rightRight operand (a vector)
Returns
Memberwise multiplication by left
template<typename T >
Vector3< T > & operator*= ( Vector3< T > &  left,
right 
)
related

Overload of binary operator *=.

This operator performs a memberwise multiplication by right, and assigns the result to left.

Parameters
leftLeft operand (a vector)
rightRight operand (a scalar value)
Returns
Reference to left
template<typename T >
Vector3< T > operator+ ( const Vector3< T > &  left,
const Vector3< T > &  right 
)
related

Overload of binary operator +.

Parameters
leftLeft operand (a vector)
rightRight operand (a vector)
Returns
Memberwise addition of both vectors
template<typename T >
Vector3< T > & operator+= ( Vector3< T > &  left,
const Vector3< T > &  right 
)
related

Overload of binary operator +=.

This operator performs a memberwise addition of both vectors, and assigns the result to left.

Parameters
leftLeft operand (a vector)
rightRight operand (a vector)
Returns
Reference to left
template<typename T >
Vector3< T > operator- ( const Vector3< T > &  left)
related

Overload of unary operator -.

Parameters
leftVector to negate
Returns
Memberwise opposite of the vector
template<typename T >
Vector3< T > operator- ( const Vector3< T > &  left,
const Vector3< T > &  right 
)
related

Overload of binary operator -.

Parameters
leftLeft operand (a vector)
rightRight operand (a vector)
Returns
Memberwise subtraction of both vectors
template<typename T >
Vector3< T > & operator-= ( Vector3< T > &  left,
const Vector3< T > &  right 
)
related

Overload of binary operator -=.

This operator performs a memberwise subtraction of both vectors, and assigns the result to left.

Parameters
leftLeft operand (a vector)
rightRight operand (a vector)
Returns
Reference to left
template<typename T >
Vector3< T > operator/ ( const Vector3< T > &  left,
right 
)
related

Overload of binary operator /.

Parameters
leftLeft operand (a vector)
rightRight operand (a scalar value)
Returns
Memberwise division by right
template<typename T >
Vector3< T > & operator/= ( Vector3< T > &  left,
right 
)
related

Overload of binary operator /=.

This operator performs a memberwise division by right, and assigns the result to left.

Parameters
leftLeft operand (a vector)
rightRight operand (a scalar value)
Returns
Reference to left
template<typename T >
bool operator== ( const Vector3< T > &  left,
const Vector3< T > &  right 
)
related

Overload of binary operator ==.

This operator compares strict equality between two vectors.

Parameters
leftLeft operand (a vector)
rightRight operand (a vector)
Returns
True if left is equal to right

Member Data Documentation

template<typename T>
T cpp3ds::Vector3< T >::x

X coordinate of the vector.

Definition at line 76 of file Vector3.hpp.

template<typename T>
T cpp3ds::Vector3< T >::y

Y coordinate of the vector.

Definition at line 77 of file Vector3.hpp.

template<typename T>
T cpp3ds::Vector3< T >::z

Z coordinate of the vector.

Definition at line 78 of file Vector3.hpp.


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