vhdVector3 Class Reference

#include <vhdVector3.h>

List of all members.

Public Member Functions

 vhdVector3 ()
 vhdVector3 (vhtReal fX, vhtReal fY, vhtReal fZ)
 vhdVector3 (vhtReal afCoordinate[3])
 vhdVector3 (int afCoordinate[3])
 vhdVector3 (const vhtReal *const r)
 vhdVector3 (const vhdVector3 &rkVector)
vhtReal get (unsigned int index) const
void set (unsigned int index, vhtReal value)
vhtRealoperator[] (int index) const
 operator vhtReal * ()
 operator const vhtReal * () const
vhdVector3operator= (const vhdVector3 &rkVector)
bool operator== (const vhdVector3 &rkVector) const
bool operator!= (const vhdVector3 &rkVector) const
bool isZero () const
bool isUnit () const
vhdVector3 operator+ (const vhdVector3 &rkVector) const
vhdVector3 operator- (const vhdVector3 &rkVector) const
vhdVector3 operator * (vhtReal fScalar) const
vhdVector3 operator * (const vhdVector3 &rhs) const
vhdVector3 operator/ (vhtReal fScalar) const
vhdVector3 operator- () const
vhdVector3operator+= (const vhdVector3 &rkVector)
vhdVector3operator-= (const vhdVector3 &rkVector)
vhdVector3operator *= (vhtReal fScalar)
vhdVector3operator/= (vhtReal fScalar)
vhdVector3operator *= (const vhdVector3 &rkVector)
vhdVector3operator/= (const vhdVector3 &rkVector)
vhtReal length () const
vhtReal squaredLength () const
vhtReal dotProduct (const vhdVector3 &vec) const
vhdVector3normalise ()
vhdVector3 getNormalized () const
vhdVector3 crossProduct (const vhdVector3 &rkVector) const
vhdVector3 midPoint (const vhdVector3 &vec) const
bool operator< (const vhdVector3 &rhs) const
bool operator> (const vhdVector3 &rhs) const
void makeFloor (const vhdVector3 &cmp)
void makeCeil (const vhdVector3 &cmp)
vhdVector3 perpendicular (void)
vhdVector3 randomDeviant (vhtReal angle, const vhdVector3 &up=vhdVector3::ZERO)
vhdQuaternion getRotationTo (const vhdVector3 &dest) const
vhtReal distance (const vhdVector3 &point) const
vhtReal squaredDistance (const vhdVector3 &point) const

Static Public Member Functions

static void generateOrthonormalBasis (vhdVector3 &rkU, vhdVector3 &rkV, vhdVector3 &rkW, bool bUnitLengthW)

Public Attributes

vhtReal x
vhtReal y
vhtReal z

Static Public Attributes

static const vhdVector3 ZERO
static const vhdVector3 UNIT_X
static const vhdVector3 UNIT_Y
static const vhdVector3 UNIT_Z
static const vhdVector3 UNIT_SCALE

Friends

vhdVector3 operator * (vhtReal fScalar, const vhdVector3 &rkVector)
std::ostream & operator<< (std::ostream &o, const vhdVector3 &v)


Constructor & Destructor Documentation

vhdVector3::vhdVector3 (  )  [inline]

vhdVector3::vhdVector3 ( vhtReal  fX,
vhtReal  fY,
vhtReal  fZ 
) [inline]

vhdVector3::vhdVector3 ( vhtReal  afCoordinate[3]  )  [inline]

vhdVector3::vhdVector3 ( int  afCoordinate[3]  )  [inline]

vhdVector3::vhdVector3 ( const vhtReal *const  r  )  [inline]

vhdVector3::vhdVector3 ( const vhdVector3 rkVector  )  [inline]


Member Function Documentation

vhtReal vhdVector3::get ( unsigned int  index  )  const [inline]

void vhdVector3::set ( unsigned int  index,
vhtReal  value 
) [inline]

vhtReal & vhdVector3::operator[] ( int  index  )  const [inline]

vhdVector3::operator vhtReal * (  )  [inline]

Cast operator for vhtReal*.

vhdVector3::operator const vhtReal * (  )  const [inline]

Cast operator for const vhtReal*.

vhdVector3 & vhdVector3::operator= ( const vhdVector3 rkVector  )  [inline]

Assigns the value of the other vector.

Parameters:
rkVector The other vector

bool vhdVector3::operator== ( const vhdVector3 rkVector  )  const [inline]

bool vhdVector3::operator!= ( const vhdVector3 rkVector  )  const [inline]

bool vhdVector3::isZero (  )  const [inline]

Returns true if this vector is zero (all elements < epsilon).

bool vhdVector3::isUnit (  )  const [inline]

Returns true if this vector is a unit-length vector. Also considers floating-point imprecision by using epsilon.

vhdVector3 vhdVector3::operator+ ( const vhdVector3 rkVector  )  const [inline]

vhdVector3 vhdVector3::operator- ( const vhdVector3 rkVector  )  const [inline]

vhdVector3 vhdVector3::operator * ( vhtReal  fScalar  )  const [inline]

vhdVector3 vhdVector3::operator * ( const vhdVector3 rhs  )  const [inline]

vhdVector3 vhdVector3::operator/ ( vhtReal  fScalar  )  const [inline]

vhdVector3 vhdVector3::operator- (  )  const [inline]

vhdVector3 & vhdVector3::operator+= ( const vhdVector3 rkVector  )  [inline]

vhdVector3 & vhdVector3::operator-= ( const vhdVector3 rkVector  )  [inline]

vhdVector3 & vhdVector3::operator *= ( vhtReal  fScalar  )  [inline]

vhdVector3 & vhdVector3::operator/= ( vhtReal  fScalar  )  [inline]

vhdVector3 & vhdVector3::operator *= ( const vhdVector3 rkVector  )  [inline]

vhdVector3 & vhdVector3::operator/= ( const vhdVector3 rkVector  )  [inline]

vhtReal vhdVector3::length (  )  const [inline]

Returns the length (magnitude) of the vector.

Warning:
This operation requires a square root and is expensive in terms of CPU operations. If you don't need to know the exact length (e.g. for just comparing lengths) use squaredLength() instead.

vhtReal vhdVector3::squaredLength (  )  const [inline]

Returns the square of the length(magnitude) of the vector.

Remarks:
This method is for efficiency - calculating the actual length of a vector requires a square root, which is expensive in terms of the operations required. This method returns the square of the length of the vector, i.e. the same as the length but before the square root is taken. Use this if you want to find the longest / shortest vector without incurring the square root.

vhtReal vhdVector3::dotProduct ( const vhdVector3 vec  )  const [inline]

Calculates the dot (scalar) product of this vector with another.

Remarks:
The dot product can be used to calculate the angle between 2 vectors. If both are unit vectors, the dot product is the cosine of the angle; otherwise the dot product must be divided by the product of the lengths of both vectors to get the cosine of the angle. This result can further be used to calculate the distance of a point from a plane.
Parameters:
vec Vector with which to calculate the dot product (together with this one).
Returns:
A float representing the dot product value.

vhdVector3 & vhdVector3::normalise (  )  [inline]

Normalises the vector.

Remarks:
This method normalises the vector such that it's length / magnitude is 1. The result is called a unit vector.
Note:
This function will not crash for zero-sized vectors, but there will be no changes made to their components.

vhdVector3 vhdVector3::getNormalized (  )  const [inline]

Returns a normalized version of this vector.

vhdVector3 vhdVector3::crossProduct ( const vhdVector3 rkVector  )  const [inline]

Calculates the cross-product of 2 vectors, i.e. the vector that lies perpendicular to them both.

Remarks:
The cross-product is normally used to calculate the normal vector of a plane, by calculating the cross-product of 2 non-equivalent vectors which lie on the plane (e.g. 2 edges of a triangle).
Parameters:
vec Vector which, together with this one, will be used to calculate the cross-product.
Returns:
A vector which is the result of the cross-product. This vector will NOT be normalised, to maximise efficiency
  • call vhdVector3::normalise on the result if you wish this to be done. As for which side the resultant vector will be on, the returned vector will be on the side from which the arc from 'this' to rkVector is anticlockwise, e.g. UNIT_Y.crossProduct(UNIT_Z) = UNIT_X, whilst UNIT_Z.crossProduct(UNIT_Y) = -UNIT_X.
