libmove3d  3.13.0
Public Member Functions | Public Attributes | Static Public Attributes | Friends
Vector3 Class Reference

#include <vector3d.h>

List of all members.

Public Member Functions

 Vector3 (const double fX, const double fY, const double fZ)
 Vector3 (const double afCoordinate[3])
 Vector3 (const int afCoordinate[3])
 Vector3 (const p3d_matrix4 m)
 Vector3 (double *const r)
 Vector3 (const double scaler)
int size () const
double operator[] (const size_t i) const
double & operator[] (const size_t i)
double * ptr ()
 Pointer accessor for direct copying.
const double * ptr () const
 Pointer accessor for direct copying.
Vector3operator= (const Vector3 &rkVector)
Vector3operator= (const double fScaler)
bool operator== (const Vector3 &rkVector) const
bool operator!= (const Vector3 &rkVector) const
Vector3 operator+ (const Vector3 &rkVector) const
Vector3 operator- (const Vector3 &rkVector) const
Vector3 operator* (const double fScalar) const
Vector3 operator* (const Vector3 &rhs) const
Vector3 operator/ (const double fScalar) const
Vector3 operator/ (const Vector3 &rhs) const
const Vector3operator+ () const
Vector3 operator- () const
Vector3operator+= (const Vector3 &rkVector)
Vector3operator+= (const double fScalar)
Vector3operator-= (const Vector3 &rkVector)
Vector3operator-= (const double fScalar)
Vector3operator*= (const double fScalar)
Vector3operator*= (const Vector3 &rkVector)
Vector3operator/= (const double fScalar)
Vector3operator/= (const Vector3 &rkVector)
double length () const
double squaredLength () const
double distance (const Vector3 &rhs) const
double squaredDistance (const Vector3 &rhs) const
double dotProduct (const Vector3 &vec) const
double absDotProduct (const Vector3 &vec) const
double normalise ()
Vector3 crossProduct (const Vector3 &rkVector) const
Vector3 midPoint (const Vector3 &vec) const
bool operator< (const Vector3 &rhs) const
bool operator> (const Vector3 &rhs) const
void makeFloor (const Vector3 &cmp)
void makeCeil (const Vector3 &cmp)
Vector3 perpendicular (void) const
bool isZeroLength (void) const
Vector3 normalisedCopy (void) const
Vector3 reflect (const Vector3 &normal) const
bool positionEquals (const Vector3 &rhs, double tolerance=1e-03) const
bool doubleEqual (const double &a, const double &b, const double &tolerance) const
bool positionCloses (const Vector3 &rhs, double tolerance=1e-03f) const

Public Attributes

double x
double y
double z

Static Public Attributes

static const Vector3 ZERO
static const Vector3 UNIT_X
static const Vector3 UNIT_Y
static const Vector3 UNIT_Z
static const Vector3 NEGATIVE_UNIT_X
static const Vector3 NEGATIVE_UNIT_Y
static const Vector3 NEGATIVE_UNIT_Z
static const Vector3 UNIT_SCALE

Friends

Vector3 operator* (const double fScalar, const Vector3 &rkVector)
Vector3 operator/ (const double fScalar, const Vector3 &rkVector)
Vector3 operator+ (const Vector3 &lhs, const double rhs)
Vector3 operator+ (const double lhs, const Vector3 &rhs)
Vector3 operator- (const Vector3 &lhs, const double rhs)
Vector3 operator- (const double lhs, const Vector3 &rhs)
std::ostream & operator<< (std::ostream &o, const Vector3 &v)

Detailed Description

Standard 3-dimensional vector.

Remarks:
A direction in 3D space represented as distances along the 3 orthogonal axes (x, y, z). Note that positions, directions and scaling factors can be represented by a vector, depending on how you interpret the values.

Member Function Documentation

double Vector3::absDotProduct ( const Vector3 vec) const [inline]

Calculates the absolute dot (scalar) product of this vector with another.

Remarks:
This function work similar dotProduct, except it use absolute value of each component of the vector to computing.
Parameters:
vecVector with which to calculate the absolute dot product (together with this one).
Returns:
A double representing the absolute dot product value.
Vector3 Vector3::crossProduct ( const Vector3 rkVector) const [inline]

Calculates the cross-product of 2 vectors, i.e. the vector that lies perpendicular to them both.

Remarks:
The cross-product is normally used to calculate the normal vector of a plane, by calculating the cross-product of 2 non-equivalent vectors which lie on the plane (e.g. 2 edges of a triangle).
Parameters:
vecVector which, together with this one, will be used to calculate the cross-product.
Returns:
A vector which is the result of the cross-product. This vector will NOT be normalised, to maximise efficiency
  • call Vector3::normalise on the result if you wish this to be done. As for which side the resultant vector will be on, the returned vector will be on the side from which the arc from 'this' to rkVector is anticlockwise, e.g. UNIT_Y.crossProduct(UNIT_Z) = UNIT_X, whilst UNIT_Z.crossProduct(UNIT_Y) = -UNIT_X. This is because OGRE uses a right-handed coordinate system.
For a clearer explanation, look a the left and the bottom edges of your monitor's screen. Assume that the first vector is the left edge and the second vector is the bottom edge, both of them starting from the lower-left corner of the screen. The resulting vector is going to be perpendicular to both of them and will go inside the screen, towards the cathode tube (assuming you're using a CRT monitor, of course).
double Vector3::distance ( const Vector3 rhs) const [inline]

Returns the distance to another vector.

Warning:
This operation requires a square root and is expensive in terms of CPU operations. If you don't need to know the exact distance (e.g. for just comparing distances) use squaredDistance() instead.
double Vector3::dotProduct ( const Vector3 vec) const [inline]

