syBR::Core::Vector3D Class Reference

3D vector class More...

#include <Vector3D.hpp>

List of all members.

Public Member Functions

 Vector3D ()
 Constructor #1.
 Vector3D (float x, float y, float z)
 Constructor #2.
 Vector3D (const Vector3D &vector)
 Copy constructor.
const float getX () const
 Get the x coordinate of the vector.
const float getY () const
 Get the y coordinate of the vector.
const float getZ () const
 Get the z coordinate of the vector.
void set (const float x, const float y, const float z)
 Set the coordinates of the vector.
void setX (const float x)
 Set the x coordinate of the vector.
void setY (const float y)
 Set the y coordinate of the vector.
void setZ (const float z)
 Set the z coordinate of the vector.
void from3Array (const float array[3])
 Set the coordinates of the vector from a 3-element array.
const float getLength () const
 Calculate the length (magnitude) of the vector.
Vector3D normalize () const
 Return a normalized vector which have the same directions as this vector.
float dotProduct (const Vector3D &right) const
 Calculate the dot product of this vector and another one.
Vector3D crossProduct (const Vector3D &right) const
 Calculate the cross product of this vector and another one.
Vector3Doperator= (const Vector3D &arg)
 Set the vector coordinates using an "=" operator.
Vector3D operator+ (const Vector3D &arg) const
 Add a vector using a "+" operator.
Vector3D operator- (const Vector3D &arg) const
 Substract a vector using a "-" operator.
Vector3D operator * (const float arg) const
 Multiply coordinates by a scalar using a "*" operator.
Vector3D operator/ (const float arg) const
 Divide coordinates by a scalar using a "/" operator.
void operator+= (const Vector3D &arg)
 Add the coordinates of a vector to those of this using a "+=" operator.
void operator-= (const Vector3D &arg)
 Substract the coordinates of a vector from those of this using a "-=" operator.
void operator *= (const float arg)
 Multiply the coordinates of this by a scalar using a "*=" operator.
void operator/= (const float arg)
 Divide the coordinates of this by a scalar using a "/=" operator.
bool operator== (const Vector3D &arg) const
 Compare a vector to this.
bool operator!= (const Vector3D &arg) const
 Compare a vector to this.

Private Attributes

float m_x
 x coordinate of the vector
float m_y
 y coordinate of the vector
float m_z
 z coordinate of the vector
float m_length
 Length of the vector (0 if not calculated yet).
bool m_lengthChanged
 Indicate if length has been changed since last time it was calculated (it avoids to re-calculate the length too many times).


Detailed Description

3D vector class

Constructor & Destructor Documentation

syBR::Core::Vector3D::Vector3D (  ) 

Constructor #1.

Initialize vector to (0,0,0)

syBR::Core::Vector3D::Vector3D ( float  x,
float  y,
float  z 
)

Constructor #2.

Initialize vector to specific coordinates

Parameters:
x X coordinate of the vector
y Y coordinate of the vector
z Z coordinate of the vector

syBR::Core::Vector3D::Vector3D ( const Vector3D vector  ) 

Copy constructor.

Parameters:
vector 3D vector from which coordinates must be copied


Member Function Documentation

const float syBR::Core::Vector3D::getX (  )  const [inline]

Get the x coordinate of the vector.

Returns:
x coordinate

const float syBR::Core::Vector3D::getY (  )  const [inline]

Get the y coordinate of the vector.

Returns:
y coordinate

const float syBR::Core::Vector3D::getZ (  )  const [inline]

Get the z coordinate of the vector.

Returns:
z coordinate

void syBR::Core::Vector3D::set ( const float  x,
const float  y,
const float  z 
)

Set the coordinates of the vector.

Parameters:
x X coordinate of the vector
y Y coordinate of the vector
z Z coordinate of the vector

void syBR::Core::Vector3D::setX ( const float  x  ) 

Set the x coordinate of the vector.

Parameters:
x X coordinate of the vector

void syBR::Core::Vector3D::setY ( const float  y  ) 

Set the y coordinate of the vector.

Parameters:
y Y coordinate of the vector

void syBR::Core::Vector3D::setZ ( const float  z  ) 

Set the z coordinate of the vector.

Parameters:
z Z coordinate of the vector

void syBR::Core::Vector3D::from3Array ( const float  array[3]  ) 

Set the coordinates of the vector from a 3-element array.

Parameters:
array Array containing the (x,y,z) coordinates

const float syBR::Core::Vector3D::getLength (  )  const

Calculate the length (magnitude) of the vector.

Returns:
Length/magnitude of the vector
Note:
If called twice without modifying coordinates, it won't calculate it again (it stores the result).

Vector3D syBR::Core::Vector3D::normalize (  )  const

Return a normalized vector which have the same directions as this vector.

Returns:
One of these:
  • Corresponding normalized vector if length is not null
  • Same vector otherwise

float syBR::Core::Vector3D::dotProduct ( const Vector3D right  )  const

Calculate the dot product of this vector and another one.

Parameters:
right Second vector used for calculating the dot product
Returns:
Dot product (scalar) of the two vectors, i.e. <*this,right>

Vector3D syBR::Core::Vector3D::crossProduct ( const Vector3D right  )  const

Calculate the cross product of this vector and another one.

Parameters:
right Second vector used for calculating the cross product
Returns:
Cross product (vector) of the two vectors, i.e. (*this)X (right)

Vector3D & syBR::Core::Vector3D::operator= ( const Vector3D arg  ) 

Set the vector coordinates using an "=" operator.

Parameters:
arg New coordinates to set
Returns:
Vector containing the new coordinates (a reference to *this)

Vector3D syBR::Core::Vector3D::operator+ ( const Vector3D arg  )  const

Add a vector using a "+" operator.

Parameters:
arg Coordinates to add
Returns:
New vector which coordinates are the sum of the coordinates of this and arg

Vector3D syBR::Core::Vector3D::operator- ( const Vector3D arg  )  const

Substract a vector using a "-" operator.

Parameters:
arg Coordinates to substract
Returns:
New vector which coordinates are the difference of the coordinates of this and arg

Vector3D syBR::Core::Vector3D::operator * ( const float  arg  )  const

Multiply coordinates by a scalar using a "*" operator.

Parameters:
arg Scalar to multiply by
Returns:
New vector which coordinates are those of this multiplied by arg

Vector3D syBR::Core::Vector3D::operator/ ( const float  arg  )  const

Divide coordinates by a scalar using a "/" operator.

Parameters:
arg Scalar to divide by
Returns:
New vector which coordinates are those of this divided by arg
Note:
Nothing is done if arg is 0 or 1.

void syBR::Core::Vector3D::operator+= ( const Vector3D arg  ) 

Add the coordinates of a vector to those of this using a "+=" operator.

Parameters:
arg Coordinates to add

void syBR::Core::Vector3D::operator-= ( const Vector3D arg  ) 

Substract the coordinates of a vector from those of this using a "-=" operator.

Parameters:
arg Coordinates to substract

void syBR::Core::Vector3D::operator *= ( const float  arg  ) 

Multiply the coordinates of this by a scalar using a "*=" operator.

Parameters:
arg Coordinates to multiply by

void syBR::Core::Vector3D::operator/= ( const float  arg  ) 

Divide the coordinates of this by a scalar using a "/=" operator.

Parameters:
arg Scalar to divide by
Note:
Nothing is done if arg is 0 or 1.

bool syBR::Core::Vector3D::operator== ( const Vector3D arg  )  const

Compare a vector to this.

Parameters:
arg Vector to compare to
Returns:
true if they are equal, false otherwise
Note:
The comparison takes rounding errors in account by using the Math::EPSILON() constant.

bool syBR::Core::Vector3D::operator!= ( const Vector3D arg  )  const

Compare a vector to this.

Parameters:
arg Vector to compare to
Returns:
true if they are different, false otherwise
Note:
The comparison takes rounding errors in account by using the Math::EPSILON constant.


Member Data Documentation

float syBR::Core::Vector3D::m_x [private]

x coordinate of the vector

float syBR::Core::Vector3D::m_y [private]

y coordinate of the vector

float syBR::Core::Vector3D::m_z [private]

z coordinate of the vector

float syBR::Core::Vector3D::m_length [private]

Length of the vector (0 if not calculated yet).

bool syBR::Core::Vector3D::m_lengthChanged [private]

Indicate if length has been changed since last time it was calculated (it avoids to re-calculate the length too many times).


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

Copyright © 2008 by Sebastien Frippiat
Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 License.
Last modified Tue Dec 30 17:57:33 2008