A class representing a 3vector. More...
#include <vector3.h>
Public Member Functions | |
| Vector3 () | |
| Vector3 (fix x, fix y, fix z) | |
| Vector3 | operator- () const |
| Vector3 | operator+ (const Vector3 &vector) const |
| Vector3 | operator- (const Vector3 &vector) const |
| Vector3 | operator* (fix scalar) const |
| Vector3 | operator/ (fix scalar) const |
| Vector3 & | operator+= (const Vector3 &vector) |
| Vector3 & | operator-= (const Vector3 &vector) |
| Vector3 & | operator*= (fix scalar) |
| Vector3 & | operator/= (fix scalar) |
| bool | operator== (const Vector3 &vector) const |
| bool | operator!= (const Vector3 &vector) const |
| fix | DotProduct (const Vector3 &vector) const |
| Vector3 | CrossProduct (const Vector3 &vector) const |
| ufix | Length () const |
| int | CompareLength (ufix length) const |
| int | CompareLengths (const Vector3 &vector) const |
| uint32_t | LengthSquared (uint32_t &fraction) const |
| Vector3 | UnitVector () const |
| Vector3 | Normal (const Vector3 &vector) const |
| fixangle | Angle (const Vector3 &vector) const |
| Vector3 | Normal (const Vector3 &point1, const Vector3 &point2) const |
| fixangle | Angle (const Vector3 &point1, const Vector3 &point2) const |
Static Public Member Functions | |
| static void | Translate (Vector3 *outVectors, unsigned vectorCount, const Vector3 *inVectors, const Vector3 &offset) |
| static void | Scale (Vector3 *outVectors, unsigned vectorCount, const Vector3 *inVectors, fix scale) |
Public Attributes | |
| fix | X |
| fix | Y |
| fix | Z |
Private Member Functions | |
| void | NormaliseComponents (unsigned bits) |
A class representing a 3vector.
The three components of the vector; X,Y and Z, are 32bit fixed point numbers with the binary point between bits 15 and 16.
Definition at line 69 of file vector3.h.
| Vector3::Vector3 | ( | ) |
| Vector3 Vector3::operator- | ( | ) | const |
Uninary minus operator.
Definition at line 41 of file vector3.cpp.
Calculate the sum of this vector and another. The resulting vector is the sum of the individual component values. If any component value overflows the range of 32bit fixed point numbers, then the result is undefined.
| vector | The vector to add to this. |
Definition at line 47 of file vector3.cpp.
Calculate the difference between this vector and another. The resulting vector is the difference between the individual component values. If any component value overflows the range of 32bit fixed point numbers, then the result is undefined.
| vector | The vector to subtract from this. |
Definition at line 53 of file vector3.cpp.
Scalar multiply. The resulting vector is the product of the individual component values of this vector multiplied by the given scalar value. If any component value overflows the range of 32bit fixed point numbers, then the result is undefined.
| scalar | The scalar value to multiply by. |
Definition at line 59 of file vector3.cpp.
Scalar division. The resulting vector is the result of dividing the individual component values of this vector by the given scalar value. If any component value overflows the range of 32bit fixed point numbers, then the result is undefined.
| scalar | The scalar value to divide by. |
Definition at line 65 of file vector3.cpp.
Add a vector to this one. The result is the sum of the individual component values. If any component value overflows the range of 32bit fixed point numbers, then the result is undefined.
| vector | The vector to add to this. |
Definition at line 71 of file vector3.cpp.
Subract a vector from this one. The result is the difference between the individual component values. If any component value overflows the range of 32bit fixed point numbers, then the result is undefined.
| vector | The vector to subtract from this. |
Definition at line 80 of file vector3.cpp.
Scalar multiply of this vector. Multiply each component of this vector by a scalar value. If any component value overflows the range of 32bit fixed point numbers, then the result is undefined.
| scalar | The scalar value to multiply by. |
Definition at line 89 of file vector3.cpp.
Scalar divide of this vector. Divide each component of this vector by a scalar value. If any component value overflows the range of 32bit fixed point numbers, then the result is undefined.
| scalar | The scalar value to divide by. |
Definition at line 98 of file vector3.cpp.
| bool Vector3::operator== | ( | const Vector3 & | vector | ) | const |
Equality operator.
| vector | The vector to test equality with. |
Definition at line 107 of file vector3.cpp.
| bool Vector3::operator!= | ( | const Vector3 & | vector | ) | const |
Calculate the dot product of this vector and a second vector.
If any product of two components is greater than 0x2aaa.aaaa then the result is undefined. This limitation can be met if all components, in both vectors, have a magnitude less than 104. (0x68.00000)
| vector | The second vector. |
Definition at line 113 of file vector3.cpp.
Calculate the cross product of this vector and a second vector.
If any product of two components is greater than 0x4000.0000 then the result is undefined. This limitation can be met if all components, in both vectors, have a magnitude less than 128. (0x80.00000)
| vector | The second vector. |
Definition at line 119 of file vector3.cpp.
| ufix Vector3::Length | ( | ) | const |
Calculate the length (magnitude) of this vector. Accuracy is limited to 24 significant bits.
Definition at line 139 of file vector3.cpp.
| int Vector3::CompareLength | ( | ufix | length | ) | const |
Compare the length (magnitude) of this vector with a given value. This is faster than comparing the value returned by Length(). E.g. instead of
if(vector.Length()<distance)
use
if(vector.CompareLength(distance)<0)
| length | The length value to compare with. |
Definition at line 174 of file vector3.cpp.
| int Vector3::CompareLengths | ( | const Vector3 & | vector | ) | const |
Compare the length of this vector with another. This is faster than comparing two values returned by Length(). E.g. instead of
if(vector1.Length()<vector2.Length())
use
if(vector1.CompareLengths(vector2)<0)
| vector | The vector to compare with. |
Definition at line 204 of file vector3.cpp.
Calculate the square of the length of this vector. This is faster than Length() and is useful when comparing a vector length with a constant or pre-calculated value. (Comparing the square of lengths will give the same result as comparing the lengths.)
| fraction | Set to the fraction part of the result, i.e the 32 bits to the right of the binary point. |
Definition at line 222 of file vector3.cpp.
| Vector3 Vector3::UnitVector | ( | ) | const |
Calculate the unit vector which lies in the same direction as this vector. I.e. scale this vector so it has a length of 1.0.
Rounding inacuracies mean the length of this 'unit' vector will actualy lie in the range 0x0.fffe to 0x1.0000.
Definition at line 317 of file vector3.cpp.
Calculate the unit vector which is normal to this vector and a second vector. I.e. the unit vector which is at right angles to both this vector and the second vector; acording to the right-hand rule.
Rounding inacuracies mean the length of this 'unit' vector will actualy lie in the range 0x0.fffe to 0x1.0000.
| vector | The second vector. |
Definition at line 338 of file vector3.cpp.
Calculate the angle between this vector and a second vector.
| vector | The second vector. |
Definition at line 356 of file vector3.cpp.
Calculate the unit vector which is normal to the two vectors formed by (point1 - this) and (point2 - this). I.e. the unit vector which is at right angles to both of these; acording to the right-hand rule.
Rounding inacuracies mean the length of this 'unit' vector will actualy lie in the range 0x0.fffe to 0x1.0000.
| point1 | The first point. | |
| point2 | The second point. |
Definition at line 362 of file vector3.cpp.
Calculate the angle between the two vectors formed by (point1 - this) and (point2 - this).
| point1 | The first point. | |
| point2 | The second point. |
Definition at line 368 of file vector3.cpp.
| void Vector3::Translate | ( | Vector3 * | outVectors, | |
| unsigned | vectorCount, | |||
| const Vector3 * | inVectors, | |||
| const Vector3 & | offset | |||
| ) | [static] |
Translate an array of vectors. I.e. add the given offset to each vector in an array.
| outVectors | Pointer to array where translated vectors will be written to. | |
| vectorCount | Number of vectors in array. | |
| inVectors | Pointer to array vectors to be translated. | |
| offset | The offset to add to each vector in the array. |
Definition at line 374 of file vector3.cpp.
| void Vector3::Scale | ( | Vector3 * | outVectors, | |
| unsigned | vectorCount, | |||
| const Vector3 * | inVectors, | |||
| fix | scale | |||
| ) | [static] |
Scale an array of vectors. I.e. perform a scalar multiply on each vector in an array.
| outVectors | Pointer to array where scaled vectors will be written to. | |
| vectorCount | Number of vectors in array. | |
| inVectors | Pointer to array vectors to be scaled. | |
| scale | The value to scale each component of each vector by. |
Definition at line 391 of file vector3.cpp.
| void Vector3::NormaliseComponents | ( | unsigned | bits | ) | [private] |
Scale the components of this array such that the component with the largest magnitude has its most-significant bit at the given position.
| bits | Bit position for MSB of largest component. |
Definition at line 269 of file vector3.cpp.
1.6.1