Calculates the dot (scalar) product of this vector with another.

Remarks:
The dot product can be used to calculate the angle between 2 vectors. If both are unit vectors, the dot product is the cosine of the angle; otherwise the dot product must be divided by the product of the lengths of both vectors to get the cosine of the angle. This result can further be used to calculate the distance of a point from a plane.
Parameters:
vecVector with which to calculate the dot product (together with this one).
Returns:
A float representing the dot product value.
bool Vector3::isZeroLength ( void  ) const [inline]

Generates a new random vector which deviates from this vector by a given angle in a random direction.

Remarks:
This method assumes that the random number generator has already been seeded appropriately.
Parameters:
angleThe angle at which to deviate
upAny vector perpendicular to this one (which could generated by cross-product of this vector and any other non-colinear vector). If you choose not to provide this the function will derive one on it's own, however if you provide one yourself the function will be faster (this allows you to reuse up vectors if you call this method more than once)
Returns:
A random vector which deviates from this vector by angle. This vector will not be normalised, normalise it if you wish afterwards. Gets the angle between 2 vectors.
Remarks:
Vectors do not have to be unit-length but must represent directions. Gets the shortest arc quaternion to rotate this vector to the destination vector.
If you call this with a dest vector that is close to the inverse of this vector, we will rotate 180 degrees around the 'fallbackAxis' (if specified, or a generated axis if not) since in this case ANY axis of rotation is valid. Returns true if this vector is zero length.
double Vector3::length ( ) const [inline]

Returns the length (magnitude) of the vector.

Warning:
This operation requires a square root and is expensive in terms of CPU operations. If you don't need to know the exact length (e.g. for just comparing lengths) use squaredLength() instead.
void Vector3::makeCeil ( const Vector3 cmp) [inline]

Sets this vector's components to the maximum of its own and the ones of the passed in vector.

Remarks:
'Maximum' in this case means the combination of the highest value of x, y and z from both vectors. Highest is taken just numerically, not magnitude, so 1 > -3.
void Vector3::makeFloor ( const Vector3 cmp) [inline]

Sets this vector's components to the minimum of its own and the ones of the passed in vector.

Remarks:
'Minimum' in this case means the combination of the lowest value of x, y and z from both vectors. Lowest is taken just numerically, not magnitude, so -1 < 0.
Vector3 Vector3::midPoint ( const Vector3 vec) const [inline]

Returns a vector at a point half way between this and the passed in vector.

double Vector3::normalise ( ) [inline]

Normalises the vector.

Remarks:
This method normalises the vector such that it's length / magnitude is 1. The result is called a unit vector.
Note:
This function will not crash for zero-sized vectors, but there will be no changes made to their components.
Returns:
The previous length of the vector.
Vector3 Vector3::normalisedCopy ( void  ) const [inline]

As normalise, except that this vector is unaffected and the normalised vector is returned as a copy.

bool Vector3::operator< ( const Vector3 rhs) const [inline]

Returns true if the vector's scalar components are all greater that the ones of the vector it is compared against.

Vector3& Vector3::operator= ( const Vector3 rkVector) [inline]

Assigns the value of the other vector.

Parameters:
rkVectorThe other vector
bool Vector3::operator> ( const Vector3 rhs) const [inline]

Returns true if the vector's scalar components are all smaller that the ones of the vector it is compared against.

Vector3 Vector3::perpendicular ( void  ) const [inline]

Generates a vector perpendicular to this vector (eg an 'up' vector).

Remarks:
This method will return a vector which is perpendicular to this vector. There are an infinite number of possibilities but this method will guarantee to generate one of them. If you need more control you should use the Quaternion class.
bool Vector3::positionCloses ( const Vector3 rhs,
double  tolerance = 1e-03f 
) const [inline]

Returns whether this vector is within a positional tolerance of another vector, also take scale of the vectors into account.

Parameters:
rhsThe vector to compare with
toleranceThe amount (related to the scale of vectors) that distance of the vector may vary by and still be considered close
bool Vector3::positionEquals ( const Vector3 rhs,
double  tolerance = 1e-03 
) const [inline]

Returns whether this vector is within a positional tolerance of another vector.

Parameters:
rhsThe vector to compare with
toleranceThe amount that each element of the vector may vary by and still be considered equal
Vector3 Vector3::reflect ( const Vector3 normal) const [inline]

Calculates a reflection vector to the plane with the given normal .

Remarks:
NB assumes 'this' is pointing AWAY FROM the plane, invert if it is not.
double Vector3::squaredDistance ( const Vector3 rhs) const [inline]

Returns the square of the distance to another vector.

Remarks:
This method is for efficiency - calculating the actual distance to another vector requires a square root, which is expensive in terms of the operations required. This method returns the square of the distance to another vector, i.e. the same as the distance but before the square root is taken. Use this if you want to find the longest / shortest distance without incurring the square root.
double Vector3::squaredLength ( ) const [inline]

Returns the square of the length(magnitude) of the vector.

Remarks:
This method is for efficiency - calculating the actual length of a vector requires a square root, which is expensive in terms of the operations required. This method returns the square of the length of the vector, i.e. the same as the length but before the square root is taken. Use this if you want to find the longest / shortest vector without incurring the square root.

Friends And Related Function Documentation

std::ostream& operator<< ( std::ostream &  o,
const Vector3 v 
) [friend]

Function for writing to a stream.


Member Data Documentation

const Vector3 Vector3::ZERO [static]

Returns whether this vector is within a directional tolerance of another vector.

Parameters:
rhsThe vector to compare with
toleranceThe maximum angle by which the vectors may vary and still be considered equal
Note:
Both vectors should be normalised.

The documentation for this class was generated from the following files:
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines