Algebra::TVector Struct Reference

#include <Algebra.h>

List of all members.


Detailed Description

Vector class.

Basic functionality of a 3D vector. The class is designed to be compatible with standard class for 3D vector SbVec3f used in Open Inventor.


Public Member Functions

 TVector ()
 Default constructor.
 TVector (const float v[3])
 Initializing constructor.
 TVector (const float x, const float y, const float z)
 Initializing constructor.
 TVector (const TVector &v)
 Copy constructor.
const float * getValue () const
 Returns the components of the vector.
void getValue (float &x, float &y, float &z) const
 Returns the components of the vector.
TVectorsetValue (const float v[3])
 Sets the components of the vector.
TVectorsetValue (const float x, const float y, const float z)
 Sets the components of the vector.
float & operator[] (const int i)
 Returns one component of the vector.
const float & operator[] (const int i) const
 Returns one component of the vector.
TVectoroperator *= (const float d)
 Multiply components of the vector by the scalar value d.
TVectoroperator/= (const float d)
 Divides components of the vector by the scalar value d.
TVectoroperator+= (const TVector &u)
 Adds u vector to this vector.
TVectoroperator-= (const TVector &u)
 Substract u vector from this vector.
TVector operator- () const
 Non-destructive operator that returns a vector of the opposite direction.
TVector cross (const TVector &v) const
 Returns cross product with vector v.
float dot (const TVector &v) const
 Returns dot product with vector v.
bool equals (const TVector &v, const float sqrTolerance) const
 Returns true if the vector does not differ from the vector v more than tolerance.
TVector getClosestAxis () const
 Returns closest axis of the vector.
float length () const
 Returns length of the vector.
float sqrLength () const
 Returns square length of the vector.
void negate ()
 Switches the direction of the vector to the opposite.
float normalize ()
 Normalizes the length of the vector to the unit.

Private Attributes

float vec [3]
 Vector data.


Member Function Documentation

TVector Algebra::TVector::cross const TVector v  )  const
 

Returns cross product with vector v.

Returns the cross-product of this vector and the vector v.

Time cost: low (one constructor, 6 multiplications, 3 substractions)

float Algebra::TVector::dot const TVector v  )  const
 

Returns dot product with vector v.

Returns the dot-product of this vector and the vector v.

Time cost: very low (3 multiplications, 2 additions)

bool Algebra::TVector::equals const TVector v,
const float  sqrTolerance
const
 

Returns true if the vector does not differ from the vector v more than tolerance.

Compares the vector with vector v to see if distance between their end-points is less or equal to root of sqrTolerance.

Time cost: very low (3 multiplications, 2+3 adds/subs, 1 compare)

TVector Algebra::TVector::getClosestAxis  )  const
 

Returns closest axis of the vector.

The function find out to which of x,y and z axis this vector is the closest. Then it returns the unit vector in the direction of this axis.

float Algebra::TVector::length  )  const
 

Returns length of the vector.

Returns the length of the vector. When possible, use sqrLength() instead, because it does not need to compute square root that is CPU expensive operation.

Time cost: high (1 square root)

void Algebra::TVector::negate  ) 
 

Switches the direction of the vector to the opposite.

Returns the same vector but of opposite direction. The original vector is not modified.

float Algebra::TVector::normalize  ) 
 

Normalizes the length of the vector to the unit.

The function normalizes the vector to the unit length. It returns the original length of the vector before normalization.

Time cost: high (1 square root, 1 division)

float Algebra::TVector::sqrLength  )  const
 

Returns square length of the vector.

Returns the square of vector length. sqrLength() is preffered over length(), because it does not need to compute square root that is CPU expensive operation.

Time cost: very low (3 mult, 2 adds)


The documentation for this struct was generated from the following files:
Viewable With Any Browser   Valid HTML 4.01!   Generated on Fri Apr 14 08:04:34 2006 for TankGame by doxygen 1.4.6-NO