For a clearer explanation, look a the left and the bottom edges of your monitor's screen. Assume that the first vector is the left edge and the second vector is the bottom edge, both of them starting from the lower-left corner of the screen. The resulting vector is going to be perpendicular to both of them and will go inside the screen, towards the cathode tube (assuming you're using a CRT monitor, of course).

vhdVector3 vhdVector3::midPoint ( const vhdVector3 vec  )  const [inline]

Returns a vector at a point half way between this and the passed in vector.

bool vhdVector3::operator< ( const vhdVector3 rhs  )  const [inline]

Returns true if the vector's scalar components are all greater that the ones of the vector it is compared against.

bool vhdVector3::operator> ( const vhdVector3 rhs  )  const [inline]

Returns true if the vector's scalar components are all smaller that the ones of the vector it is compared against.

void vhdVector3::makeFloor ( const vhdVector3 cmp  )  [inline]

Sets this vector's components to the minimum of its own and the ones of the passed in vector.

Remarks:
'Minimum' in this case means the combination of the lowest value of x, y and z from both vectors. Lowest is taken just numerically, not magnitude, so -1 < 0.

void vhdVector3::makeCeil ( const vhdVector3 cmp  )  [inline]

Sets this vector's components to the maximum of its own and the ones of the passed in vector.

Remarks:
'Maximum' in this case means the combination of the highest value of x, y and z from both vectors. Highest is taken just numerically, not magnitude, so 1 > -3.

vhdVector3 vhdVector3::perpendicular ( void   )  [inline]

Generates a vector perpendicular to this vector (eg an 'up' vector).

Remarks:
This method will return a vector which is perpendicular to this vector. There are an infinite number of possibilities but this method will guarantee to generate one of them. If you need more control you should use the vhdQuaternion class.

vhdVector3 vhdVector3::randomDeviant ( vhtReal  angle,
const vhdVector3 up = vhdVector3::ZERO 
) [inline]

Generates a new random vector which deviates from this vector by a given angle in a random direction.

Remarks:
This method assumes that the random number generator has already been seeded appropriately.
Parameters:
angle The angle at which to deviate in radians
up Any vector perpendicular to this one (which could generated by cross-product of this vector and any other non-colinear vector). If you choose not to provide this the function will derive one on it's own, however if you provide one yourself the function will be faster (this allows you to reuse up vectors if you call this method more than once)
Returns:
A random vector which deviates from this vector by angle. This vector will not be normalised, normalise it if you wish afterwards.

vhdQuaternion vhdVector3::getRotationTo ( const vhdVector3 dest  )  const

vhtReal vhdVector3::distance ( const vhdVector3 point  )  const [inline]

Returns distance between this vector and argument vector

vhtReal vhdVector3::squaredDistance ( const vhdVector3 point  )  const [inline]

Returns distance between this vector and argument vector

void vhdVector3::generateOrthonormalBasis ( vhdVector3 rkU,
vhdVector3 rkV,
vhdVector3 rkW,
bool  bUnitLengthW 
) [static]


Friends And Related Function Documentation

vhdVector3 operator * ( vhtReal  fScalar,
const vhdVector3 rkVector 
) [friend]

std::ostream& operator<< ( std::ostream &  o,
const vhdVector3 v 
) [friend]


Member Data Documentation

vhtReal vhdVector3::x

vhtReal vhdVector3::y

vhtReal vhdVector3::z

const vhdVector3 vhdVector3::ZERO [static]

const vhdVector3 vhdVector3::UNIT_X [static]

const vhdVector3 vhdVector3::UNIT_Y [static]

const vhdVector3 vhdVector3::UNIT_Z [static]

const vhdVector3 vhdVector3::UNIT_SCALE [static]


Generated on Thu Jan 18 10:06:27 2007 for vhdPLUS by  doxygen 1.5.1-p1