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.
CVector position, velocity, acceleration;
float friction_constant = 0.1;
void update_physics(float dt) {
velocity += acceleration * dt;
position += velocity * dt;
velocity *= pow(fraction_constant, dt);
}
Definition at line 45 of file CVector.h.
Constructor & Destructor Documentation
|
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. |
|
- Returns:
- The magnitude of the vector, using pythagoras' theorem.
Definition at line 93 of file CVector.h. |
|
- 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:
|
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. |
|
Vector subtraction. vout[i] = v1[i] - v[2].
Definition at line 153 of file CVector.h. |
|
Vector addition. vout[i] = v1[i] + v2[i].
Definition at line 164 of file CVector.h. |
|
Subtract vector from this vector.
Definition at line 175 of file CVector.h. |
|
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. |
|
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. |
|
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. |
|
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
1.4.1