MarSTDv2004: CVector Class Reference

MarSTDv2004

CVector Class Reference

List of all members.

Detailed Description

A vector has three components (x, y, z). These components can be accessed using operator[]. Vectors are commonly used to represent rotation, velocity, position, acceleration, force, etc.
// Example:

CVector position, velocity, acceleration;
float friction_constant = 0.1;                  // Velocity is halved every second.

void update_physics(float dt) {

        velocity += acceleration * dt;
        position += velocity * dt;
        
        velocity *= pow(fraction_constant, dt);

}

Definition at line 45 of file CVector.h.

Public Member Functions

 CVector ()
 CVector (float x, float y, float z)
void set (float x, float y, float z)
float size ()
float size2 ()
void normalize ()
CVector MA (CVector &vector, float scale)
void operator= (CVector vector)
CVector operator- (CVector vector)
CVector operator+ (CVector vector)
CVectoroperator-= (CVector &vector)
CVectoroperator+= (CVector &vector)
CVector operator * (float scale)
CVector operator/ (float scale)
CVectoroperator *= (float scale)
CVectoroperator/= (float scale)
CVector operator- ()
float operator * (CVector &vector)
CVector operator% (CVector &vector)
CVector operator| (CVector &vector)
float & operator[] (int index)
 operator float * ()
bool operator== (CVector &vector)
bool operator!= (CVector &vector)

Public Attributes

float v [4]

Constructor & Destructor Documentation

CVector::CVector  ) 
 

Default constructor. Initializes all three components to 0.0.

Definition at line 53 of file CVector.h.

CVector::CVector float  x,
float  y,
float  z
 

Constructor with explicit initial values for (x, y, z).

Definition at line 61 of file CVector.h.


Member Function Documentation

void CVector::set float  x,
float  y,
float  z
 

Convinient way to set all three components at once.

Parameters:
x New x value.
y new y value.
z new z value.

Definition at line 84 of file CVector.h.

float CVector::size  ) 
 

Returns:
The magnitude of the vector, using pythagoras' theorem.

Definition at line 93 of file CVector.h.

float CVector::size2  ) 
 

Returns:
The magnitude of the vector squared. This is faster than size() because it doesn't do a sqrt().
See also:
size()

Definition at line 101 of file CVector.h.

void CVector::normalize  ) 
 

Makes the vector a unit vector if size() != 0.0. Leaves vector unchanged if 0.0.

See also:
size()

Definition at line 109 of file CVector.h.

Here is the call graph for this function:

CVector CVector::MA CVector vector,
float  scale
 

Returns a vector that equals this + vector * scale. Use it to interpolate vectors.

Parameters:
vector Vector to add to this vector. Delta when interpolating vectors.
scale Scaling factor to scale vector.

Definition at line 130 of file CVector.h.

void CVector::operator= CVector  vector  ) 
 

Copies vector into this vector.

Definition at line 144 of file CVector.h.

CVector CVector::operator- CVector  vector  ) 
 

Vector subtraction. vout[i] = v1[i] - v[2].

Definition at line 153 of file CVector.h.

CVector CVector::operator+ CVector  vector  ) 
 

Vector addition. vout[i] = v1[i] + v2[i].

Definition at line 164 of file CVector.h.

CVector& CVector::operator-= CVector vector  ) 
 

Subtract vector from this vector.

Definition at line 175 of file CVector.h.

CVector& CVector::operator+= CVector vector  ) 
 

Adds vector to this vector.

Definition at line 185 of file CVector.h.

CVector CVector::operator * float  scale  ) 
 

Vector scaling. vout[i] = v[i] * scale.

Definition at line 195 of file CVector.h.

CVector CVector::operator/ float  scale  ) 
 

Vector scaling inverse. vout[i] = v[i] * 1/scale.

Definition at line 206 of file CVector.h.

CVector& CVector::operator *= float  scale  ) 
 

Multiplies this vector by scaling factor.

Definition at line 218 of file CVector.h.

CVector& CVector::operator/= float  scale  ) 
 

Divides this vector by scaling factor.

Definition at line 228 of file CVector.h.

CVector CVector::operator-  ) 
 

Negates this vector. vout[i] = -v[i].

Definition at line 240 of file CVector.h.

float CVector::operator * CVector vector  ) 
 

Returns the dot product of this vector and vector. dot = a[0]*b[0] + a[1]*b[1] + a[2]*b[2].

Definition at line 252 of file CVector.h.

CVector CVector::operator% CVector vector  ) 
 

Returns the cross product of this vector and vector. The resulting vector is perpendicular to both input vectors.

Definition at line 262 of file CVector.h.

CVector CVector::operator| CVector vector  ) 
 

Vector multiplication by vector. vout[i] = a[i] * b[i].

Definition at line 273 of file CVector.h.

float& CVector::operator[] int  index  ) 
 

Returns component[index].

Definition at line 284 of file CVector.h.

CVector::operator float *  ) 
 

Returns a float* pointer to the internal representation of the vector.

Definition at line 292 of file CVector.h.

bool CVector::operator== CVector vector  ) 
 

Returns true if vector is exactly the same as this vector.

Definition at line 299 of file CVector.h.

bool CVector::operator!= CVector vector  ) 
 

Returns true if vector is not the same as this vector.

Definition at line 319 of file CVector.h.


The documentation for this class was generated from the following file:
Generated on Tue Feb 8 21:59:44 2005 for MarSTDv2004 by  doxygen 1.4.1