vector3 Struct Reference

3 component vector More...

#include <3dmath.h>

List of all members.

Public Member Functions

 vector3 (float _x=0, float _y=0, float _z=0)
 Constructor.
 vector3 (const float *v)
 Constructor.
 vector3 (const vector3 &v)
 Copy constructor.
vector3operator= (const vector3 &v)
 Assignment operator.
float operator[] (unsigned i) const
 Get component.
vector3 operator- (const vector3 &v) const
 Subtract operator.
vector3 operator- () const
 Unary operator.
vector3 operator+ (const vector3 &v) const
 Add operator.
vector3 operator* (float f) const
 Scalar multiply operator.
vector3 operator/ (float f) const
 Scalar divide operator.
vector3operator+= (const vector3 &v)
 Add assignment operator.
vector3operator-= (const vector3 &v)
 Subtract assignment operator.
vector3operator*= (float f)
 Multiply assignment operator.
vector3operator/= (float f)
 Divide assignment operator.
bool operator== (const vector3 &v) const
 Equal operator.
bool operator!= (const vector3 &v) const
 Not Equal operator.
bool operator< (const vector3 &v) const
 Less then operator.
float Dot (const vector3 &v) const
 Get dot product.
vector3 Cross (const vector3 &v) const
 Get cross product.
vector3 Normalize () const
 Get normalized vector.
float LengthSq () const
 Get squared length.
float Length () const
 Get length.
wxString ToString () const
 Get string.
vector3Clone () const
 Get copy of instance.

Public Attributes

union {
   struct {
      float   x
 Components.
      float   y
      float   z
   } 
   float   _v [3]
 Components.
}; 

Friends

vector3 operator* (float f, const vector3 &v)
 Scalar multiply operator.
vector3 operator/ (float f, const vector3 &v)
 Scalar divide operator.
std::ostream & operator<< (std::ostream &os, const vector3 &v)
 Output stream operator.
float Distance (const vector3 &a, const vector3 &b)
float SqrDistance (const vector3 &a, const vector3 &b)


Detailed Description

3 component vector

Definition at line 58 of file 3dmath.h.


Constructor & Destructor Documentation

vector3::vector3 ( float  _x = 0,
float  _y = 0,
float  _z = 0 
) [inline]

Constructor.

Definition at line 72 of file 3dmath.h.

00072 : x(_x), y(_y), z(_z)       {}

vector3::vector3 ( const float *  v  )  [inline]

Constructor.

Definition at line 74 of file 3dmath.h.

00074 : x(v[0]), y(v[1]), z(v[2]) {}

vector3::vector3 ( const vector3 v  )  [inline]

Copy constructor.

Definition at line 76 of file 3dmath.h.

00076 : x(v.x), y(v.y), z(v.z)           {}


Member Function Documentation

vector3& vector3::operator= ( const vector3 v  )  [inline]

Assignment operator.

Definition at line 79 of file 3dmath.h.

00080        {
00081               x = v.x;
00082               y = v.y;
00083               z = v.z;
00084               return *this;
00085        }

float vector3::operator[] ( unsigned  i  )  const [inline]

Get component.

Definition at line 88 of file 3dmath.h.

00089        {
00090               return _v[i];
00091        }

vector3 vector3::operator- ( const vector3 v  )  const [inline]

Subtract operator.

Definition at line 94 of file 3dmath.h.

00095        {
00096               return vector3(x-v.x, y-v.y, z-v.z);
00097        }

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

Unary operator.

Definition at line 100 of file 3dmath.h.

00101        {
00102               return vector3(-x, -y, -z);
00103        }

vector3 vector3::operator+ ( const vector3 v  )  const [inline]

Add operator.

Definition at line 106 of file 3dmath.h.

00107        {
00108               return vector3(x+v.x, y+v.y, z+v.z);
00109        }

vector3 vector3::operator* ( float  f  )  const [inline]

Scalar multiply operator.

Definition at line 112 of file 3dmath.h.

00113        {
00114               return vector3(f*x, f*y, f*z);
00115        }

vector3 vector3::operator/ ( float  f  )  const [inline]

Scalar divide operator.

Definition at line 124 of file 3dmath.h.

00125        {
00126               float div = 1.0f/f;
00127               return operator*(div);
00128        }

vector3& vector3::operator+= ( const vector3 v  )  [inline]

Add assignment operator.

Definition at line 138 of file 3dmath.h.

00139        {
00140               x += v.x;
00141               y += v.y;
00142               z += v.z;
00143               return *this;
00144        }

vector3& vector3::operator-= ( const vector3 v  )  [inline]

Subtract assignment operator.

Definition at line 147 of file 3dmath.h.

00148        {
00149               x -= v.x;
00150               y -= v.y;
00151               z -= v.z;
00152               return *this;
00153        }

vector3& vector3::operator*= ( float  f  )  [inline]

Multiply assignment operator.

Definition at line 156 of file 3dmath.h.

00157        {
00158               x *= f;
00159               y *= f;
00160               z *= f;
00161               return *this;
00162        }

vector3& vector3::operator/= ( float  f  )  [inline]

Divide assignment operator.

Definition at line 165 of file 3dmath.h.

00166        {
00167               x /= f;
00168               y /= f;
00169               z /= f;
00170               return *this;
00171        }

bool vector3::operator== ( const vector3 v  )  const [inline]

Equal operator.

Definition at line 174 of file 3dmath.h.

00175        {
00176               return (x == v.x) && ( y == v.y) && (z == v.z);
00177        }

bool vector3::operator!= ( const vector3 v  )  const [inline]

Not Equal operator.

Definition at line 180 of file 3dmath.h.

00181        {
00182               return (x != v.x) || ( y != v.y) || (z != v.z);
00183        }

bool vector3::operator< ( const vector3 v  )  const [inline]

Less then operator.

Definition at line 186 of file 3dmath.h.

00187        {
00188               return (x < v.x) || ((x == v.x) && ( y < v.y)) || ((x == v.x) && ( y == v.y) && (z < v.z));
00189        }

float vector3::Dot ( const vector3 v  )  const [inline]

Get dot product.

Definition at line 192 of file 3dmath.h.

00193        {
00194               return x * v.x + y * v.y + z * v.z;
00195        }

vector3 vector3::Cross ( const vector3 v  )  const [inline]

Get cross product.

Definition at line 198 of file 3dmath.h.

00199        {
00200               return vector3(y*v.z-z*v.y,z*v.x-x*v.z,x*v.y-y*v.x);
00201        }

vector3 vector3::Normalize (  )  const [inline]

Get normalized vector.

Definition at line 204 of file 3dmath.h.

00205        {
00206               float a = 1.0f/Length();
00207               return operator*(a);
00208        }

float vector3::LengthSq (  )  const [inline]

Get squared length.

Definition at line 211 of file 3dmath.h.

00212        {
00213               return x*x + y*y + z*z;
00214        }

float vector3::Length (  )  const [inline]

Get length.

Definition at line 217 of file 3dmath.h.

00218        {
00219               return sqrtf(x*x + y*y + z*z);
00220        }

wxString vector3::ToString (  )  const [inline]

Get string.

Definition at line 223 of file 3dmath.h.

00224        {
00225               return wxString(wxT("(")) << x << wxT(", ") << y << wxT(", ") << z << wxT(")");
00226        }

vector3* vector3::Clone (  )  const [inline]

Get copy of instance.

Definition at line 235 of file 3dmath.h.

00236        {
00237               return new vector3(*this);
00238        }


Friends And Related Function Documentation

vector3 operator* ( float  f,
const vector3 v 
) [friend]

Scalar multiply operator.

Definition at line 118 of file 3dmath.h.

00119        {
00120               return vector3(f*v.x, f*v.y, f*v.z);
00121        }

vector3 operator/ ( float  f,
const vector3 v 
) [friend]

Scalar divide operator.

Definition at line 131 of file 3dmath.h.

00132        {
00133               float div = 1.0f/f;
00134               return v*div;
00135        }

std::ostream& operator<< ( std::ostream &  os,
const vector3 v 
) [friend]

Output stream operator.

Definition at line 229 of file 3dmath.h.

00230        {
00231               return os << "(" << v.x << ", " << v.y << ", " << v.z << ")";
00232        }

float Distance ( const vector3 a,
const vector3 b 
) [friend]

Definition at line 240 of file 3dmath.h.

00240                                                             {
00241        return (a-b).Length();
00242   }

float SqrDistance ( const vector3 a,
const vector3 b 
) [friend]

Definition at line 243 of file 3dmath.h.

00243                                                                {
00244        return (a-b).LengthSq();
00245   }


Member Data Documentation

float vector3::x

Components.

Definition at line 65 of file 3dmath.h.

float vector3::y

Definition at line 65 of file 3dmath.h.

float vector3::z

Definition at line 65 of file 3dmath.h.

float vector3::_v[3]

Components.

Definition at line 68 of file 3dmath.h.

union { ... }


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

Generated on Tue Mar 10 14:41:39 2009 for VRUT by  doxygen 1.5.5