voxelTerrain
 All Classes Functions Variables Typedefs Enumerations Pages
Public Member Functions | Public Attributes | Static Public Attributes | Friends | List of all members
blub::vector3 Class Reference

Public Member Functions

 vector3 (const Ogre::Vector3 &vec)
 
 operator Ogre::Vector3 () const
 
 vector3 (const real fX, const real fY, const real fZ)
 
 vector3 (const real &scaler)
 
 vector3 (const vector3int32 &cast)
 
bool operator<= (const vector3 &rhs) const
 
bool operator>= (const vector3 &rhs) const
 
vector3 getFloor (void) const
 
vector3 getAbs (void) const
 
void swap (vector3 &other)
 
real operator[] (const size_t i) const
 
real & operator[] (const size_t i)
 
real * ptr ()
 Pointer accessor for direct copying.
 
const real * ptr () const
 Pointer accessor for direct copying.
 
vector3operator= (const real 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 real fScalar) const
 
vector3 operator* (const vector3 &rhs) const
 
vector3 operator/ (const real fScalar) const
 
vector3 operator/ (const vector3 &rhs) const
 
const vector3operator+ () const
 
vector3 operator- () const
 
vector3operator+= (const vector3 &rkVector)
 
vector3operator+= (const real fScalar)
 
vector3operator-= (const vector3 &rkVector)
 
vector3operator-= (const real fScalar)
 
vector3operator*= (const real fScalar)
 
vector3operator*= (const vector3 &rkVector)
 
vector3operator/= (const real fScalar)
 
vector3operator/= (const vector3 &rkVector)
 
real length () const
 
real squaredLength () const
 
real distance (const vector3 &rhs) const
 
real squaredDistance (const vector3 &rhs) const
 
real dotProduct (const vector3 &vec) const
 
real absDotProduct (const vector3 &vec) const
 
real 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
 
real angleBetween (const vector3 &dest) const
 
quaternion getRotationTo (const vector3 &dest, const vector3 &fallbackAxis=vector3::ZERO) const
 
bool isZeroLength (void) const
 
vector3 getNormalise () const
 
vector3 normalisedCopy (void) const
 
vector3 reflect (const vector3 &normal) const
 
bool positionCloses (const vector3 &rhs, real tolerance=1e-03f) const
 
vector3 primaryAxis () const
 Extract the primary (dominant) axis from this direction vector.
 

Public Attributes

real x
 
real y
 
real z
 

Static Public Attributes

static const vector3 ZERO = vector3(0.)
 
static const vector3 UNIT_X = vector3(1., 0., 0.)
 
static const vector3 UNIT_Y = vector3(0., 1., 0.)
 
static const vector3 UNIT_Z = vector3(0., 0., 1.)
 
static const vector3 NEGATIVE_UNIT_X = vector3(-1., 0., 0.)
 
static const vector3 NEGATIVE_UNIT_Y = vector3(0., -1., 0.)
 
static const vector3 NEGATIVE_UNIT_Z = vector3(0., 0., -1.)
 
static const vector3 UNIT_SCALE = vector3(1., 1., 1.)
 

Friends

vector3 operator* (const real fScalar, const vector3 &rkVector)
 
vector3 operator/ (const real fScalar, const vector3 &rkVector)
 
vector3 operator+ (const vector3 &lhs, const real rhs)
 
vector3 operator+ (const real lhs, const vector3 &rhs)
 
vector3 operator- (const vector3 &lhs, const real rhs)
 
vector3 operator- (const real lhs, const vector3 &rhs)
 

Detailed Description

Examples:
customVertexInformation.cpp, mesh.cpp, noise.cpp, and primitives.cpp.

Member Function Documentation

real blub::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 real representing the absolute dot product value.
real blub::vector3::angleBetween ( const vector3 dest) const
inline

Gets the angle between 2 vectors.

Remarks
Vectors do not have to be unit-length but must represent directions.
vector3 blub::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
rkVectorVector 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).
real blub::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.
real blub::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.
vector3 blub::vector3::getNormalise ( ) const
inline

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

quaternion vector3::getRotationTo ( const vector3 dest,
const vector3 fallbackAxis = vector3::ZERO 
) const

Gets the shortest arc quaternion to rotate this vector to the destination vector.

Remarks
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.
bool blub::vector3::isZeroLength ( void  ) const
inline

Returns true if this vector is zero length.

real blub::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 blub::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 blub::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 blub::vector3::midPoint ( const vector3 vec) const
inline

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

real blub::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 blub::vector3::normalisedCopy ( void  ) const
inline

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

bool blub::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& blub::vector3::operator= ( const real  fScaler)
inline

Assigns the value of the other vector.

Parameters
rkVectorThe other vector depricated! inline vector3& operator = ( const vector3& rkVector ) { x = rkVector.x; y = rkVector.y; z = rkVector.z;

return *this; }

bool blub::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 blub::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 blub::vector3::positionCloses ( const vector3 rhs,
real  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
vector3 blub::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.
real blub::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.
real blub::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.
void blub::vector3::swap ( vector3 other)
inline

Exchange the contents of this vector with another.


The documentation for this class was generated from the following files: