Main Page   Modules   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

Vec3 Class Template Reference

A templated 3-vector class. More...

#include <vec3f.hpp>

List of all members.

Public Methods

 Vec3 (void)
 Default constructor. Note: does not initialize x, y, and z!

 Vec3 (const Type X, const Type Y, const Type Z)
 Three component constructor.

 Vec3 (const Vec3 &v)
 Copy constructor.

 Vec3 (const Type v[3])
 Construct from array.

void Set (const Type X, const Type Y, const Type Z)
 Set from components.

void Set (const Type v[3])
 Set from array.

 operator Type * ()
 Type * CONVERSION.

 operator const Type * () const
 CONST Type * CONVERSION.

int operator== (const Vec3 &A) const
 COMPARISON (==).

Vec3 & operator= (const Vec3 &A)
 ASSIGNMENT (=).

Vec3 operator+ (const Vec3 &A) const
 ADDITION (+).

Vec3 operator- (const Vec3 &A) const
 SUBTRACTION (-).

Type operator * (const Vec3 &A) const
 DOT-PRODUCT (*).

Vec3 operator/ (const Vec3 &A) const
 CROSS-PRODUCT (/).

Vec3 operator^ (const Vec3 &A) const
 ALSO CROSS-PRODUCT (^).

Vec3 operator * (const Type s) const
 MULTIPLY BY SCALAR V*s (*).

Vec3 operator/ (const Type s) const
 DIVIDE BY SCALAR (/).

Vec3 operator & (const Vec3 &A) const
 COMPONENT MULTIPLY (&).

Vec3 & operator+= (const Vec3 &A)
 ACCUMULATED VECTOR ADDITION (+=).

Vec3 & operator-= (const Vec3 &A)
 ACCUMULATED VECTOR SUBTRACTION (-=).

Vec3 & operator *= (const Type s)
 ACCUMULATED SCALAR MULT (*=).

Vec3 & operator/= (const Type s)
 ACCUMULATED SCALAR DIV (/=).

Vec3 & operator &= (const Vec3 &A)
 ACCUMULATED COMPONENT MULTIPLY (&=).

Vec3 operator- (void) const
 NEGATION (-).

Type Length (void) const
 LENGTH OF VECTOR.

Type LengthSqr (void) const
 LENGTH OF VECTOR (SQUARED).

Vec3 & Normalize (void)
 NORMALIZE VECTOR.

Type * Star () const
 Returns the 'star' matrix for a vector. More...

void UpdateMinMax (Vec3 &Min, Vec3 &Max) const
 Update Min and Max to enclose this. More...

void CompleteOrthonormalBasis (Vec3 &U, Vec3 &V) const
 Construct an orthonormal basis from this. More...

void Print () const
 Dump the vector to stdout in a pretty way.


Public Attributes

Type x
Type y
Type z
 The storage for the three components of the vector.


Static Public Attributes

Vec3 ZERO = Vec3<Type>(0,0,0)
 This is a handy way to get the zero vector just use Vec3<Type>::ZERO.


Friends

Vec3 operator * (Type s, const Vec3 &v)
 SCALAR MULT s*V.


Detailed Description

template<class Type>
class Vec3< Type >

A templated 3-vector class.

Everybody in graphics has to write their own basic 3-vector class. And we're no exception. This one uses templates, so that with one definition of the class you can have a 3-vector of floats or doubles depending on how precise you are, or you can make 3-vectors of ints or unsigned char, handy for representing colors.

A couple of typedefs for common instatiations are provided by default: Vec3f, and Vec3d, the float and double versions, respectively.


Member Function Documentation

template<class Type>
void Vec3< Type >::CompleteOrthonormalBasis Vec3< Type > &   U,
Vec3< Type > &   V
const [inline]
 

Construct an orthonormal basis from this.

Compute two unit vectors U and V that are orthogonal to this vector and to each other. Note that *this need not be a unit vector.

The algorithm works as follows: Find smallest component of L (this), zero it, negate one of the other two and swap them. Then normalize. Ex. if x1 is the smallest, assign (x2,y2,z2):=(0,z1,-y1) Clearly now v1 dot v2 = x1*0 + y1*z1 + z1*-y1 = 0; Zeroing out the smallest means that the magnitude of the remaining vector will be as big as possible so that when we normalize, we are safe from dividing by anything close to zero (unless *this was near 0 magnitude to begin with, in which case lack of precision can't be avoided)

template<class Type>
Type* Vec3< Type >::Star   const [inline]
 

Returns the 'star' matrix for a vector.

This is the skew-symmetric matrix A such that A v == this x v (the cross-product of this and v), for any vector v. The matrix looks like this given vector (x,y,z):

            | 0  -z   y|
            | z   0  -x|
            |-y   x   0|
        

Return format is just an array in row-major (OpenGL/Fortran) order. That is [0, -z, y, z, 0, -x, -y, x, 0].

template<class Type>
void Vec3< Type >::UpdateMinMax Vec3< Type > &   Min,
Vec3< Type > &   Max
const [inline]
 

Update Min and Max to enclose this.

A very handy routine for working with min-max or axis aligned bounding boxes.


The documentation for this class was generated from the following file:
Generated at Fri Oct 12 15:12:22 2001 for GLVU by doxygen1.2.10 written by Dimitri van Heesch, © 1997-2001